Do not force recompile pyc files (#2642)

Helps with #2637
This commit is contained in:
Shantanu 2024-03-24 17:02:53 -07:00 committed by GitHub
parent a7b251f65e
commit a6602ad416
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 1 deletions

View File

@ -36,6 +36,20 @@ with warnings.catch_warnings():
file=sys.stderr,
)
sys.exit(1)
if invalidation_mode is None:
try:
invalidation_mode = py_compile._get_default_invalidation_mode()
except AttributeError:
invalidation_mode = None # guard against implementation details
# Unlike pip, we will usually set force=False. It's unclear why pip sets force=True, but it
# doesn't matter much for them, as pip only compiles newly installed files.
force = False
if invalidation_mode != py_compile.PycInvalidationMode.TIMESTAMP:
# Note that compileall has undesirable, arguably buggy behaviour. Even if invalidation_mode
# is hash based, compileall will not recompile the file if the existing pyc is timestamp
# based and has a matching mtime (unless force=True).
force = True
# In rust, we provide one line per file to compile.
for path in sys.stdin:
@ -47,7 +61,7 @@ with warnings.catch_warnings():
# We'd like to show those errors, but given that pip thinks that's totally fine,
# we can't really change that.
success = compileall.compile_file(
path, invalidation_mode=invalidation_mode, force=True, quiet=2
path, invalidation_mode=invalidation_mode, force=force, quiet=2
)
# We're ready for the next file.
print(path)