forked from NixOS/nixpkgs
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split buildPythonPackage into setup hooks
This commit splits the `buildPythonPackage` into multiple setup hooks. Generally, Python packages are built from source to wheels using `setuptools`. The wheels are then installed with `pip`. Tests were often called with `python setup.py test` but this is less common nowadays. Most projects now use a different entry point for running tests, typically `pytest` or `nosetests`. Since the wheel format was introduced more tools were built to generate these, e.g. `flit`. Since PEP 517 is provisionally accepted, defining a build-system independent format (`pyproject.toml`), `pip` can now use that format to execute the correct build-system. In the past I've added support for PEP 517 (`pyproject`) to the Python builder, resulting in a now rather large builder. Furthermore, it was not possible to reuse components elsewhere. Therefore, the builder is now split into multiple setup hooks. The `setuptoolsCheckHook` is included now by default but in time it should be removed from `buildPythonPackage` to make it easier to use another hook (curently one has to pass in `dontUseSetuptoolsCheck`).
- Loading branch information
Showing
28 changed files
with
500 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
pkgs/development/interpreters/python/build-python-package-common.nix
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
pkgs/development/interpreters/python/build-python-package-flit.nix
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
pkgs/development/interpreters/python/build-python-package-pyproject.nix
This file was deleted.
Oops, something went wrong.
60 changes: 0 additions & 60 deletions
60
pkgs/development/interpreters/python/build-python-package-setuptools.nix
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
pkgs/development/interpreters/python/build-python-package-wheel.nix
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
pkgs/development/interpreters/python/build-python-package.nix
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Hooks for building Python packages. | ||
{ python | ||
, callPackage | ||
, makeSetupHook | ||
}: | ||
|
||
let | ||
pythonInterpreter = python.pythonForBuild.interpreter; | ||
pythonSitePackages = python.sitePackages; | ||
pythonCheckInterpreter = python.interpreter; | ||
setuppy = ../run_setup.py; | ||
in rec { | ||
|
||
flitBuildHook = callPackage ({ flit }: | ||
makeSetupHook { | ||
name = "flit-build-hook"; | ||
deps = [ flit ]; | ||
substitutions = { | ||
inherit pythonInterpreter; | ||
}; | ||
} ./flit-build-hook.sh) {}; | ||
|
||
pipBuildHook = callPackage ({ pip }: | ||
makeSetupHook { | ||
name = "pip-build-hook.sh"; | ||
deps = [ pip ]; | ||
substitutions = { | ||
inherit pythonInterpreter pythonSitePackages; | ||
}; | ||
} ./pip-build-hook.sh) {}; | ||
|
||
pipInstallHook = callPackage ({ pip }: | ||
makeSetupHook { | ||
name = "pip-install-hook"; | ||
deps = [ pip ]; | ||
substitutions = { | ||
inherit pythonInterpreter pythonSitePackages; | ||
}; | ||
} ./pip-install-hook.sh) {}; | ||
|
||
pytestCheckHook = callPackage ({ pytest }: | ||
makeSetupHook { | ||
name = "pytest-check-hook"; | ||
deps = [ pytest ]; | ||
substitutions = { | ||
inherit pythonCheckInterpreter; | ||
}; | ||
} ./pytest-check-hook.sh) {}; | ||
|
||
pythonCatchConflictsHook = callPackage ({ setuptools }: | ||
makeSetupHook { | ||
name = "python-catch-conflicts-hook"; | ||
deps = [ setuptools ]; | ||
substitutions = { | ||
inherit pythonInterpreter; | ||
catchConflicts=../catch_conflicts/catch_conflicts.py; | ||
}; | ||
} ./python-catch-conflicts-hook.sh) {}; | ||
|
||
pythonImportsCheckHook = callPackage ({}: | ||
makeSetupHook { | ||
name = "python-imports-check-hook.sh"; | ||
substitutions = { | ||
inherit pythonCheckInterpreter; | ||
}; | ||
} ./python-imports-check-hook.sh) {}; | ||
|
||
pythonRemoveBinBytecodeHook = callPackage ({ }: | ||
makeSetupHook { | ||
name = "python-remove-bin-bytecode-hook"; | ||
} ./python-remove-bin-bytecode-hook.sh) {}; | ||
|
||
setuptoolsBuildHook = callPackage ({ setuptools, wheel }: | ||
makeSetupHook { | ||
name = "setuptools-setup-hook"; | ||
deps = [ setuptools wheel ]; | ||
substitutions = { | ||
inherit pythonInterpreter pythonSitePackages setuppy; | ||
}; | ||
} ./setuptools-build-hook.sh) {}; | ||
|
||
setuptoolsCheckHook = callPackage ({ setuptools }: | ||
makeSetupHook { | ||
name = "setuptools-check-hook"; | ||
deps = [ setuptools ]; | ||
substitutions = { | ||
inherit pythonCheckInterpreter setuppy; | ||
}; | ||
} ./setuptools-check-hook.sh) {}; | ||
|
||
wheelUnpackHook = callPackage ({ }: | ||
makeSetupHook { | ||
name = "wheel-unpack-hook.sh"; | ||
} ./wheel-unpack-hook.sh) {}; | ||
} |
15 changes: 15 additions & 0 deletions
15
pkgs/development/interpreters/python/hooks/flit-build-hook.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Setup hook for flit | ||
echo "Sourcing flit-build-hook" | ||
|
||
flitBuildPhase () { | ||
echo "Executing flitBuildPhase" | ||
preBuild | ||
@pythonInterpreter@ -m flit build --format wheel | ||
postBuild | ||
echo "Finished executing flitBuildPhase" | ||
} | ||
|
||
if [ -z "$dontUseFlitBuild" ] && [ -z "$buildPhase" ]; then | ||
echo "Using flitBuildPhase" | ||
buildPhase=flitBuildPhase | ||
fi |
Oops, something went wrong.