Merge pull request #474 from TyberiusPrime/install_requires

fix requirements extraction in setuptools post b6fcbbd
This commit is contained in:
DavHau 2022-07-06 08:30:34 +02:00 committed by GitHub
commit 51caf584f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,6 +33,11 @@ let
pkgs.symlinkJoin { pkgs.symlinkJoin {
name = "${python_env.name}-patched"; name = "${python_env.name}-patched";
paths = [ python_env ]; paths = [ python_env ];
buildInputs = [
# prefer binary wrapper - but if that's not available (e.g. nixos 21.05)
# use the regular shell script wrapper
pkgs.makeBinaryWrapper or pkgs.makeWrapper
];
postBuild = '' postBuild = ''
### Distutils ### Distutils
# symlinks to files # symlinks to files
@ -69,10 +74,15 @@ let
rm ${site_pkgs_dir}/setuptools/__pycache__/__init__.* rm ${site_pkgs_dir}/setuptools/__pycache__/__init__.*
fi fi
# fix executables # fix executables
for f in $(ls ${python_env}/bin); do shopt -s nullglob
sed -i "s|${python_env}|$out|g" $out/bin/$f for f in ${python_env}/bin/*; do
sed -i "/NIX_PYTHONPATH/a export PYTHONPATH=$out\/lib\/python${major}.${minor}" $out/bin/$f f=$(basename "$f")
# wrap it once more, set PYTHONPATH, ignoring NIXPYTHON_PATH and NIX_PYTHONEXECUTABLE
rm "$out/bin/$f" # remove the existing symlink
makeWrapper "${python_env}/bin/$f" "$out/bin/$f" \
--set PYTHONPATH "$out/lib/python${major}.${minor}"
done done
''; '';
}; };
@ -94,6 +104,9 @@ let
f.close(); f.close();
exec(compile(code, __file__, 'exec')) exec(compile(code, __file__, 'exec'))
''; '';
# note on SETUPTOOLS_USE_DISTUTILS=stdlib: Restore old setuptools behaviour (since
# https://github.com/pypa/setuptools/commit/b6fcbbd00cb6d5607c9272dec452a50457bdb292),
# to keep it working with mach-nix.
script = pyVersions: '' script = pyVersions: ''
mkdir $out mkdir $out
${concatStringsSep "\n" (forEach pythonInterpreters (interpreter: ${concatStringsSep "\n" (forEach pythonInterpreters (interpreter:
@ -106,7 +119,7 @@ let
# only use selected interpreters # only use selected interpreters
in optionalString (pyVersions == [] || elem v pyVersions) '' in optionalString (pyVersions == [] || elem v pyVersions) ''
echo "extracting metadata for python${v}" echo "extracting metadata for python${v}"
out_file=$out/python${v}.json ${py}/bin/python -c "${setuptools_shim}" install &> $out/python${v}.log || true SETUPTOOLS_USE_DISTUTILS=stdlib out_file=$out/python${v}.json ${py}/bin/python -c "${setuptools_shim}" install &> $out/python${v}.log || true
'' ''
))} ))}
''; '';
@ -114,7 +127,7 @@ let
chmod +x setup.py || true chmod +x setup.py || true
mkdir $out mkdir $out
echo "extracting dependencies" echo "extracting dependencies"
out_file=$out/python.json ${py}/bin/python -c "${setuptools_shim}" install &> $out/python.log || true SETUPTOOLS_USE_DISTUTILS=stdlib out_file=$out/python.json ${py}/bin/python -c "${setuptools_shim}" install &> $out/python.log || true
''; '';
base_derivation = pyVersions: with pkgs; { base_derivation = pyVersions: with pkgs; {
buildInputs = [ unzip pkg-config ]; buildInputs = [ unzip pkg-config ];