Skip to content

Conversation

@hugovk
Copy link
Member

@hugovk hugovk commented May 14, 2025

Existing behaviour, shows the version number of the repo:

python3 Tools/build/patchlevel.py
3.15.0a0python3 Tools/build/patchlevel.py --short
3.15

New:

Use argparse to add (colour) help:

python3 Tools/build/patchlevel.py --help
usage: patchlevel.py [-h] [--short | --hex] [version]

positional arguments:
  version               version to convert (default: repo version)

options:
  -h, --help            show this help message and exit
  --short               print version as x.y
  --hex                 print version as a 4-byte hex number

Pass an x.y version number on the command line:

python3 Tools/build/patchlevel.py 3.15
3.15.0python3 Tools/build/patchlevel.py 3.15 --short
3.15

Add --hex option to get the patch level as 4-byte hex number:

python3 Tools/build/patchlevel.py 3.15 --hex
0x30f00f0

Pass an x.y.z version:

python3 Tools/build/patchlevel.py 3.15.0
3.15.0python3 Tools/build/patchlevel.py 3.14.0
3.14.0python3 Tools/build/patchlevel.py 3.14.0 --short
3.14python3 Tools/build/patchlevel.py 3.14.0 --hex
0x30e00f0

Pass an x.y.z[release-level]serial version:

python3 Tools/build/patchlevel.py 3.13.0b1
3.13.0b1python3 Tools/build/patchlevel.py 3.13.0b1 --short
3.13python3 Tools/build/patchlevel.py 3.13.0b1 --hex
0x30d00b1

Pass a hex patch level:

python3 Tools/build/patchlevel.py 0x030502A1
3.5.2a1python3 Tools/build/patchlevel.py 0x030502A1 --short
3.5python3 Tools/build/patchlevel.py 0x030502A1 --hex
0x30502a1

Tested by temporarily adding these asserts:

assert get_version_hex(version_info(1, 5, 2, "alpha", 2)) == 0x010502A2
assert get_version_hex(version_info(3, 5, 2, "alpha", 1)) == 0x030502A1
assert get_version_hex(version_info(1, 5, 2, "beta", 2)) == 0x010502B2
assert get_version_hex(version_info(3, 9, 0, "final", 0)) == 0x030900F0
assert get_version_hex(version_info(3, 10, 0, "final", 0)) == 0x030A00F0
assert get_version_hex(version_info(3, 11, 0, "final", 0)) == 0x030B00F0
assert get_version_hex(version_info(3, 12, 0, "final", 0)) == 0x030C00F0
assert get_version_hex(version_info(3, 13, 0, "final", 0)) == 0x030D00F0
assert get_version_hex(version_info(3, 14, 0, "final", 0)) == 0x030E00F0

assert parse_str_version("3.8") == version_info(3, 8, 0, "final", 0)
assert parse_str_version("3.9.0") == version_info(3, 9, 0, "final", 0)
assert parse_str_version("3.10.1") == version_info(3, 10, 1, "final", 0)
assert parse_str_version("3.11.1a2") == version_info(3, 11, 1, "alpha", 2)
assert parse_str_version("3.12.13b3") == version_info(3, 12, 13, "beta", 3)
assert parse_str_version("3.13.3rc2") == version_info(3, 13, 3, "candidate", 2)

assert parse_hex_version(0x30A00A0) == version_info(3, 10, 0, "alpha", 0)

📚 Documentation preview 📚: https://cpython-previews--134000.org.readthedocs.build/

Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

I'd really prefer not to do this. The CLI interface of patchlevel.py is not a contract for end users, but required because we use it in the Makefile / make.bat to get the current version. Ideally, any observable inteface would be removed -- unlike Tools/ nothing in Doc/tools is intended for manual use (even check-warnings.py isn't really for manual use).

If the decimal <-> hexadecimal conversion is deemed useful, it should go elsewhere, perhaps in Tools/build or Misc. The alternative is just doing the conversion by hand.

A

@bedevere-app
Copy link

bedevere-app bot commented May 14, 2025

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

@hugovk
Copy link
Member Author

hugovk commented May 14, 2025

I have made the requested changes; please review again: moved to Tools/build/.

@bedevere-app
Copy link

bedevere-app bot commented May 14, 2025

Thanks for making the requested changes!

@AA-Turner: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from AA-Turner May 14, 2025 12:43
@hugovk hugovk closed this May 14, 2025
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.

2 participants