python.pipInstallHook: avoid producing wrong direct_url.json file

When installing many python packages, a `direct_url.json` file appeared in the lib directory. Example:

```sh
➤ nix build nixpkgs/29755fec55e58a315b517d431b2be261772f2b80#python3Packages.flask

➤ cat result/lib/python3.10/site-packages/Flask-2.2.3.dist-info/direct_url.json
{"archive_info": {}, "url": "file:///build/Flask-2.2.3/dist/Flask-2.2.3-py3-none-any.whl"}⏎
```

As you can see, that file contains a wrong reference to `/build`.

In https://discuss.python.org/t/pep-610-usage-guidelines-for-linux-distributions/4012/4 there's an explanation on how to avoid this. Here, I'm implementing that change for nixpkgs.

@moduon MT-1075
This commit is contained in:
Jairo Llopis 2023-05-02 13:38:52 +01:00 committed by Frederik Rietdijk
parent e6a40d6f7c
commit bff6c67911

View file

@ -10,9 +10,7 @@ pipInstallPhase() {
mkdir -p "$out/@pythonSitePackages@"
export PYTHONPATH="$out/@pythonSitePackages@:$PYTHONPATH"
pushd dist || return 1
@pythonInterpreter@ -m pip install ./*.whl --no-index --no-warn-script-location --prefix="$out" --no-cache $pipInstallFlags
popd || return 1
@pythonInterpreter@ -m pip install $pname --find-links dist --no-index --no-warn-script-location --prefix="$out" --no-cache $pipInstallFlags
runHook postInstall
echo "Finished executing pipInstallPhase"