@@ -44,6 +44,44 @@ def call_fxn(*args, **kwargs):
44
44
return decorated_fxn
45
45
46
46
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
+
47
85
def get_git_branch ():
48
86
"""Get the symbolic name for the current git branch"""
49
87
cmd = "git rev-parse --abbrev-ref HEAD" .split ()
@@ -102,11 +140,11 @@ def get_base_branch():
102
140
# Not a git checkout, so there's no base branch
103
141
return None
104
142
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' :
107
145
base_branch = get_git_remote_default_branch (upstream_remote )
108
146
else :
109
- base_branch = "{0. major}.{0. minor}". format ( version )
147
+ base_branch = f" { major } .{ minor } "
110
148
this_branch = get_git_branch ()
111
149
if this_branch is None or this_branch == base_branch :
112
150
# Not on a git PR branch, so there's no base branch
@@ -320,6 +358,7 @@ def main():
320
358
help = 'Perform pass/fail checks' )
321
359
args = parser .parse_args ()
322
360
if args .ci :
361
+ SRCDIR = os .getcwd ()
323
362
ci (args .ci )
324
363
else :
325
364
main ()
0 commit comments