Skip to content
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

bpo-29514: Check magic number for bugfix release #54

Merged
merged 3 commits into from
Apr 17, 2017

Conversation

appeltel
Copy link
Contributor

@appeltel appeltel commented Feb 12, 2017

Add a test to check the current MAGIC_NUMBER against the
expected number for the release if the current release is
at candidate or final level. On test failure, describe to
the developer the procedure for changing the magic number.

https://bugs.python.org/issue29514

Add a dict importlib.util.EXPECTED_MAGIC_NUMBERS which
details the initial and expected pyc magic number for
each minor release. This gives a mechanism for users to
check if the magic number has changed within a release and
for a test to ensure procedure is followed if a change is
necessary.

Add a test to check the current MAGIC_NUMBER against the
expected number for the release if the current release is
at candidate or final level. On test failure, describe to
the developer the procedure for changing the magic number.
Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

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

The general approach in the test case looks like it will give affected maintainers useful guidance, but the impact can be reduced by moving the EXPECTED_MAGIC_NUMBERS table into the test case itself (the test case will complain when it needs updating, so it's OK to have it separated from the list of actual magic numbers in the importlib code)

(2, 7): 62211,
(3, 5): 3350,
(3, 6): 3379
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd put this table in the test suite rather than in the code - there's no need to have it other than the bytecode stability test case, and if it hasn't been updated when it needs to be we'll get a test failure anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplifed to a sigle entry in the test case in 9ea7c52

@@ -4,6 +4,7 @@
from ._bootstrap import _resolve_name
from ._bootstrap import spec_from_loader
from ._bootstrap import _find_spec
from ._bootstrap_external import EXPECTED_MAGIC_NUMBERS
Copy link
Contributor

Choose a reason for hiding this comment

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

With the table moved to the test suite, this won't be needed any more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed in 9ea7c52


In exceptional cases, it may be required to change the MAGIC_NUMBER
for a maintenance release. In this case the change should be
discussed in dev-python. If a change is required, community
Copy link
Contributor

Choose a reason for hiding this comment

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

dev-python -> python-dev

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 9ea7c52


EXPECTED_MAGIC_NUMBERS = {
(2, 7): 62211,
(3, 5): 3350,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean we're reverting the magic number bump from 3.5.3?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, but the current special case from the test should just be moved directly into the table of expected magic numbers with a suitable comment.

Simplify the magic number release test by removing
EXPECTED_MAGIC_NUMBERS table and making the expected
magic number self-contained within the test.

BPO: 29514
Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

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

This is looking pretty close now, just a couple of suggestions around details of the test execution.

@@ -757,5 +757,49 @@ def test_source_from_cache_path_like_arg(self):
) = util.test_both(PEP3147Tests, util=importlib_util)


class MagicNumberTests:
Copy link
Contributor

Choose a reason for hiding this comment

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

Inherit from unittest.TestCase here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially avoided this and followed the test machinery as I wasn't sure about directly importing importlib.util within this test module, but after looking at the way the test specialization works I don't see how this is an issue. Changed in 1e32a1b.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this module does some interesting things to create "real" test classes in different configurations, but we don't need those kinds of tricks for the new test.

adjustment to this test case.
"""
if sys.version_info.releaselevel not in ('final', 'candidate'):
return
Copy link
Contributor

Choose a reason for hiding this comment

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

This can change to a unittest.skipUnless decorator on the testmethod:

@unittest.skipUnless(sys.version_info.release in ('final', 'release'), 'Only check magic number stability for release candidates and later')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 1e32a1b

actual = int.from_bytes(self.util.MAGIC_NUMBER[:2], 'little')

msg = (
"Candidate and final releases require the current "
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd start this message with "To avoid breaking backwards compatibility with cached bytecode files that can't be automatically regenerated by the current user, ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 1e32a1b

Improve the execution of the magic number test by
using skipUnless for alpha and beta releases, and
directly inheriting from unittest.TestCase rather than
using the machinery for the other tests. Also improve
the error message to explain the reason for caution in
changing the magic number.

BPO: 29514
@codecov
Copy link

codecov bot commented Mar 12, 2017

Codecov Report

Merging #54 into master will decrease coverage by <.01%.
The diff coverage is 50%.

@@            Coverage Diff             @@
##           master      #54      +/-   ##
==========================================
- Coverage   82.37%   82.37%   -0.01%     
==========================================
  Files        1427     1428       +1     
  Lines      350948   350968      +20     
==========================================
+ Hits       289093   289102       +9     
- Misses      61855    61866      +11

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c22bfaa...1e32a1b. Read the comment docs.

actual = int.from_bytes(importlib.util.MAGIC_NUMBER[:2], 'little')

msg = (
"To avoid breaking backwards compatibility with cached bytecode "
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't be better to use a multiline string literal if you want such verbose error message?

But I think that "broken *.pyc files compatibility" would be enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then you'd have to dedent it, etc. This message is perfectly legible to me.

)
def test_magic_number(self):
"""
Each python minor release should generally have a MAGIC_NUMBER
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to write this as a comment rather than a docstring. If you want, add a one-line docstring, but most test methods don't have docstrings.

@ambv ambv merged commit d6d344d into python:master Apr 17, 2017
@miss-islington
Copy link
Contributor

🐍🍒⛏🤖 Thanks @appeltel for the PR, and @ambv for merging it 🌮🎉.I'm working now to backport this PR to: 2.7, 3.6.

@miss-islington
Copy link
Contributor

Sorry @appeltel and @ambv, I had trouble checking out the 3.6 backport branch.
Please backport using cherry_picker on command line.

@miss-islington
Copy link
Contributor

Sorry, @appeltel and @ambv, I could not cleanly backport this to 2.7 due to a conflict.
Please backport using cherry_picker on command line.

@ncoghlan
Copy link
Contributor

ncoghlan commented Sep 7, 2017

This was backported a while back, but I missed updating the labels:

2.7:#2160
3.5: #2158
3.6: #2157

lazka added a commit to lazka/cpython that referenced this pull request Nov 10, 2021
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
lazka added a commit to lazka/cpython that referenced this pull request Nov 21, 2021
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jan 23, 2022
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request May 27, 2022
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
lazka added a commit to lazka/cpython that referenced this pull request Jun 6, 2022
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
lazka added a commit to lazka/cpython that referenced this pull request Jun 24, 2022
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
lazka added a commit to lazka/cpython that referenced this pull request Sep 22, 2022
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Dec 8, 2022
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
lazka added a commit to lazka/cpython that referenced this pull request Mar 2, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
mgmacias95 pushed a commit to mgmacias95/cpython that referenced this pull request Mar 27, 2023
lazka added a commit to lazka/cpython that referenced this pull request Apr 7, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
lazka added a commit to lazka/cpython that referenced this pull request Apr 16, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 18, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 20, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 23, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 23, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 23, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 23, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 23, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 23, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 23, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 23, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 24, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
naveen521kk pushed a commit to naveen521kk/cpython that referenced this pull request Jun 25, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
oraluben pushed a commit to oraluben/cpython that referenced this pull request Jul 12, 2023
lazka added a commit to lazka/cpython that referenced this pull request Jul 28, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
lazka added a commit to lazka/cpython that referenced this pull request Aug 27, 2023
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
lazka added a commit to lazka/cpython that referenced this pull request Feb 10, 2024
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
lazka added a commit to lazka/cpython that referenced this pull request Aug 25, 2024
The versions checked here are 20 years old. Also dllwrap
has started to emit a deprecation warning in the latest release
spamming the build logs.

Fixes python#54
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.

7 participants