@@ -375,6 +375,49 @@ def check_cpython_repo_is_clean(db: ReleaseShelf) -> None:
375
375
raise ReleaseException ("Git repository is not clean" )
376
376
377
377
378
+ def check_magic_number (db : ReleaseShelf ) -> None :
379
+ release_tag = db ["release" ]
380
+ if release_tag .is_final or release_tag .is_release_candidate :
381
+
382
+ def out (msg : str ) -> None :
383
+ raise ReleaseException (msg )
384
+
385
+ else :
386
+
387
+ def out (msg : str ) -> None :
388
+ print ("warning:" , msg , file = sys .stderr , flush = True )
389
+
390
+ def get_magic (source : Path , regex : re .Pattern [str ]) -> str :
391
+ if m := regex .search (source .read_text ()):
392
+ return m .group ("magic" )
393
+
394
+ out (f"Cannot find magic in { source } , tried { regex .pattern } " )
395
+ return "unknown"
396
+
397
+ work_dir = Path (db ["git_repo" ])
398
+ magic_actual_file = work_dir / "Include" / "internal" / "pycore_magic_number.h"
399
+ magic_actual_re = re .compile (
400
+ r"^#define\s+PYC_MAGIC_NUMBER\s+(?P<magic>\d+)$" , re .MULTILINE
401
+ )
402
+ magic_actual = get_magic (magic_actual_file , magic_actual_re )
403
+
404
+ magic_expected_file = work_dir / "Lib" / "test" / "test_importlib" / "test_util.py"
405
+ magic_expected_re = re .compile (
406
+ r"^\s+EXPECTED_MAGIC_NUMBER = (?P<magic>\d+)$" , re .MULTILINE
407
+ )
408
+ magic_expected = get_magic (magic_expected_file , magic_expected_re )
409
+
410
+ if magic_actual == magic_expected :
411
+ return
412
+
413
+ out (
414
+ f"Magic numbers in { magic_actual_file } ({ magic_actual } )"
415
+ f" and { magic_expected_file } ({ magic_expected } ) don't match."
416
+ )
417
+ if not ask_question ("Do you want to continue? This will fail tests in RC stage." ):
418
+ raise ReleaseException ("Magic numbers don't match!" )
419
+
420
+
378
421
def prepare_temporary_branch (db : ReleaseShelf ) -> None :
379
422
subprocess .check_call (
380
423
["git" , "checkout" , "-b" , f"branch-{ db ['release' ]} " ], cwd = db ["git_repo" ]
@@ -1179,6 +1222,7 @@ def _api_key(api_key: str) -> str:
1179
1222
),
1180
1223
Task (check_buildbots , "Check buildbots are good" ),
1181
1224
Task (check_cpython_repo_is_clean , "Checking Git repository is clean" ),
1225
+ Task (check_magic_number , "Checking the magic number is up-to-date" ),
1182
1226
Task (prepare_temporary_branch , "Checking out a temporary release branch" ),
1183
1227
Task (run_blurb_release , "Run blurb release" ),
1184
1228
Task (check_cpython_repo_is_clean , "Checking Git repository is clean" ),
0 commit comments