| Commit message (Expand) | Author | Age | Files | Lines |
| * | Make venv change work on Darwin•••This patch builds on the previous to make prefix resolution work
correctly inside virtual environments on Darwin. The --inherit-argv0
mechanism is insufficient, as on Darwin, Python uses the
_NSGetExecutablePath() call to work out the actual path to its binary.
Since this resolves to the real unwrapped binary, --inherit-argv0 is
little use.
This patch adds a new variant, --inherit-argv0-path, which resolves the
full path before passing it to argv[0]. On Darwin this is done using
_NSGetExecutablePath(), on Linux by reading /proc/self/exe. This
bypasses the real_executable lookup, as Python gives precedence to
argv[0] when it appears to be a path (contains a slash).
While not strictly necessary on Linux (as --inherit-argv0 works anyway),
the change is made to both for consistency.
| Alex O'Brien | 2024-03-01 | 1 | -1/+1 |
| * | Fix venv creation in Python environments•••The way we build python environments is subtly broken. A python
environment should be semantically identical to a vanilla Python
installation in, say, /usr/local. The current implementation, however,
differs in two important ways. The first is that it's impossible to use
python packages from the environment in python virtual environments. The
second is that the nix-generated environment appears to be a venv, but
it's not.
This commit changes the way python environments are built:
* When generating wrappers for python executables, we set argv0 to
the full path of the wrapper. This causes python to initialize its
configuration in the environment with all the correct paths.
* We remove the sitecustomize.py file from the base python package.
This file was used tweak the python configuration after it was
incorrectly initialized. That's no longer necessary.
* When building the environment's bin directory, we now detect wrapped
python scripts from installed packages, and generate unwrapped
copies with the environment's python executable as the interpreter.
The end result is that python environments no longer appear to be venvs,
and behave more like a vanilla python installation. In addition it's
possible to create a venv using an environment and use packages from
both the environment and the venv.
| Colin Putney | 2024-03-01 | 1 | -1/+9 |
| * | treewide: use optionalString instead of 'then ""' | Felix Buehler | 2023-06-24 | 1 | -1/+1 |
| * | python-wrapper: use makeBinaryWrapper•••A "python" made with the wrapper is likely to be used as a shebang. On macOS,
this requires a binary rather than another shebang'd script.
| Atemu | 2022-04-20 | 1 | -2/+2 |
| * | treewide: Fix various tools wrappers "with packages"•••Now that `buildEnv` is ready, always put `makeWrapper` in
`nativeBuildInputs`, rather than `buildInputs` or (worse) mucking around
with setup hooks by hand.
(C.f. #112276, which didn't catch these because the manual setup hook
sourcing is such a hack to being with!)
Fixes #114687
| John Ericson | 2021-03-02 | 1 | -4/+9 |
| * | pkgs/development/interpreters: stdenv.lib -> lib | Ben Siraphob | 2021-01-23 | 1 | -3/+3 |
| * | Python: introduce NIX_PYTHONPREFIX in order to set site.PREFIXES•••This is needed in case of `python.buildEnv` to make sure site.PREFIXES
does not only point to the unwrapped executable prefix.
--------------------------------------------------------------------------------
This PR is a story where your valiant hero sets out on a very simple adventure but ends up having to slay dragons, starts questioning his own sanity and finally manages to gain enough knowledge to slay the evil dragon and finally win the proverbial price.
It all started out on sunny spring day with trying to tackle the Nixops plugin infrastructure and make that nice enough to work with.
Our story begins in the shanty town of [NixOps-AWS](https://github.com/nixos/nixops-aws) where [mypy](http://mypy-lang.org/) type checking has not yet been seen.
As our deuteragonist (@grahamc) has made great strides in the capital city of [NixOps](https://github.com/nixos/nixops) our hero wanted to bring this out into the land and let the people rejoice in reliability and a wonderful development experience.
The plugin work itself was straight forward and our hero quickly slayed the first small dragon, at this point things felt good and our hero thought he was going to reach the town of NixOps-AWS very quickly.
But alas! Mypy did not want to go, it said:
`Cannot find implementation or library stub for module named 'nixops'`
Our hero felt a small sliver of life escape from his body. Things were not going to be so easy.
After some frustration our hero discovered there was a [rule of the land of Python](https://www.python.org/dev/peps/pep-0561/) that governed the import of types into the kingdom, more specificaly a very special document (file) called `py.typed`.
Things were looking good.
But no, what the law said did not seem to match reality. How could things be so?
After some frustrating debugging our valiant hero thought to himself "Hmm, I wonder if this is simply a Nix idiosyncrasy", and it turns out indeed it was.
Things that were working in the blessed way of the land of Python (inside a `virtualenv`) were not working the way they were from his home town of Nix (`nix-shell` + `python.withPackages`).
After even more frustrating attempts at reading the mypy documentation and trying to understand how things were supposed to work our hero started questioning his sanity.
This is where things started to get truly interesting.
Our hero started to use a number of powerful weapons, both forged in the land of Python (pdb) & by the mages of UNIX (printf-style-debugging & strace).
After first trying to slay the dragon simply by `strace` and a keen eye our hero did not spot any weak points.
Time to break out a more powerful sword (`pdb`) which also did not divulge any secrets about what was wrong.
Our hero went back to the `strace` output and after a fair bit of thought and analysis a pattern started to emerge. Mypy was looking in the wrong place (i.e. not in in the environment created by `python.withPackages` but in the interpreter store path) and our princess was in another castle!
Our hero went to the pub full of old grumpy men giving out the inner workings of the open source universe (Github) and acquired a copy of Mypy.
He littered the code with print statements & break points.
After a fierce battle full of blood, sweat & tears he ended up in https://github.com/python/mypy/blob/20f7f2dd71c21bde4d3d99f9ab69bf6670c7fa03/mypy/sitepkgs.py and realised that everything came down to the Python `site` module and more specifically https://docs.python.org/3.7/library/site.html#site.getsitepackages which in turn relies on https://docs.python.org/3.7/library/site.html#site.PREFIXES .
Our hero created a copy of the environment created by `python.withPackages` and manually modified it to confirm his findings, and it turned out it was indeed the case.
Our hero had damaged the dragon and it was time for a celebration.
He went out and acquired some mead which he ingested while he typed up his story and waited for the dragon to finally die (the commit caused a mass-rebuild, I had to wait for my repro).
In the end all was good in [NixOps-AWS](https://github.com/nixos/nixops-aws)-town and type checks could run. (PR for that incoming tomorrow).
| adisbladis | 2020-03-14 | 1 | -1/+1 |
| * | Python: introduce NIX_PYTHONEXECUTABLE in order to set sys.executable•••This is needed in case of `python.buildEnv` to make sure sys.executable
does not point to the unwrapped executable.
| Frederik Rietdijk | 2019-07-27 | 1 | -1/+2 |
| * | python.buildEnv: use NIX_PYTHONPATH | Frederik Rietdijk | 2019-07-13 | 1 | -1/+2 |
| * | Add flag to disable PYTHONNOUSERSITE for wrapped binaries in python environments | Tom McLaughlin | 2019-05-13 | 1 | -1/+2 |
| * | python.buildEnv: new argument `makeWrapperArgs`•••`python.buildEnv` would already wrap executables exporting `PYTHONHOME`.
With this change, it is possible to pass in additional arguments to the
underlying `makeWrapper`.
| Frederik Rietdijk | 2018-10-13 | 1 | -1/+3 |
| * | python.buildEnv: always include the $out output•••28299f669adc41e5278372cad952fb1e1165b44b introduced the first Python
packages having multiple outputs. The required outputs were not picked
up by `python.buildEnv` (#31857).
This commit modifies `python.buildEnv` so that it always includes the
$out output and thus fixes #31857.
| Frederik Rietdijk | 2017-12-10 | 1 | -1/+2 |
| * | Python: the pythonModule attribute•••Python libraries or modules now have an attribute `pythonModule = interpreter;` to indicate
they provide Python modules for the specified `interpreter`.
The package set provides the following helper functions:
- hasPythonModule: Check whether a derivation provides a Python module.
- requiredPythonModules: Recurse into a list of Python modules, returning all Python modules that are required.
- makePythonPath: Create a PYTHONPATH from a list of Python modules.
Also included in this commit is:
- disabledIf: Helper function for disabling non-buildPythonPackage functions.
| Frederik Rietdijk | 2017-11-23 | 1 | -3/+4 |
| * | python.buildEnv: add extraOutputsToInstall attribute | Nikolay Amiantov | 2017-09-25 | 1 | -1/+2 |
| * | python.buildEnv: only wrap executables | Robin Gloster | 2017-08-09 | 1 | -1/+3 |
| * | python.buildEnv: undo removal of passthru.python | Frederik Rietdijk | 2017-08-02 | 1 | -0/+1 |
| * | python.buildEnv: fix passthru•••Python envs did not pass through any of the properties the Python
interpreter has. That could be annoying, especially not having
`python.interpreter` which is the path to the interpreter. This commit
fixes the situation and inherit python.passthru.
| Frederik Rietdijk | 2017-08-01 | 1 | -14/+15 |
| * | Python: disable user site-packages for programs and environments.•••Python by default checks a `site-packages` folder in the user's home
folder. We do not want such an impurity and therefore disable it.
Fixes #26846.
| Frederik Rietdijk | 2017-07-31 | 1 | -1/+1 |
| * | python.buildenv: don't filter non-python packages•••python.buildenv is used to build an env that provides binaries that can
import all modules that were passed in to the env.
Before this change it filtered the propagatedBuildInputs to remove all
non-Python packages, thereby possibly reducing the amount of packages
that were referenced. However, Python packages often don't have non-
Python packages as propagatedBuildInputs. And occasionally, we do want
to be able to add other packages to the env.
| Frederik Rietdijk | 2016-09-17 | 1 | -1/+1 |
| * | python: apply wrapper to all packages in python.buildEnv extraLibs•••Currently, when constructing a buildEnv and adding packages via
extraLibs, then binaries in extraLibs cannot access the other Python
modules. An example is having ipython/jupyter in extraLibs; in that case
ipython cannot import any other modules.
| Frederik Rietdijk | 2015-11-30 | 1 | -6/+15 |
| * | python: add .env for convenient nix-shell's | Nikolay Amiantov | 2015-08-17 | 1 | -21/+33 |
| * | python27FullBuildEnv -> python.buildEnv for all interpreters | Domen Kožar | 2014-10-19 | 1 | -3/+7 |
| * | pythonFull -> python with all modules, pythonFullWithPkgs -> buildEnv | Domen Kožar | 2014-10-13 | 1 | -4/+3 |
| * | python-wrapper: add 'ignoreCollisions' parameter (which default to 'false') | Peter Simons | 2014-02-24 | 1 | -2/+3 |
| * | Partial revert of b09f8110dbcb8bc8a1fcdb3e9a5dddb0956aba96•••Didn't mean to commit this change
Signed-off-by: Shea Levy <shea@shealevy.com>
| Shea Levy | 2013-11-19 | 1 | -5/+0 |
| * | nspr: Bump to 4.10.2•••Signed-off-by: Shea Levy <shea@shealevy.com>
| Shea Levy | 2013-11-18 | 1 | -0/+5 |
| * | python-wrapper: split 'extraLibs' into 'stdLibs' and 'extraLibs', and add 'po...•••The default setting for extraLibs used to be the set of modules that come with
python by default but aren't usually enabled in our standard python derivation
because they require additional libraries. This meant that users who want to
*add* libraries to that set had to use a fairly complicated override, to add
more entries without loosing the ones set by default.
After this patch, the "standard libraries" such as "curses' are listed in
stdLibs while the extraLibs argument remains empty by default. This allows
users to override extraLibs without overriding the standard libraries.
Furthermore, the wrapper environment can be messed around with in an
additional 'postBuild' step. One nice application of this build step is
to patch scripts and binaries to use the wrapped python interpreter
instead of the pristine one, thereby enabling them to pick up all
modules that have been configured. The following example shows how this
is done for the 'pylint' utility:
pkgs.python27Full.override {
extraLibs = [pkgs.pylint];
postBuild = ''
cd ${pkgs.pylint}/bin
for i in *; do
rm $out/bin/$i
sed -r -e "s|^exec |exec $out/bin/python -- |" <$i >$out/bin/$i
chmod +x $out/bin/$i
done;
'';
};
| Peter Simons | 2013-11-07 | 1 | -4/+5 |
| * | python-wrapper: recursively include all dependencies of the specified 'extraL...•••This patch means that adding 'matplotlib' to extraLibs will automatically
include 'numpy', too, because matplotlib depends on it.
| Peter Simons | 2013-11-07 | 1 | -1/+3 |
| * | Fix pythonWrapper when all of the binaries come from python•••See discussion in #834
Signed-off-by: Shea Levy <shea@shealevy.com>
| Shea Levy | 2013-10-03 | 1 | -0/+3 |
| * | Re-implement python-wrapper with buildEnv.•••The new wrapper creates an environment that contains all files from
Python and the extra libraries that have been specified. All files are
found at run-time by means of the $PYTHONHOME variable; the wrapper no
longer uses $PYTHONPATH.
| Peter Simons | 2013-10-02 | 1 | -13/+13 |
| * | fix pythonWrapper for non-gnu ln | Florian Friesdorf | 2013-03-25 | 1 | -1/+1 |
| * | recursivePthLoader included via wrapper, not propagated by modules | Florian Friesdorf | 2013-01-11 | 1 | -2/+2 |
| * | python: make pdb.py available as bin/pdb and bin/pdb${python.majorVersion} | Florian Friesdorf | 2012-07-20 | 1 | -1/+1 |
| * | Revert "do not propagate makeWrapper via pythonXYFull"•••This reverts commit 3ee2667e4c60c2ed850da8538cf135fe7f716f30.
svn path=/nixpkgs/branches/stdenv-updates/; revision=32656
| Florian Friesdorf | 2012-02-28 | 1 | -2/+1 |
| * | Revert "pysite support for pythonXYFull wrapper"•••This reverts commit f77b9a16a9ef52951a601997593dc557a42660b9.
svn path=/nixpkgs/branches/stdenv-updates/; revision=32653
| Florian Friesdorf | 2012-02-28 | 1 | -1/+0 |
| * | pysite support for pythonXYFull wrapper•••svn path=/nixpkgs/branches/stdenv-updates/; revision=32593
| Florian Friesdorf | 2012-02-26 | 1 | -0/+1 |
| * | do not propagate makeWrapper via pythonXYFull•••svn path=/nixpkgs/branches/stdenv-updates/; revision=32589
| Florian Friesdorf | 2012-02-26 | 1 | -1/+2 |
| * | symlink python manpage for pythonXYFull•••svn path=/nixpkgs/branches/stdenv-updates/; revision=32588
| Florian Friesdorf | 2012-02-26 | 1 | -0/+2 |
| * | python wrapper comment•••svn path=/nixpkgs/branches/stdenv-updates/; revision=32587
| Florian Friesdorf | 2012-02-26 | 1 | -0/+3 |
| * | * "ensureDir" -> "mkdir -p". "ensureDir" is a rather pointless••• function, so obsolete it.
svn path=/nixpkgs/branches/stdenv-updates/; revision=31644
| Eelco Dolstra | 2012-01-18 | 1 | -1/+1 |
| * | pkgs/development/interpreters/python/wrapper.nix: clean up debug code•••svn path=/nixpkgs/trunk/; revision=23200
| Peter Simons | 2010-08-17 | 1 | -2/+1 |
| * | Added "python-$version-wrapper" expression.•••The python wrapper expression expects a list of Python modules, $extraLibs,
which are added to $PYTHONPATH before executing the actual Python interpreter.
svn path=/nixpkgs/trunk/; revision=23194
| Peter Simons | 2010-08-16 | 1 | -0/+19 |