5 from stgit
.run
import Run
, RunException
8 class VersionUnavailable(Exception):
12 def git_describe_version():
13 root
= sys
.path
[0] if sys
.path
[0] else None
16 Run('git', 'describe', '--tags', '--abbrev=4')
21 except RunException
as e
:
22 raise VersionUnavailable(str(e
))
23 m
= re
.match(r
'^v([0-9].*)', v
)
27 raise VersionUnavailable('bad version: %s' % v
)
30 Run('git', 'diff-index', '--name-only', 'HEAD')
35 except RunException
as e
:
36 raise VersionUnavailable(str(e
))
42 def git_archival_version():
43 archival_path
= os
.path
.join(sys
.path
[0], '.git_archival.txt')
44 if not os
.path
.isfile(archival_path
):
45 # The archival file will not be present in sdist archives.
46 raise VersionUnavailable('%s does not exist' % archival_path
)
47 tag_re
= re
.compile(r
'(?<=\btag: )([^,]+)\b')
48 with
open(archival_path
) as f
:
50 if line
.startswith('ref-names:'):
51 for tag
in tag_re
.findall(line
):
52 if tag
.startswith('v'):
55 raise VersionUnavailable('no tags found in %s' % archival_path
)
58 def get_builtin_version():
60 import stgit
.builtin_version
62 raise VersionUnavailable('could not import stgit.builtin_version')
64 return stgit
.builtin_version
.version
68 for v
in [get_builtin_version
, git_describe_version
, git_archival_version
]:
71 except VersionUnavailable
:
73 return 'unknown-version'
76 # minimum version requirements
78 python_min_ver
= '3.5'