summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorFrederik Rietdijk <fridh@fridh.nl>2019-02-17 20:33:30 +0100
committerFrederik Rietdijk <fridh@fridh.nl>2019-02-23 20:05:19 +0100
commite7b4608d029dec2d14758837c0378fcf4746f3be (patch)
tree308d6b818c97f88e4df83b502219ef0f680ec4c2 /pkgs
parent073602c1432595b90499a685386dd5dca9477f5f (diff)
downloadnixpkgs-e7b4608d029dec2d14758837c0378fcf4746f3be.tar
nixpkgs-e7b4608d029dec2d14758837c0378fcf4746f3be.tar.gz
nixpkgs-e7b4608d029dec2d14758837c0378fcf4746f3be.tar.bz2
nixpkgs-e7b4608d029dec2d14758837c0378fcf4746f3be.tar.lz
nixpkgs-e7b4608d029dec2d14758837c0378fcf4746f3be.tar.xz
nixpkgs-e7b4608d029dec2d14758837c0378fcf4746f3be.tar.zst
nixpkgs-e7b4608d029dec2d14758837c0378fcf4746f3be.zip
buildPythonPackage: initial support for PEP 517
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/development/interpreters/python/build-python-package-pyproject.nix53
-rw-r--r--pkgs/development/interpreters/python/build-python-package.nix4
2 files changed, 56 insertions, 1 deletions
diff --git a/pkgs/development/interpreters/python/build-python-package-pyproject.nix b/pkgs/development/interpreters/python/build-python-package-pyproject.nix
new file mode 100644
index 00000000000..86c450fcf92
--- /dev/null
+++ b/pkgs/development/interpreters/python/build-python-package-pyproject.nix
@@ -0,0 +1,53 @@
+# This function provides specific bits for building a setuptools-based Python package.
+
+{ lib
+, python
+}:
+
+{
+# passed to "python setup.py build_ext"
+# https://github.com/pypa/pip/issues/881
+# Rename to `buildOptions` because it is not setuptools specific?
+  setupPyBuildFlags ? []
+# Execute before shell hook
+, preShellHook ? ""
+# Execute after shell hook
+, postShellHook ? ""
+, ... } @ attrs:
+
+let
+  options = lib.concatMapStringsSep " " (option: "--global-option ${option}") setupPyBuildFlags;
+in attrs // {
+  buildPhase = attrs.buildPhase or ''
+    runHook preBuild
+    mkdir -p dist
+    echo "Creating a wheel..."
+    ${python.pythonForBuild.interpreter} -m pip wheel --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist ${options} .
+    echo "Finished creating a wheel..."
+    runHook postBuild
+  '';
+
+  installCheckPhase = ''
+    runHook preCheck
+    echo "No checkPhase defined. Either provide a checkPhase or disable tests in case tests are not available."; exit 1
+    runHook postCheck
+  '';
+
+  # With Python it's a common idiom to run the tests
+  # after the software has been installed.
+  doCheck = attrs.doCheck or true;
+
+  shellHook = attrs.shellHook or ''
+    ${preShellHook}
+    # Long-term setup.py should be dropped.
+    if [ -e pyproject.toml ]; then
+      tmp_path=$(mktemp -d)
+      export PATH="$tmp_path/bin:$PATH"
+      export PYTHONPATH="$tmp_path/${python.pythonForBuild.sitePackages}:$PYTHONPATH"
+      mkdir -p $tmp_path/${python.pythonForBuild.sitePackages}
+      ${python.pythonForBuild.pkgs.bootstrapped-pip}/bin/pip install -e . --prefix $tmp_path >&2
+    fi
+    ${postShellHook}
+  '';
+
+}
\ No newline at end of file
diff --git a/pkgs/development/interpreters/python/build-python-package.nix b/pkgs/development/interpreters/python/build-python-package.nix
index b664cf0b14f..98322312f7f 100644
--- a/pkgs/development/interpreters/python/build-python-package.nix
+++ b/pkgs/development/interpreters/python/build-python-package.nix
@@ -17,6 +17,7 @@
 
 let
   setuptools-specific = import ./build-python-package-setuptools.nix { inherit lib python; };
+  pyproject-specific = import ./build-python-package-pyproject.nix { inherit lib python; };
   flit-specific = import ./build-python-package-flit.nix { inherit python flit; };
   wheel-specific = import ./build-python-package-wheel.nix { };
   common = import ./build-python-package-common.nix { inherit python; };
@@ -37,7 +38,8 @@ format ? "setuptools"
 
 let
   formatspecific =
-    if format == "setuptools" then common (setuptools-specific attrs)
+    if format == "pyproject" then common (pyproject-specific attrs)
+    else if format == "setuptools" then common (setuptools-specific attrs)
     else if format == "flit" then common (flit-specific attrs)
     else if format == "wheel" then common (wheel-specific attrs)
     else if format == "other" then {}