29
29
30
30
def get_version (version_file : str = STATIC_VERSION_FILE ) -> str :
31
31
version_info = get_static_version_info (version_file )
32
- version = version_info ["version" ]
33
- if version == "__use_git__" :
32
+ if version_info ["version" ] == "__use_git__" :
34
33
version = get_version_from_git ()
35
34
if not version :
36
35
version = get_version_from_git_archive (version_info )
37
36
if not version :
38
37
version = Version ("unknown" , None , None )
39
38
return pep440_format (version )
40
39
else :
41
- return version
40
+ return version_info [ " version" ]
42
41
43
42
44
43
def get_static_version_info (version_file : str = STATIC_VERSION_FILE ) -> Dict [str , str ]:
45
- version_info = {}
44
+ version_info : Dict [ str , str ] = {}
46
45
with open (os .path .join (package_root , version_file ), "rb" ) as f :
47
46
exec (f .read (), {}, version_info )
48
47
return version_info
@@ -78,32 +77,32 @@ def get_version_from_git() -> Version:
78
77
stderr = subprocess .PIPE ,
79
78
)
80
79
except OSError :
81
- return
80
+ return None
82
81
if p .wait () != 0 :
83
- return
82
+ return None
84
83
if not os .path .samefile (p .communicate ()[0 ].decode ().rstrip ("\n " ), distr_root ):
85
84
# The top-level directory of the current Git repository is not the same
86
85
# as the root directory of the distribution: do not extract the
87
86
# version from Git.
88
- return
87
+ return None
89
88
90
89
# git describe --first-parent does not take into account tags from branches
91
90
# that were merged-in. The '--long' flag gets us the 'dev' version and
92
91
# git hash, '--always' returns the git hash even if there are no tags.
93
92
for opts in [["--first-parent" ], []]:
94
93
try :
95
94
p = subprocess .Popen (
96
- ["git" , "describe" , "--long" , "--always" ] + opts ,
95
+ ["git" , "describe" , "--long" , "--always" ] + opts , # type: ignore
97
96
cwd = distr_root ,
98
97
stdout = subprocess .PIPE ,
99
98
stderr = subprocess .PIPE ,
100
99
)
101
100
except OSError :
102
- return
101
+ return None
103
102
if p .wait () == 0 :
104
103
break
105
104
else :
106
- return
105
+ return None
107
106
108
107
description = (
109
108
p .communicate ()[0 ]
@@ -143,7 +142,7 @@ def get_version_from_git() -> Version:
143
142
# Currently we can only tell the tag the current commit is
144
143
# pointing to, or its hash (with no version info)
145
144
# if it is not tagged.
146
- def get_version_from_git_archive (version_info ):
145
+ def get_version_from_git_archive (version_info ) -> Version :
147
146
try :
148
147
refnames = version_info ["refnames" ]
149
148
git_hash = version_info ["git_hash" ]
@@ -166,7 +165,7 @@ def get_version_from_git_archive(version_info):
166
165
return Version ("unknown" , dev = None , labels = [f"g{ git_hash } " ])
167
166
168
167
169
- __version__ = get_version ()
168
+ __version__ : str = get_version ()
170
169
171
170
172
171
# The following section defines a module global 'cmdclass',
0 commit comments