Skip to content

Commit cf0d54d

Browse files
jaankitGerrit Code Review
authored andcommitted
Merge "setup.py: Use latest git tag to set version."
2 parents 3753e6b + ff8f4a8 commit cf0d54d

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
'photon-iso-builder = photon_installer.isoBuilder:main'
2626
]
2727
},
28-
version='2.2+'+get_installer_version(),
28+
version=get_installer_version(),
2929
author_email='[email protected]'
3030
)

version.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
__all__ = ('get_installer_version')
99

10+
# Default Tag represents tag value in case git is not available on system.
11+
# This need not be updated with every tag release.
12+
defaultTag = "2.2"
13+
1014
import os
1115
from subprocess import Popen, PIPE
1216
from subprocess import call, STDOUT
@@ -21,6 +25,15 @@ def get_version():
2125
except:
2226
raise ValueError('Cannot get the version number!')
2327

28+
def get_latest_tag():
29+
try:
30+
p = Popen(['git', 'describe', '--tags', '--abbrev=0'],
31+
stdout=PIPE, stderr=PIPE)
32+
p.stderr.close()
33+
line = p.stdout.readlines()[0].decode().strip()
34+
return line[1:]
35+
except:
36+
raise ValueError('Cannot get the latest tag!')
2437

2538
def is_dirty():
2639
try:
@@ -34,15 +47,15 @@ def is_dirty():
3447

3548

3649
def get_installer_version():
37-
# if not a git repo, return empty string
50+
# if not a git repo, return default tag.
3851
try:
3952
if call(['git', 'branch'], stderr=STDOUT, stdout=open(os.devnull, 'w')):
40-
return ''
53+
return defaultTag
4154
except FileNotFoundError:
42-
# also return empty when we do not have git
43-
return ''
55+
# also return default tag when we do not have git.
56+
return defaultTag
4457

45-
version = get_version()
58+
version = f"{get_latest_tag()}+{get_version()}"
4659
if not version:
4760
raise ValueError("Cannot get the version number!")
4861

0 commit comments

Comments
 (0)