Skip to content

Commit

Permalink
Fixup Pip and lock handling of use_system_time.
Browse files Browse the repository at this point in the history
In the Pip case, do not mix the associated env vars into the PEX, just
pass via env var - this need not effect disk layout / potentially double
the number of Pip venvs. In the lock case, ensure old locks use system
time as they have been; only have new locks use this new feature
(unconditionally).
  • Loading branch information
jsirois committed Oct 9, 2024
1 parent aaaab3e commit c3c12e1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pex/cache/dirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def iter_transitive_dependents(self):

PIP = Value(
"pip",
version=0,
version=1,
name="Pip Versions",
description="Isolated Pip caches and Pip PEXes Pex uses to resolve distributions.",
)
Expand Down
10 changes: 6 additions & 4 deletions pex/pip/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ def _pip_installation(

isolated_pip_builder = PEXBuilder(path=chroot.work_dir)
isolated_pip_builder.info.venv = True
# Allow REPRODUCIBLE_BUILDS_ENV PYTHONHASHSEED env var to take effect.
# Allow REPRODUCIBLE_BUILDS_ENV PYTHONHASHSEED env var to take effect if needed.
isolated_pip_builder.info.venv_hermetic_scripts = False
if not use_system_time:
isolated_pip_builder.info.inject_env = REPRODUCIBLE_BUILDS_ENV
for dist_location in iter_distribution_locations():
isolated_pip_builder.add_dist_location(dist=dist_location)
with named_temporary_file(prefix="", suffix=".py", mode="w") as fp:
Expand All @@ -83,7 +81,11 @@ def _pip_installation(
isolated_pip_builder.freeze()
pip_cache = os.path.join(pip_root, "pip_cache")
pip_pex = ensure_venv(PEX(pip_pex_path, interpreter=pip_interpreter))
pip_venv = PipVenv(venv_dir=pip_pex.venv_dir, execute_args=tuple(pip_pex.execute_args()))
pip_venv = PipVenv(
venv_dir=pip_pex.venv_dir,
execute_env=REPRODUCIBLE_BUILDS_ENV if not use_system_time else {},
execute_args=tuple(pip_pex.execute_args()),
)
return Pip(pip=pip_venv, version=version, pip_cache=pip_cache)


Expand Down
2 changes: 2 additions & 0 deletions pex/pip/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def analyze(self, line):
@attr.s(frozen=True)
class PipVenv(object):
venv_dir = attr.ib() # type: str
execute_env = attr.ib() # type: Mapping[str, str]
_execute_args = attr.ib() # type: Tuple[str, ...]

def execute_args(self, *args):
Expand Down Expand Up @@ -431,6 +432,7 @@ def _spawn_pip_isolated(
popen_kwargs["stdout"] = sys.stderr.fileno()
popen_kwargs.update(stderr=subprocess.PIPE)

env.update(self._pip.execute_env)
args = self._pip.execute_args(*command)

rendered_env = " ".join(
Expand Down
5 changes: 5 additions & 0 deletions pex/resolve/lockfile/json_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ def assemble_tag(
prefer_older_binary=get("prefer_older_binary", bool),
use_pep517=get("use_pep517", bool, optional=True),
build_isolation=get("build_isolation", bool),
# N.B.: Although locks are now always generated under SOURCE_DATE_EPOCH=fixed and
# PYTHONHASHSEED=0 (aka: `use_system_time=False`), that did not use to be the case. In
# those old locks there was no "use_system_time" field.
use_system_time=get("use_system_time", bool, optional=True) or True,
),
transitive=get("transitive", bool),
excluded=excluded,
Expand Down Expand Up @@ -399,6 +403,7 @@ def as_json_data(
"prefer_older_binary": lockfile.prefer_older_binary,
"use_pep517": lockfile.use_pep517,
"build_isolation": lockfile.build_isolation,
"use_system_time": lockfile.use_system_time,
"transitive": lockfile.transitive,
"excluded": [str(exclude) for exclude in lockfile.excluded],
"overridden": [str(override) for override in lockfile.overridden],
Expand Down
4 changes: 3 additions & 1 deletion pex/resolve/lockfile/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def extract_requirement(req):
prefer_older_binary=build_configuration.prefer_older_binary,
use_pep517=build_configuration.use_pep517,
build_isolation=build_configuration.build_isolation,
use_system_time=build_configuration.use_system_time,
transitive=transitive,
excluded=SortedTuple(excluded),
overridden=SortedTuple(overridden),
Expand All @@ -130,6 +131,7 @@ def extract_requirement(req):
prefer_older_binary = attr.ib() # type: bool
use_pep517 = attr.ib() # type: Optional[bool]
build_isolation = attr.ib() # type: bool
use_system_time = attr.ib() # type: bool
transitive = attr.ib() # type: bool
excluded = attr.ib() # type: SortedTuple[Requirement]
overridden = attr.ib() # type: SortedTuple[Requirement]
Expand All @@ -147,7 +149,7 @@ def build_configuration(self):
prefer_older_binary=self.prefer_older_binary,
use_pep517=self.use_pep517,
build_isolation=self.build_isolation,
use_system_time=False,
use_system_time=self.use_system_time,
)

def dependency_configuration(self):
Expand Down
1 change: 1 addition & 0 deletions tests/integration/cli/commands/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
prefer_older_binary=False,
use_pep517=None,
build_isolation=True,
use_system_time=False,
transitive=True,
excluded=SortedTuple(),
overridden=SortedTuple(),
Expand Down

0 comments on commit c3c12e1

Please sign in to comment.