Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 2 commits into from
Oct 10, 2018

Conversation

elprans
Copy link
Contributor

@elprans elprans commented Sep 27, 2018

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.

https://bugs.python.org/issue34022

…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.
.. 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its

@vstinner vstinner requested a review from benjaminp September 28, 2018 00:15
Copy link
Member

@vstinner vstinner left a 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.
Copy link
Member

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`.
Copy link
Member

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).

Copy link
Contributor Author

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.

Copy link
Member

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')
Copy link
Member

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?

@elprans
Copy link
Contributor Author

elprans commented Sep 28, 2018

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).

Benjamin's comment on the issue:

I dislike that having SOURCE_DATE_EPOCH set magically changes command line tools behavior. In my view, this problem should be fixed by reverting ccbe581.

Reverting seems like a drastic measure, I think this PR achieves a better balance.

@vstinner
Copy link
Member

cc @bmwiedemann who authored PR #5200.

@bmwiedemann
Copy link
Contributor

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.
If there is some other preferable approach to achieve that, I'd love to hear about that.

@vstinner
Copy link
Member

Hum, a few tests still fail with SOURCE_DATE_EPOCH=0:

  • test_multiprocessing_main_handling
  • test_cmd_line_script
  • test_runpy

@elprans: Do you want to fix these tests in the same PR, or do you prefer to fix them in a different PR?

@elprans
Copy link
Contributor Author

elprans commented Oct 10, 2018

@vstinner Separate PR. Those are unrelated to py_compile and are due to broken zipimport.

@vstinner vstinner merged commit a6b3ec5 into python:master Oct 10, 2018
@vstinner
Copy link
Member

@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.

@vstinner
Copy link
Member

@vstinner Separate PR. Those are unrelated to py_compile and are due to broken zipimport.

Perfect. In this case, I see no other reason to no merge your PR :-) I merged it, good job! Thanks @elprans.

@ned-deily
Copy link
Member

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.

@vstinner
Copy link
Member

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 :-)

@ned-deily
Copy link
Member

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..

yan12125 added a commit to archlinuxcn/repo that referenced this pull request Oct 11, 2018
Some SOURCE_DATE_EPOCH-related tests are fixed in
python/cpython#9607
@mcepl
Copy link
Contributor

mcepl commented Oct 15, 2018

@elprans @vstinner Separate PR. Those are unrelated to py_compile and are due to broken zipimport.

Is there such PR somewhere? Or at least a bug?

@elprans
Copy link
Contributor Author

elprans commented Oct 16, 2018

@mcepl I'm working on a followup PR to fix these.

@mcepl
Copy link
Contributor

mcepl commented Oct 16, 2018

@elprans thanks

@miss-islington
Copy link
Contributor

Thanks @elprans for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-10775 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 28, 2018
…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]>
miss-islington added a commit that referenced this pull request Nov 28, 2018
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants