New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: indicate whether a derivation provides a Python module #30606
Conversation
pkgs/top-level/python-packages.nix
Outdated
hasPythonModule = drv: (hasAttr "pythonModule" drv) && ( (getAttr "pythonModule" drv) == python); | ||
|
||
# Recurse into a list of Python modules, returning all Python modules that are required. | ||
requiredModules = drvs: filter hasPythonModule (closePropagation drvs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe name it requiredPythonModules
or even recursiveFilterPythonModules
. The meaning of requiredModules
is hard to understand if you don't think in the context of Python modules.
When I first tried python package using stdenv.mkDerivation {
#...
buildInputs = with pythonPackages; [ foo ];
} is not automatically transformed into stdenv.mkDerivation rec {
#...
buildInputs = with pythonPackages; [ foo ];
pythonPath = requiredModules buildInputs;
} Or perhaps even do this in bash. Say, we could call |
@veprbl certain inputs are only needed at build or test time. Also, non-python dependencies should not be added to Certain things can be done in |
e2b3956
to
e2fc437
Compare
@FRidh Things that are only needed at build and test time go to Also, |
I had to clean up some space and disable some packages that were too long to recompile but finally ended up ok. It fixed the problem for me (1st version of the PR, you 've pushed a new version since then but I can't recompile on every push sry xD). |
Good to hear.
Yes and no. Currently the Python interpreter comes with a setup hook which adds the site-packages folders to I would prefer to do most of this in Nix instead of through a setup hook. In case of our |
507e326
to
2b6152e
Compare
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.
pythonPath is used to create the eventual wrappers. It does not recurse into the Python dependencies, which means e.g. requests doesn't haven its dependencies.
…Derivation does not use
I've pushed this to staging. |
Motivation for this change
The
python-packages.nix
file contains derivations that provide Python modules. Sometimes, one needs to determine whether packages provide Python modules. Currently, a hook is used for this, but the hook does not check whether thesite-packages
correspond to the right Python derivation.Derivations providing Python modules should be marked with
isPythonModule = python;
wherepython
is the interpreter that was used to build the module.Most of the derivations in
python-packages.nix
are produced withbuildPythonPackage
but not all of them. Therefore, a helper functiontoPythonModule
is provided that sets this attribute, and corrects the name as well.Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)