Skip to content

Commit

Permalink
Continue to populate empty code caches for back compat.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirois committed Nov 3, 2024
1 parent 3210cfd commit 0ef0ff4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
23 changes: 12 additions & 11 deletions pex/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ def _ensure_installed(
bootstrap_cache = BootstrapDir.create(
pex_info.bootstrap_hash, pex_root=pex_info.pex_root
)
if pex_info.code_hash is None:
raise AssertionError(
"Expected code_hash to be populated for {}.".format(layout)
)
code_cache = UserCodeDir.create(pex_info.code_hash, pex_root=pex_info.pex_root)

with atomic_directory(
bootstrap_cache, source=layout.bootstrap_strip_prefix()
Expand All @@ -357,18 +362,14 @@ def _ensure_installed(
install_to=install_to,
)

if pex_info.code_hash:
code_cache = UserCodeDir.create(
pex_info.code_hash, pex_root=pex_info.pex_root
with atomic_directory(code_cache) as code_chroot:
if not code_chroot.is_finalized():
layout.extract_code(code_chroot.work_dir)
for path in os.listdir(code_cache):
os.symlink(
os.path.join(os.path.relpath(code_cache, install_to), path),
os.path.join(chroot.work_dir, path),
)
with atomic_directory(code_cache) as code_chroot:
if not code_chroot.is_finalized():
layout.extract_code(code_chroot.work_dir)
for path in os.listdir(code_cache):
os.symlink(
os.path.join(os.path.relpath(code_cache, install_to), path),
os.path.join(chroot.work_dir, path),
)

layout.extract_pex_info(chroot.work_dir)
layout.extract_main(chroot.work_dir)
Expand Down
7 changes: 2 additions & 5 deletions pex/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ def access_zipped_assets(cls, static_module_name, static_path, dir_location=None


class CacheHelper(object):
_EMPTY_CODE_HASH = hashlib.sha1().hexdigest()

@classmethod
def hash(cls, path, digest=None, hasher=sha1):
# type: (Text, Optional[Hasher], Callable[[], Hasher]) -> str
Expand All @@ -88,7 +86,7 @@ def pex_code_hash(
exclude_dirs=(), # type: Container[str]
exclude_files=(), # type: Container[str]
):
# type: (...) -> Optional[str]
# type: (...) -> str
"""Return a reproducible hash of the user code of a loose PEX; excluding all `.pyc` files.
If no code is found, `None` is returned.
Expand All @@ -106,8 +104,7 @@ def pex_code_hash(
)
),
)
code_hash = digest.hexdigest()
return None if code_hash == cls._EMPTY_CODE_HASH else code_hash
return digest.hexdigest()

@classmethod
def dir_hash(cls, directory, digest=None, hasher=sha1):
Expand Down

0 comments on commit 0ef0ff4

Please sign in to comment.