Skip to content

Commit

Permalink
introduce --{,no-}cache-dists flag to gate use of the packed cache
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Aug 5, 2023
1 parent 2131a26 commit 31592ec
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 79 deletions.
20 changes: 18 additions & 2 deletions pex/bin/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,23 @@ def configure_clp_pex_options(parser):
),
)

# TODO: avoid caching at all for --no-compress, since the cache entries are so large and the
# performance improvement is so slim.
group.add_argument(
"--cache-dists",
"--no-cache-dists",
dest="cache_dists",
default=None,
action=HandleBoolAction,
help=(
"Whether to zip up each dist contained in the output PEX file into a fingerprinted "
"cache directory to speed up later PEX file builds. For `--layout packed`, this "
"behavior is enabled by default. "
"For `--layout zipapp`, this synthesizes the zip file from those cached zips with an "
"experimental zip merging technique, so this flag is disabled by default when building "
"a zipapp. This will re-use the same caches as `--layout packed`, so creating a "
"zipapp or packed PEX file from the same inputs will only populate the cache once. "
"This flag and behavior do not apply to other layouts."
),
)
group.add_argument(
"--compress",
"--compressed",
Expand Down Expand Up @@ -961,6 +976,7 @@ def do_main(
deterministic_timestamp=not options.use_system_time,
layout=options.layout,
compress=options.compress,
cache_dists=options.cache_dists,
)
if options.seed != Seed.NONE:
seed_info = seed_cache(
Expand Down
4 changes: 2 additions & 2 deletions pex/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def zip_entry_from_file(
arcname += "/"
if date_time is None:
date_time = time.localtime(st.st_mtime)
zinfo = zipfile.ZipInfo(filename=arcname, date_time=cast(_DateTime, date_time[:6]))
zinfo = zipfile.ZipInfo(filename=arcname, date_time=cast("_DateTime", date_time[:6]))
zinfo.external_attr = (st.st_mode & 0xFFFF) << 16 # Unix attributes
if isdir:
zinfo.file_size = 0
Expand Down Expand Up @@ -659,7 +659,7 @@ def delete(self):
# https://github.com/pantsbuild/pex/issues/2158 and https://github.com/pantsbuild/pex/pull/2175.
def zip(
self,
output_file, # type: Union[str, io.IOBase]
output_file, # type: Union[str, io.IOBase, io.BufferedRandom]
mode="w", # type: str
deterministic_timestamp=False, # type: bool
exclude_file=lambda _: False, # type: Callable[[str], bool]
Expand Down
Loading

0 comments on commit 31592ec

Please sign in to comment.