From 96f710ade7a95db7f650a6041ba8f957b4dcbc5c Mon Sep 17 00:00:00 2001 From: John Sirois Date: Sun, 3 Nov 2024 14:03:37 -0800 Subject: [PATCH] Continue to populate empty code caches for back compat. --- pex/layout.py | 23 ++++++++++++----------- pex/util.py | 5 ++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pex/layout.py b/pex/layout.py index 514e0e205..30724e73b 100644 --- a/pex/layout.py +++ b/pex/layout.py @@ -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() @@ -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) diff --git a/pex/util.py b/pex/util.py index 94d51ea9f..2362680bd 100644 --- a/pex/util.py +++ b/pex/util.py @@ -88,7 +88,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. @@ -106,8 +106,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):