Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at release-19.03 53 lines 1.6 kB view raw
1# This function provides specific bits for building a setuptools-based Python package. 2 3{ lib 4, python 5}: 6 7{ 8# passed to "python setup.py build_ext" 9# https://github.com/pypa/pip/issues/881 10# Rename to `buildOptions` because it is not setuptools specific? 11 setupPyBuildFlags ? [] 12# Execute before shell hook 13, preShellHook ? "" 14# Execute after shell hook 15, postShellHook ? "" 16, ... } @ attrs: 17 18let 19 options = lib.concatMapStringsSep " " (option: "--global-option ${option}") setupPyBuildFlags; 20in attrs // { 21 buildPhase = attrs.buildPhase or '' 22 runHook preBuild 23 mkdir -p dist 24 echo "Creating a wheel..." 25 ${python.pythonForBuild.interpreter} -m pip wheel --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist ${options} . 26 echo "Finished creating a wheel..." 27 runHook postBuild 28 ''; 29 30 installCheckPhase = '' 31 runHook preCheck 32 echo "No checkPhase defined. Either provide a checkPhase or disable tests in case tests are not available."; exit 1 33 runHook postCheck 34 ''; 35 36 # With Python it's a common idiom to run the tests 37 # after the software has been installed. 38 doCheck = attrs.doCheck or true; 39 40 shellHook = attrs.shellHook or '' 41 ${preShellHook} 42 # Long-term setup.py should be dropped. 43 if [ -e pyproject.toml ]; then 44 tmp_path=$(mktemp -d) 45 export PATH="$tmp_path/bin:$PATH" 46 export PYTHONPATH="$tmp_path/${python.pythonForBuild.sitePackages}:$PYTHONPATH" 47 mkdir -p $tmp_path/${python.pythonForBuild.sitePackages} 48 ${python.pythonForBuild.pkgs.bootstrapped-pip}/bin/pip install -e . --prefix $tmp_path >&2 49 fi 50 ${postShellHook} 51 ''; 52 53}