Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pythonPackages.pip: make reproducible #102222

Merged
merged 1 commit into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pipInstallPhase() {

pushd dist || return 1
mkdir tmpbuild
NIX_PIP_INSTALL_TMPDIR=tmpbuild @pythonInterpreter@ -m pip install ./*.whl --no-index --prefix="$out" --no-cache $pipInstallFlags
@pythonInterpreter@ -m pip install ./*.whl --no-index --prefix="$out" --no-cache $pipInstallFlags
rm -rf tmpbuild
popd || return 1

Expand Down
5 changes: 5 additions & 0 deletions pkgs/development/python-modules/bootstrapped-pip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ stdenv.mkDerivation rec {
];

postPatch = ''
# Apply the pip reproducible patch
pushd "${pip.src.name}"
patch -p1 < ${../pip/reproducible.patch}
popd

mkdir -p $out/bin
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/python-modules/pip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ buildPythonPackage rec {
};

# Remove when solved https://github.com/NixOS/nixpkgs/issues/81441
# Also update pkgs/development/interpreters/python/hooks/pip-install-hook.sh accordingly
# See also https://github.com/pypa/pip/issues/7808
patches = [ ./reproducible.patch ];

nativeBuildInputs = [ bootstrapped-pip ];
Expand Down
38 changes: 25 additions & 13 deletions pkgs/development/python-modules/pip/reproducible.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
diff --git a/src/pip/_internal/operations/install/wheel.py b/src/pip/_internal/operations/install/wheel.py
index e7315ee4..4e36b03d 100644
--- a/src/pip/_internal/operations/install/wheel.py
+++ b/src/pip/_internal/operations/install/wheel.py
@@ -615,6 +615,8 @@ def install_wheel(
direct_url=None, # type: Optional[DirectUrl]
):
# type: (...) -> None
+ _temp_dir_for_testing = (
+ _temp_dir_for_testing or os.environ.get("NIX_PIP_INSTALL_TMPDIR"))
with TempDirectory(
path=_temp_dir_for_testing, kind="unpacked-wheel"
) as unpacked_dir, ZipFile(wheel_path, allowZip64=True) as z:
diff --git a/src/pip/_internal/utils/temp_dir.py b/src/pip/_internal/utils/temp_dir.py
index 201ba6d98..f1569fecd 100644
--- a/src/pip/_internal/utils/temp_dir.py
+++ b/src/pip/_internal/utils/temp_dir.py
@@ -3,6 +3,7 @@ from __future__ import absolute_import
import errno
import itertools
import logging
+import os
import os.path
import tempfile
from contextlib import contextmanager
@@ -181,6 +182,11 @@ class TempDirectory(object):
# symlinked to another directory. This tends to confuse build
# scripts, so we canonicalize the path by traversing potential
# symlinks here.
+ if "SOURCE_DATE_EPOCH" in os.environ:
+ path = os.path.join(tempfile.gettempdir(), "pip-{}-immobile".format(kind))
+ os.mkdir(path)
+ return path
+
path = os.path.realpath(
tempfile.mkdtemp(prefix="pip-{}-".format(kind))
)