@@ -44,6 +44,44 @@ def call_fxn(*args, **kwargs):
4444 return decorated_fxn
4545
4646
47+ def get_patchlevel_version_info ():
48+ patchlevel_h = os .path .join (SRCDIR , 'Include' , 'patchlevel.h' )
49+
50+ try :
51+ with open (patchlevel_h , encoding = "utf-8" ) as f :
52+ patchlevel = f .read ()
53+ except FileNotFoundError :
54+ return sys .version_info [:4 ]
55+
56+ d = {}
57+ skip = True
58+ for line in patchlevel .splitlines ():
59+ if skip :
60+ if line == "/*--start constants--*/" :
61+ skip = False
62+ continue
63+
64+ for name in ("MAJOR_VERSION" , "MINOR_VERSION" , "MICRO_VERSION" ,
65+ "RELEASE_LEVEL" ):
66+ if line .startswith (define := f"#define PY_{ name } " ):
67+ d [name ] = line .removeprefix (define ).lstrip (" " )
68+ break
69+
70+ if len (d ) == 4 :
71+ break
72+
73+ major = int (d ['MAJOR_VERSION' ])
74+ minor = int (d ['MINOR_VERSION' ])
75+ micro = int (d ['MICRO_VERSION' ])
76+ level = {
77+ 'PY_RELEASE_LEVEL_ALPHA' : 'alpha' ,
78+ 'PY_RELEASE_LEVEL_BETA' : 'beta' ,
79+ 'PY_RELEASE_LEVEL_GAMMA' : 'rc' ,
80+ 'PY_RELEASE_LEVEL_FINAL' : 'final' ,
81+ }[d ['RELEASE_LEVEL' ]]
82+ return major , minor , micro , level
83+
84+
4785def get_git_branch ():
4886 """Get the symbolic name for the current git branch"""
4987 cmd = "git rev-parse --abbrev-ref HEAD" .split ()
@@ -102,11 +140,11 @@ def get_base_branch():
102140 # Not a git checkout, so there's no base branch
103141 return None
104142 upstream_remote = get_git_upstream_remote ()
105- version = sys . version_info
106- if version . releaselevel == 'alpha' :
143+ major , minor , micro , level = get_patchlevel_version_info ()
144+ if level == 'alpha' :
107145 base_branch = get_git_remote_default_branch (upstream_remote )
108146 else :
109- base_branch = "{0. major}.{0. minor}". format ( version )
147+ base_branch = f" { major } .{ minor } "
110148 this_branch = get_git_branch ()
111149 if this_branch is None or this_branch == base_branch :
112150 # Not on a git PR branch, so there's no base branch
@@ -320,6 +358,7 @@ def main():
320358 help = 'Perform pass/fail checks' )
321359 args = parser .parse_args ()
322360 if args .ci :
361+ SRCDIR = os .getcwd ()
323362 ci (args .ci )
324363 else :
325364 main ()
0 commit comments