summaryrefslogtreecommitdiff
path: root/pkgs/development/interpreters/python/wrapper.nix (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Make venv change work on DarwinAlex O'Brien2024-03-011-1/+1
| | | | | | | | | | | | | | | | | | 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.
* Fix venv creation in Python environmentsColin Putney2024-03-011-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* treewide: use optionalString instead of 'then ""'Felix Buehler2023-06-241-1/+1
|
* python-wrapper: use makeBinaryWrapperAtemu2022-04-201-2/+2
| | | | | 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.
* treewide: Fix various tools wrappers "with packages"John Ericson2021-03-021-4/+9
| | | | | | | | | | | 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
* pkgs/development/interpreters: stdenv.lib -> libBen Siraphob2021-01-231-3/+3
|
* Python: introduce NIX_PYTHONPREFIX in order to set site.PREFIXESadisbladis2020-03-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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).
* Python: introduce NIX_PYTHONEXECUTABLE in order to set sys.executableFrederik Rietdijk2019-07-271-1/+2
| | | | | This is needed in case of `python.buildEnv` to make sure sys.executable does not point to the unwrapped executable.
* python.buildEnv: use NIX_PYTHONPATHFrederik Rietdijk2019-07-131-1/+2
|
* Add flag to disable PYTHONNOUSERSITE for wrapped binaries in python environmentsTom McLaughlin2019-05-131-1/+2
|
* python.buildEnv: new argument `makeWrapperArgs`Frederik Rietdijk2018-10-131-1/+3
| | | | | | `python.buildEnv` would already wrap executables exporting `PYTHONHOME`. With this change, it is possible to pass in additional arguments to the underlying `makeWrapper`.
* python.buildEnv: always include the $out outputFrederik Rietdijk2017-12-101-1/+2
| | | | | | | | | 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.
* Python: the pythonModule attributeFrederik Rietdijk2017-11-231-3/+4
| | | | | | | | | | | | | | 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.
* python.buildEnv: add extraOutputsToInstall attributeNikolay Amiantov2017-09-251-1/+2
|
* python.buildEnv: only wrap executablesRobin Gloster2017-08-091-1/+3
|
* python.buildEnv: undo removal of passthru.pythonFrederik Rietdijk2017-08-021-0/+1
|
* python.buildEnv: fix passthruFrederik Rietdijk2017-08-011-14/+15
| | | | | | | 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.
* Python: disable user site-packages for programs and environments.Frederik Rietdijk2017-07-311-1/+1
| | | | | | 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.
* python.buildenv: don't filter non-python packagesFrederik Rietdijk2016-09-171-1/+1
| | | | | | | | | | | 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.
* python: apply wrapper to all packages in python.buildEnv extraLibsFrederik Rietdijk2015-11-301-6/+15
| | | | | | | 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.
* python: add .env for convenient nix-shell'sNikolay Amiantov2015-08-171-21/+33
|
* python27FullBuildEnv -> python.buildEnv for all interpretersDomen Kožar2014-10-191-3/+7
|
* pythonFull -> python with all modules, pythonFullWithPkgs -> buildEnvDomen Kožar2014-10-131-4/+3
|
* python-wrapper: add 'ignoreCollisions' parameter (which default to 'false')Peter Simons2014-02-241-2/+3
|
* Partial revert of b09f8110dbcb8bc8a1fcdb3e9a5dddb0956aba96Shea Levy2013-11-191-5/+0
| | | | | | Didn't mean to commit this change Signed-off-by: Shea Levy <shea@shealevy.com>
* nspr: Bump to 4.10.2Shea Levy2013-11-181-0/+5
| | | | Signed-off-by: Shea Levy <shea@shealevy.com>
* python-wrapper: split 'extraLibs' into 'stdLibs' and 'extraLibs', and add ↵Peter Simons2013-11-071-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 'postBuild' step 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; ''; };
* python-wrapper: recursively include all dependencies of the specified ↵Peter Simons2013-11-071-1/+3
| | | | | | | 'extraLibs' in the generated environment This patch means that adding 'matplotlib' to extraLibs will automatically include 'numpy', too, because matplotlib depends on it.
* Fix pythonWrapper when all of the binaries come from pythonShea Levy2013-10-031-0/+3
| | | | | | See discussion in #834 Signed-off-by: Shea Levy <shea@shealevy.com>
* Re-implement python-wrapper with buildEnv.Peter Simons2013-10-021-13/+13
| | | | | | | 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.
* fix pythonWrapper for non-gnu lnFlorian Friesdorf2013-03-251-1/+1
|
* recursivePthLoader included via wrapper, not propagated by modulesFlorian Friesdorf2013-01-111-2/+2
|
* python: make pdb.py available as bin/pdb and bin/pdb${python.majorVersion}Florian Friesdorf2012-07-201-1/+1
|
* Revert "do not propagate makeWrapper via pythonXYFull"Florian Friesdorf2012-02-281-2/+1
| | | | | | This reverts commit 3ee2667e4c60c2ed850da8538cf135fe7f716f30. svn path=/nixpkgs/branches/stdenv-updates/; revision=32656
* Revert "pysite support for pythonXYFull wrapper"Florian Friesdorf2012-02-281-1/+0
| | | | | | This reverts commit f77b9a16a9ef52951a601997593dc557a42660b9. svn path=/nixpkgs/branches/stdenv-updates/; revision=32653
* pysite support for pythonXYFull wrapperFlorian Friesdorf2012-02-261-0/+1
| | | | svn path=/nixpkgs/branches/stdenv-updates/; revision=32593
* do not propagate makeWrapper via pythonXYFullFlorian Friesdorf2012-02-261-1/+2
| | | | svn path=/nixpkgs/branches/stdenv-updates/; revision=32589
* symlink python manpage for pythonXYFullFlorian Friesdorf2012-02-261-0/+2
| | | | svn path=/nixpkgs/branches/stdenv-updates/; revision=32588
* python wrapper commentFlorian Friesdorf2012-02-261-0/+3
| | | | svn path=/nixpkgs/branches/stdenv-updates/; revision=32587
* * "ensureDir" -> "mkdir -p". "ensureDir" is a rather pointlessEelco Dolstra2012-01-181-1/+1
| | | | | | function, so obsolete it. svn path=/nixpkgs/branches/stdenv-updates/; revision=31644
* pkgs/development/interpreters/python/wrapper.nix: clean up debug codePeter Simons2010-08-171-2/+1
| | | | svn path=/nixpkgs/trunk/; revision=23200
* Added "python-$version-wrapper" expression.Peter Simons2010-08-161-0/+19
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