1
- # SPDX-FileCopyrightText: 2023 - 2024 Intel Corporation
2
- #
3
- # SPDX-License-Identifier: Apache-2.0
4
1
5
2
# This file helps to compute a version number in source trees obtained from
6
3
# git-archive tarball (such as those provided by githubs download-from-tag
9
6
# that just contains the computed version number.
10
7
11
8
# This file is released into the public domain.
12
- # Generated by versioneer-0.28
9
+ # Generated by versioneer-0.29
13
10
# https://github.com/python-versioneer/python-versioneer
14
11
15
12
"""Git implementation of _version.py."""
19
16
import re
20
17
import subprocess
21
18
import sys
22
- from typing import Callable , Dict
19
+ from typing import Any , Callable , Dict , List , Optional , Tuple
23
20
import functools
24
21
25
22
26
- def get_keywords ():
23
+ def get_keywords () -> Dict [ str , str ] :
27
24
"""Get the keywords needed to look up the version information."""
28
25
# these strings will be replaced by git during git-archive.
29
26
# setup.py/versioneer.py will grep for the variable names, so they must
@@ -39,8 +36,15 @@ def get_keywords():
39
36
class VersioneerConfig :
40
37
"""Container for Versioneer configuration parameters."""
41
38
39
+ VCS : str
40
+ style : str
41
+ tag_prefix : str
42
+ parentdir_prefix : str
43
+ versionfile_source : str
44
+ verbose : bool
42
45
43
- def get_config ():
46
+
47
+ def get_config () -> VersioneerConfig :
44
48
"""Create, populate and return the VersioneerConfig() object."""
45
49
# these strings are filled in when 'setup.py versioneer' creates
46
50
# _version.py
@@ -62,9 +66,9 @@ class NotThisMethod(Exception):
62
66
HANDLERS : Dict [str , Dict [str , Callable ]] = {}
63
67
64
68
65
- def register_vcs_handler (vcs , method ) : # decorator
69
+ def register_vcs_handler (vcs : str , method : str ) -> Callable : # decorator
66
70
"""Create decorator to mark a method as the handler of a VCS."""
67
- def decorate (f ) :
71
+ def decorate (f : Callable ) -> Callable :
68
72
"""Store f in HANDLERS[vcs][method]."""
69
73
if vcs not in HANDLERS :
70
74
HANDLERS [vcs ] = {}
@@ -73,13 +77,19 @@ def decorate(f):
73
77
return decorate
74
78
75
79
76
- def run_command (commands , args , cwd = None , verbose = False , hide_stderr = False ,
77
- env = None ):
80
+ def run_command (
81
+ commands : List [str ],
82
+ args : List [str ],
83
+ cwd : Optional [str ] = None ,
84
+ verbose : bool = False ,
85
+ hide_stderr : bool = False ,
86
+ env : Optional [Dict [str , str ]] = None ,
87
+ ) -> Tuple [Optional [str ], Optional [int ]]:
78
88
"""Call the given command(s)."""
79
89
assert isinstance (commands , list )
80
90
process = None
81
91
82
- popen_kwargs = {}
92
+ popen_kwargs : Dict [ str , Any ] = {}
83
93
if sys .platform == "win32" :
84
94
# This hides the console window if pythonw.exe is used
85
95
startupinfo = subprocess .STARTUPINFO ()
@@ -95,8 +105,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
95
105
stderr = (subprocess .PIPE if hide_stderr
96
106
else None ), ** popen_kwargs )
97
107
break
98
- except OSError :
99
- e = sys .exc_info ()[1 ]
108
+ except OSError as e :
100
109
if e .errno == errno .ENOENT :
101
110
continue
102
111
if verbose :
@@ -116,7 +125,11 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
116
125
return stdout , process .returncode
117
126
118
127
119
- def versions_from_parentdir (parentdir_prefix , root , verbose ):
128
+ def versions_from_parentdir (
129
+ parentdir_prefix : str ,
130
+ root : str ,
131
+ verbose : bool ,
132
+ ) -> Dict [str , Any ]:
120
133
"""Try to determine the version from the parent directory name.
121
134
122
135
Source tarballs conventionally unpack into a directory that includes both
@@ -141,13 +154,13 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
141
154
142
155
143
156
@register_vcs_handler ("git" , "get_keywords" )
144
- def git_get_keywords (versionfile_abs ) :
157
+ def git_get_keywords (versionfile_abs : str ) -> Dict [ str , str ] :
145
158
"""Extract version information from the given file."""
146
159
# the code embedded in _version.py can just fetch the value of these
147
160
# keywords. When used from setup.py, we don't want to import _version.py,
148
161
# so we do it with a regexp instead. This function is not used from
149
162
# _version.py.
150
- keywords = {}
163
+ keywords : Dict [ str , str ] = {}
151
164
try :
152
165
with open (versionfile_abs , "r" ) as fobj :
153
166
for line in fobj :
@@ -169,7 +182,11 @@ def git_get_keywords(versionfile_abs):
169
182
170
183
171
184
@register_vcs_handler ("git" , "keywords" )
172
- def git_versions_from_keywords (keywords , tag_prefix , verbose ):
185
+ def git_versions_from_keywords (
186
+ keywords : Dict [str , str ],
187
+ tag_prefix : str ,
188
+ verbose : bool ,
189
+ ) -> Dict [str , Any ]:
173
190
"""Get version information from git keywords."""
174
191
if "refnames" not in keywords :
175
192
raise NotThisMethod ("Short version file found" )
@@ -233,7 +250,12 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
233
250
234
251
235
252
@register_vcs_handler ("git" , "pieces_from_vcs" )
236
- def git_pieces_from_vcs (tag_prefix , root , verbose , runner = run_command ):
253
+ def git_pieces_from_vcs (
254
+ tag_prefix : str ,
255
+ root : str ,
256
+ verbose : bool ,
257
+ runner : Callable = run_command
258
+ ) -> Dict [str , Any ]:
237
259
"""Get version from 'git describe' in the root of the source tree.
238
260
239
261
This only gets called if the git-archive 'subst' keywords were *not*
@@ -273,7 +295,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
273
295
raise NotThisMethod ("'git rev-parse' failed" )
274
296
full_out = full_out .strip ()
275
297
276
- pieces = {}
298
+ pieces : Dict [ str , Any ] = {}
277
299
pieces ["long" ] = full_out
278
300
pieces ["short" ] = full_out [:7 ] # maybe improved later
279
301
pieces ["error" ] = None
@@ -365,14 +387,14 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
365
387
return pieces
366
388
367
389
368
- def plus_or_dot (pieces ) :
390
+ def plus_or_dot (pieces : Dict [ str , Any ]) -> str :
369
391
"""Return a + if we don't already have one, else return a ."""
370
392
if "+" in pieces .get ("closest-tag" , "" ):
371
393
return "."
372
394
return "+"
373
395
374
396
375
- def render_pep440 (pieces ) :
397
+ def render_pep440 (pieces : Dict [ str , Any ]) -> str :
376
398
"""Build up version string, with post-release "local version identifier".
377
399
378
400
Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
@@ -397,7 +419,7 @@ def render_pep440(pieces):
397
419
return rendered
398
420
399
421
400
- def render_pep440_branch (pieces ) :
422
+ def render_pep440_branch (pieces : Dict [ str , Any ]) -> str :
401
423
"""TAG[[.dev0]+DISTANCE.gHEX[.dirty]] .
402
424
403
425
The ".dev0" means not master branch. Note that .dev0 sorts backwards
@@ -427,7 +449,7 @@ def render_pep440_branch(pieces):
427
449
return rendered
428
450
429
451
430
- def pep440_split_post (ver ) :
452
+ def pep440_split_post (ver : str ) -> Tuple [ str , Optional [ int ]] :
431
453
"""Split pep440 version string at the post-release segment.
432
454
433
455
Returns the release segments before the post-release and the
@@ -437,7 +459,7 @@ def pep440_split_post(ver):
437
459
return vc [0 ], int (vc [1 ] or 0 ) if len (vc ) == 2 else None
438
460
439
461
440
- def render_pep440_pre (pieces ) :
462
+ def render_pep440_pre (pieces : Dict [ str , Any ]) -> str :
441
463
"""TAG[.postN.devDISTANCE] -- No -dirty.
442
464
443
465
Exceptions:
@@ -461,7 +483,7 @@ def render_pep440_pre(pieces):
461
483
return rendered
462
484
463
485
464
- def render_pep440_post (pieces ) :
486
+ def render_pep440_post (pieces : Dict [ str , Any ]) -> str :
465
487
"""TAG[.postDISTANCE[.dev0]+gHEX] .
466
488
467
489
The ".dev0" means dirty. Note that .dev0 sorts backwards
@@ -488,7 +510,7 @@ def render_pep440_post(pieces):
488
510
return rendered
489
511
490
512
491
- def render_pep440_post_branch (pieces ) :
513
+ def render_pep440_post_branch (pieces : Dict [ str , Any ]) -> str :
492
514
"""TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] .
493
515
494
516
The ".dev0" means not master branch.
@@ -517,7 +539,7 @@ def render_pep440_post_branch(pieces):
517
539
return rendered
518
540
519
541
520
- def render_pep440_old (pieces ) :
542
+ def render_pep440_old (pieces : Dict [ str , Any ]) -> str :
521
543
"""TAG[.postDISTANCE[.dev0]] .
522
544
523
545
The ".dev0" means dirty.
@@ -539,7 +561,7 @@ def render_pep440_old(pieces):
539
561
return rendered
540
562
541
563
542
- def render_git_describe (pieces ) :
564
+ def render_git_describe (pieces : Dict [ str , Any ]) -> str :
543
565
"""TAG[-DISTANCE-gHEX][-dirty].
544
566
545
567
Like 'git describe --tags --dirty --always'.
@@ -559,7 +581,7 @@ def render_git_describe(pieces):
559
581
return rendered
560
582
561
583
562
- def render_git_describe_long (pieces ) :
584
+ def render_git_describe_long (pieces : Dict [ str , Any ]) -> str :
563
585
"""TAG-DISTANCE-gHEX[-dirty].
564
586
565
587
Like 'git describe --tags --dirty --always -long'.
@@ -579,7 +601,7 @@ def render_git_describe_long(pieces):
579
601
return rendered
580
602
581
603
582
- def render (pieces , style ) :
604
+ def render (pieces : Dict [ str , Any ], style : str ) -> Dict [ str , Any ] :
583
605
"""Render the given version pieces into the requested style."""
584
606
if pieces ["error" ]:
585
607
return {"version" : "unknown" ,
@@ -615,7 +637,7 @@ def render(pieces, style):
615
637
"date" : pieces .get ("date" )}
616
638
617
639
618
- def get_versions ():
640
+ def get_versions () -> Dict [ str , Any ] :
619
641
"""Get version information or return default if unable to do so."""
620
642
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
621
643
# __file__, we can work backwards from there to the root. Some
0 commit comments