-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-34022: Stop forcing of hash-based invalidation with SOURCE_DATE_EPOCH #9607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…POCH Unconditional forcing of ``CHECKED_HASH`` invalidation was introduced in 3.7.0 in bpo-29708. The change is bad, as it unconditionally overrides *invalidation_mode*, even if it was passed as an explicit argument to ``py_compile.compile()`` or ``compileall``. An environment variable should *never* override an explicit argument to a library function. That change leads to multiple test failures if the ``SOURCE_DATE_EPOCH`` environment variable is set. This changes ``py_compile.compile()`` to only look at ``SOURCE_DATE_EPOCH`` if no explicit *invalidation_mode* was specified. I also made various relevant tests run with explicit control over the value of ``SOURCE_DATE_EPOCH``. While looking at this, I noticed that ``zipimport`` does not work with hash-based .pycs _at all_, though I left the fixes for subsequent commits.
Doc/library/py_compile.rst
Outdated
.. versionchanged:: 3.7.2 | ||
The :envvar:`SOURCE_DATE_EPOCH` environment variable no longer | ||
overrides the value of the *invalidation_mode* argument, and determines | ||
it's default value instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I have a few minor comments.
I will not approve this PR since it's the work of @benjaminp and I'm not sure that the change respects his design (PEP 552) (I'm not sure that he agrees with the change).
bytecode cache files at runtime. | ||
The default is ``timestamp`` if the :envvar:`SOURCE_DATE_EPOCH` environment | ||
variable is not set, and ``checked-hash`` if the ``SOURCE_DATE_EPOCH`` | ||
environment variable is set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"is set": I suggest "is set to a non-empty string". See other existing examples:
https://docs.python.org/dev/using/cmdline.html#envvar-PYTHONOPTIMIZE
Maybe add a reference to the PEP 552 somewhere (you can use syntax :pep:552
).
By the way, should we mention SOURCE_DATE_EPOCH somewhere in https://docs.python.org/dev/using/cmdline.html ? The variable is not specific to Python, but it changes its behavior.
enum and controls how the generated bytecode cache is invalidated at | ||
runtime. The default is :attr:`PycInvalidationMode.CHECKED_HASH` if | ||
the :envvar:`SOURCE_DATE_EPOCH` environment variable is set, otherwise | ||
the default is :attr:`PycInvalidationMode.TIMESTAMP`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a reference to the PEP 552 somewhere (you can use syntax :pep:552
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP 552 actually has no mention of SOURCE_DATE_EPOCH
, so I'm not sure such a reference would be useful here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invalidation_mode is a new thing coming from the PEP 552. Moreover, I proposed to update the PEP:
https://bugs.python.org/issue34022#msg326638
@functools.wraps(fxn) | ||
def wrapper(*args, **kwargs): | ||
with support.EnvironmentVarGuard() as env: | ||
env.unset('SOURCE_DATE_EPOCH') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there at least one unit test for SOURCE_DATE_EPOCH set to an empty string?
Benjamin's comment on the issue:
Reverting seems like a drastic measure, I think this PR achieves a better balance. |
cc @bmwiedemann who authored PR #5200. |
I really like this PR as it is what I should have written, if I was a python guru. We do need some way to get reproducible .pyc files across all of openSUSE's ~1800 python packages without having to touch each of them individually to add an invalidation_mode. |
Hum, a few tests still fail with SOURCE_DATE_EPOCH=0:
@elprans: Do you want to fix these tests in the same PR, or do you prefer to fix them in a different PR? |
@vstinner Separate PR. Those are unrelated to |
@ned-deily, @benjaminp, @elprans: I guess that this change can wait Python 3.7.2, it's not a blocker issue nor a major bug. So I suggest to wait until 3.7.1 final is released before backporting this change to the 3.7 branch. |
Unless a release manager says otherwise, please don't wait between RC's and finals to merge PRs. It's better to get them exposed on buildbots. We'll cherry-picked fixes as necessary into the finals. |
The merged change is a backward incompatible and it mentions the version 3.7.2 in the modified documentation :-) |
The docs can be easily changed for the final. The question is how much of an impact is it for 3.7.1 users by not having this change in vs having it in.. |
Some SOURCE_DATE_EPOCH-related tests are fixed in python/cpython#9607
@mcepl I'm working on a followup PR to fix these. |
@elprans thanks |
GH-10775 is a backport of this pull request to the 3.7 branch. |
…POCH (pythonGH-9607) Unconditional forcing of ``CHECKED_HASH`` invalidation was introduced in 3.7.0 in bpo-29708. The change is bad, as it unconditionally overrides *invalidation_mode*, even if it was passed as an explicit argument to ``py_compile.compile()`` or ``compileall``. An environment variable should *never* override an explicit argument to a library function. That change leads to multiple test failures if the ``SOURCE_DATE_EPOCH`` environment variable is set. This changes ``py_compile.compile()`` to only look at ``SOURCE_DATE_EPOCH`` if no explicit *invalidation_mode* was specified. I also made various relevant tests run with explicit control over the value of ``SOURCE_DATE_EPOCH``. While looking at this, I noticed that ``zipimport`` does not work with hash-based .pycs _at all_, though I left the fixes for subsequent commits. (cherry picked from commit a6b3ec5) Co-authored-by: Elvis Pranskevichus <[email protected]>
…POCH (GH-9607) Unconditional forcing of ``CHECKED_HASH`` invalidation was introduced in 3.7.0 in bpo-29708. The change is bad, as it unconditionally overrides *invalidation_mode*, even if it was passed as an explicit argument to ``py_compile.compile()`` or ``compileall``. An environment variable should *never* override an explicit argument to a library function. That change leads to multiple test failures if the ``SOURCE_DATE_EPOCH`` environment variable is set. This changes ``py_compile.compile()`` to only look at ``SOURCE_DATE_EPOCH`` if no explicit *invalidation_mode* was specified. I also made various relevant tests run with explicit control over the value of ``SOURCE_DATE_EPOCH``. While looking at this, I noticed that ``zipimport`` does not work with hash-based .pycs _at all_, though I left the fixes for subsequent commits. (cherry picked from commit a6b3ec5) Co-authored-by: Elvis Pranskevichus <[email protected]>
Unconditional forcing of
CHECKED_HASH
invalidation was introduced in3.7.0 in bpo-29708. The change is bad, as it unconditionally overrides
invalidation_mode, even if it was passed as an explicit argument to
py_compile.compile()
orcompileall
. An environment variableshould never override an explicit argument to a library function.
That change leads to multiple test failures if the
SOURCE_DATE_EPOCH
environment variable is set.
This changes
py_compile.compile()
to only look atSOURCE_DATE_EPOCH
if no explicit invalidation_mode was specified.I also made various relevant tests run with explicit control over the
value of
SOURCE_DATE_EPOCH
.While looking at this, I noticed that
zipimport
does not workwith hash-based .pycs at all, though I left the fixes for
subsequent commits.
https://bugs.python.org/issue34022