-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
Python: support installing wheels #15010
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,6 @@ | |
| # https://github.com/pypa/pip/issues/881 | ||
| , setupPyBuildFlags ? [] | ||
|
|
||
| # enable tests by default | ||
| , doCheck ? true | ||
|
|
||
| # DEPRECATED: use propagatedBuildInputs | ||
| , pythonPath ? [] | ||
|
|
||
|
|
@@ -45,6 +42,8 @@ | |
| # Additional flags to pass to "pip install". | ||
| , installFlags ? [] | ||
|
|
||
| , format ? "setup" | ||
|
|
||
| , ... } @ attrs: | ||
|
|
||
|
|
||
|
|
@@ -57,8 +56,51 @@ let | |
| # use setuptools shim (so that setuptools is imported before distutils) | ||
| # pip does the same thing: https://github.com/pypa/pip/pull/3265 | ||
| setuppy = ./run_setup.py; | ||
| # For backwards compatibility, let's use an alias | ||
| doInstallCheck = doCheck; | ||
|
|
||
| formatspecific = | ||
| if format == "wheel" then | ||
| { | ||
| unpackPhase = '' | ||
| mkdir dist | ||
| cp $src dist/"''${src#*-}" | ||
| ''; | ||
|
|
||
| # Wheels are pre-compiled | ||
| buildPhase = attrs.buildPhase or ":"; | ||
| installCheckPhase = attrs.checkPhase or ":"; | ||
|
|
||
| # Wheels don't have any checks to run | ||
| doInstallCheck = attrs.doCheck or false; | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is correct, we indeed don't want to run tests by default when we have a wheel.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's my understanding too |
||
| else if format == "setup" then | ||
| { | ||
| # propagate python/setuptools to active setup-hook in nix-shell | ||
| propagatedBuildInputs = | ||
| propagatedBuildInputs ++ [ python setuptools ]; | ||
|
|
||
| # we copy nix_run_setup.py over so it's executed relative to the root of the source | ||
| # many project make that assumption | ||
| buildPhase = attrs.buildPhase or '' | ||
| runHook preBuild | ||
| cp ${setuppy} nix_run_setup.py | ||
| ${python.interpreter} nix_run_setup.py ${lib.optionalString (setupPyBuildFlags != []) ("build_ext " + (lib.concatStringsSep " " setupPyBuildFlags))} bdist_wheel | ||
| runHook postBuild | ||
| ''; | ||
|
|
||
| installCheckPhase = attrs.checkPhase or '' | ||
| runHook preCheck | ||
| ${python.interpreter} nix_run_setup.py test | ||
| runHook postCheck | ||
| ''; | ||
|
|
||
| # We run all tests after software has been installed since that is | ||
| # a common idiom in Python | ||
| # | ||
| # For backwards compatibility, let's use an alias | ||
| doInstallCheck = attrs.doCheck or false; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I am correct this should actually be |
||
| } | ||
| else | ||
| throw "Unsupported format ${format}"; | ||
| in | ||
| python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] // { | ||
| name = namePrefix + name; | ||
|
|
@@ -67,9 +109,6 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] // | |
| ++ [ (ensureNewerSourcesHook { year = "1980"; }) ] | ||
| ++ (lib.optional (lib.hasSuffix "zip" attrs.src.name or "") unzip); | ||
|
|
||
| # propagate python/setuptools to active setup-hook in nix-shell | ||
| propagatedBuildInputs = propagatedBuildInputs ++ [ python setuptools ]; | ||
|
|
||
| pythonPath = pythonPath; | ||
|
|
||
| configurePhase = attrs.configurePhase or '' | ||
|
|
@@ -82,14 +121,8 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] // | |
| runHook postConfigure | ||
| ''; | ||
|
|
||
| # we copy nix_run_setup.py over so it's executed relative to the root of the source | ||
| # many project make that assumption | ||
| buildPhase = attrs.buildPhase or '' | ||
| runHook preBuild | ||
| cp ${setuppy} nix_run_setup.py | ||
| ${python.interpreter} nix_run_setup.py ${lib.optionalString (setupPyBuildFlags != []) ("build_ext " + (lib.concatStringsSep " " setupPyBuildFlags))} bdist_wheel | ||
| runHook postBuild | ||
| ''; | ||
| # Python packages don't have a checkPhase, only a installCheckPhase | ||
| doCheck = false; | ||
|
|
||
| installPhase = attrs.installPhase or '' | ||
| runHook preInstall | ||
|
|
@@ -104,16 +137,6 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] // | |
| runHook postInstall | ||
| ''; | ||
|
|
||
| # We run all tests after software has been installed since that is | ||
| # a common idiom in Python | ||
| doInstallCheck = doInstallCheck; | ||
|
|
||
| installCheckPhase = attrs.checkPhase or '' | ||
| runHook preCheck | ||
| ${python.interpreter} nix_run_setup.py test | ||
| runHook postCheck | ||
| ''; | ||
|
|
||
| postFixup = attrs.postFixup or '' | ||
| wrapPythonPrograms | ||
|
|
||
|
|
@@ -143,4 +166,4 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] // | |
| # a marker for release utilities to discover python packages | ||
| isBuildPythonPackage = python.meta.platforms; | ||
| }; | ||
| }) | ||
| } // formatspecific) | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
If there are only two formats, perhaps calling the option explicitly "useWheel" or similar would be better.
Alternatively, you could just see if the name of the source ends with
.whl(we're already doing something similar to detect if the source is a.zip)Either way, this parameter should be documented with examples
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks for your comments @adnelson
See the first message about why I chose
formatlike this.