Skip to content

gh-122188: Move magic number to its own file #122243

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 18 commits into from
Jul 30, 2024
Merged

Conversation

mdboom
Copy link
Contributor

@mdboom mdboom commented Jul 24, 2024

can be named after the Python major version of the magic number bump, but
it can really be anything, as long as it's different than anything else
that's come before. The tags are included in the following table, starting
with Python 3.2a0.
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 just moved this comment here from the other file, but I did notice this last sentence seems to be no longer true. There are two 3.2 magic tags mentioned below but that's it. I think it's just entirely based on version number now. Does it make sense to remove this paragraph?

@mdboom mdboom requested review from a team and kumaraditya303 as code owners July 25, 2024 16:46
value = PyLong_FromLong(PYC_MAGIC_NUMBER);
if (value == NULL)
goto error;
res = PyDict_SetItemString(impl_info, "pyc_magic_number", value);
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if sys.implementation is the best place for this? https://docs.python.org/3/library/sys.html#sys.implementation has all attributes being required for all implementations and bytecode is not necessary to implement Python. Should it just be a private attribute in sys instead?

Copy link
Member

Choose a reason for hiding this comment

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

According to those docs, this can't be added as sys.implementation.pyc_magic_number without a PEP. sys.implementation._pyc_magic_number (left undocumented) would be fine, though.

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've made this private.

@mdboom mdboom added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 26, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @mdboom for commit 2cc27f0 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 26, 2024
@mdboom mdboom added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 26, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @mdboom for commit 4fd9ea6 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 26, 2024
@mdboom mdboom force-pushed the move-magic-number branch from 4fd9ea6 to f7d8a42 Compare July 26, 2024 13:48
@mdboom mdboom added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 26, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @mdboom for commit ef89747 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 26, 2024
@bedevere-app
Copy link

bedevere-app bot commented Jul 29, 2024

Thanks for making the requested changes!

@ericsnowcurrently: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from ericsnowcurrently July 29, 2024 17:47
Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

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

Thanks for moving that.

There's one small thing left to do.

@bedevere-app
Copy link

bedevere-app bot commented Jul 29, 2024

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@mdboom mdboom added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 30, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @mdboom for commit 398988d 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 30, 2024
@mdboom
Copy link
Contributor Author

mdboom commented Jul 30, 2024

I have made the requested changes; please review again

Note, I've added a test to make sure that the new C-side calculation of _pyc_magic_number_token matches the old _RAW_MAGIC_NUMBER, and run it over the buildbots to make sure it gets some testing on big-endian machines (since endianness matters here).

@bedevere-app
Copy link

bedevere-app bot commented Jul 30, 2024

Thanks for making the requested changes!

@ericsnowcurrently: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from ericsnowcurrently July 30, 2024 14:33
Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

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

LGTM

I've left a small number of minor suggestions related to formatting and tests. I'm approving the PR assuming you will address those (one way or another).

@mdboom mdboom merged commit af0a00f into python:main Jul 30, 2024
35 checks passed
MAGIC_NUMBER = (3603).to_bytes(2, 'little') + b'\r\n'

_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
MAGIC_NUMBER = (_imp.pyc_magic_number).to_bytes(2, 'little') + b'\r\n'
Copy link
Member

Choose a reason for hiding this comment

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

It can be defined as:

MAGIC_NUMBER = _imp.pyc_magic_number_token.to_bytes(4, 'little')

And _imp.pyc_magic_number will no longer be used, it can be removed. See #122503.

blhsing pushed a commit to blhsing/cpython that referenced this pull request Aug 22, 2024
* pythongh-122188: Move magic number to its own file

* Add versionadded directive

* Do work in C

* Integrate launcher.c

* Make _pyc_magic_number private

* Remove metadata

* Move sys.implementation -> _imp

* Modernize comment

* Move _RAW_MAGIC_NUMBER to the C side as well

* _pyc_magic_number -> pyc_magic_number

* Remove unused import

* Update docs

* Apply suggestions from code review

Co-authored-by: Eric Snow <[email protected]>

* Fix typo in tests

---------

Co-authored-by: Eric Snow <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants