Skip to content

Commit

Permalink
Fixup dep tracking sha1 vs sha256 mismatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirois committed Oct 17, 2024
1 parent 168fce0 commit e5fade4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
23 changes: 6 additions & 17 deletions pex/cli/commands/cache/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@

from pex.cache import access as cache_access
from pex.cache import data as cache_data
from pex.cache.dirs import (
AtomicCacheDir,
BootstrapDir,
CacheDir,
InstalledWheelDir,
UnzipDir,
VenvDirs,
)
from pex.cache.dirs import AtomicCacheDir, BootstrapDir, CacheDir, InstalledWheelDir, VenvDirs
from pex.cli.command import BuildTimeCommand
from pex.cli.commands.cache.bytes import ByteAmount, ByteUnits
from pex.cli.commands.cache.du import DiskUsage
Expand Down Expand Up @@ -542,12 +535,9 @@ def prune_unused_deps(additional=False):
return unused_wheels

cutoff = self.options.cutoff
pex_dirs = OrderedDict(
cache_access.last_access_before(cutoff.cutoff)
) # type: OrderedDict[Union[UnzipDir, VenvDirs], float]
pex_hashes_to_prune = set(pex_dir.pex_hash for pex_dir in pex_dirs)
last_access_by_pex_hash = {
pex_dir.pex_hash: last_access for pex_dir, last_access in pex_dirs.items()
pex_dirs = OrderedDict(cache_access.last_access_before(cutoff.cutoff))
pex_hashes_to_prune = {
pex_dir.pex_hash: (pex_dir, last_access) for pex_dir, last_access in pex_dirs.items()
}

# True to prune the Pip version completely, False to just prune the Pip PEX.
Expand Down Expand Up @@ -660,9 +650,8 @@ def spawn_remove(args):
execute_parallel(inputs=pip_removes, spawn_func=spawn_remove),
):
removes_by_pip[pip.version.value] += remove_count
cache_access.record_access(
pip.pex_dir, last_access=last_access_by_pex_hash[pip.pex_hash]
)
pex_dir, last_access = pex_hashes_to_prune[pip.pex_hash]
cache_access.record_access(pex_dir, last_access=last_access)
if removes_by_pip:
total = sum(removes_by_pip.values())
print(
Expand Down
3 changes: 2 additions & 1 deletion pex/pex_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ def execv(
def ensure_venv(
pex, # type: PEX
collisions_ok=True, # type: bool
copy_mode=None, # type: Optional[CopyMode.Value]
):
# type: (...) -> VenvPex
pex_info = pex.pex_info()
Expand Down Expand Up @@ -578,7 +579,7 @@ def ensure_venv(
# so we'll not have a stable base there to symlink from. As such, always copy
# for loose PEXes to ensure the PEX_ROOT venv is stable in the face of
# modification of the source loose PEX.
copy_mode = (
copy_mode = copy_mode or (
CopyMode.SYMLINK
if (pex.layout != Layout.LOOSE and not pex_info.venv_site_packages_copies)
else CopyMode.LINK
Expand Down
14 changes: 11 additions & 3 deletions pex/pex_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from pex.interpreter import PythonInterpreter
from pex.layout import Layout
from pex.orderedset import OrderedSet
from pex.pep_376 import InstalledWheel
from pex.pex import PEX
from pex.pex_info import PexInfo
from pex.sh_boot import create_sh_boot_script
Expand Down Expand Up @@ -373,9 +374,16 @@ def _add_dist(
relpath = os.path.relpath(filename, path)
target = os.path.join(target_dir, relpath)
self._copy_or_link(filename, target, label=dist_name)
return fingerprint or (
CacheHelper.hash(path) if is_wheel_file else CacheHelper.dir_hash(path)
)
if fingerprint:
return fingerprint
if not is_wheel_file:
try:
installed_wheel = InstalledWheel.load(path)
if installed_wheel.fingerprint:
return installed_wheel.fingerprint
except InstalledWheel.LoadError:
pass
return CacheHelper.hash(path) if is_wheel_file else CacheHelper.dir_hash(path)

def add_distribution(
self,
Expand Down
2 changes: 1 addition & 1 deletion pex/pip/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _create_pip(

pip_interpreter = interpreter or PythonInterpreter.get()
pex = PEX(pip_pex.path, interpreter=pip_interpreter)
venv_pex = ensure_venv(pex)
venv_pex = ensure_venv(pex, copy_mode=CopyMode.SYMLINK)
pex_hash = pex.pex_info().pex_hash
production_assert(pex_hash is not None)
pip_venv = PipVenv(
Expand Down

0 comments on commit e5fade4

Please sign in to comment.