Skip to content

Commit 713d0ed

Browse files
introduce --{,no-}cache-dists flag to gate use of the packed cache
1 parent 2131a26 commit 713d0ed

File tree

3 files changed

+181
-79
lines changed

3 files changed

+181
-79
lines changed

pex/bin/pex.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,23 @@ def configure_clp_pex_options(parser):
164164
),
165165
)
166166

167-
# TODO: avoid caching at all for --no-compress, since the cache entries are so large and the
168-
# performance improvement is so slim.
167+
group.add_argument(
168+
"--cache-dists",
169+
"--no-cache-dists",
170+
dest="cache_dists",
171+
default=None,
172+
action=HandleBoolAction,
173+
help=(
174+
"Whether to zip up each dist contained in the output PEX file into a fingerprinted "
175+
"cache directory to speed up later PEX file builds. For `--layout packed`, this "
176+
"behavior is enabled by default. "
177+
"For `--layout zipapp`, this synthesizes the zip file from those cached zips with an "
178+
"experimental zip merging technique, so this flag is disabled by default when building "
179+
"a zipapp. This will re-use the same caches as `--layout packed`, so creating a "
180+
"zipapp or packed PEX file from the same inputs will only populate the cache once. "
181+
"This flag and behavior do not apply to other layouts."
182+
),
183+
)
169184
group.add_argument(
170185
"--compress",
171186
"--compressed",
@@ -961,6 +976,7 @@ def do_main(
961976
deterministic_timestamp=not options.use_system_time,
962977
layout=options.layout,
963978
compress=options.compress,
979+
cache_dists=options.cache_dists,
964980
)
965981
if options.seed != Seed.NONE:
966982
seed_info = seed_cache(

pex/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def zip_entry_from_file(
219219
arcname += "/"
220220
if date_time is None:
221221
date_time = time.localtime(st.st_mtime)
222-
zinfo = zipfile.ZipInfo(filename=arcname, date_time=cast(_DateTime, date_time[:6]))
222+
zinfo = zipfile.ZipInfo(filename=arcname, date_time=cast("_DateTime", date_time[:6]))
223223
zinfo.external_attr = (st.st_mode & 0xFFFF) << 16 # Unix attributes
224224
if isdir:
225225
zinfo.file_size = 0
@@ -659,7 +659,7 @@ def delete(self):
659659
# https://github.com/pantsbuild/pex/issues/2158 and https://github.com/pantsbuild/pex/pull/2175.
660660
def zip(
661661
self,
662-
output_file, # type: Union[str, io.IOBase]
662+
output_file, # type: Union[str, io.IOBase, io.BufferedRandom]
663663
mode="w", # type: str
664664
deterministic_timestamp=False, # type: bool
665665
exclude_file=lambda _: False, # type: Callable[[str], bool]

0 commit comments

Comments
 (0)