Created
September 30, 2019 22:57
-
-
Save styk-tv/330f7ef66263499813455273a431e645 to your computer and use it in GitHub Desktop.
semantic version from git describe tags (python3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import subprocess | |
proc1 = subprocess.Popen("git describe --tags", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | |
out = proc1.communicate() | |
if proc1.returncode != 0: | |
sys.stdout.write("fourbars must install from cloned folder. make sure .git folder exists\n") | |
sys.stdout.write(out[1]) | |
raise SystemExit(32) | |
v = out[0].decode('ascii').replace('\n', '') | |
if v.startswith('v.'): | |
v = v[2:] | |
elif v.startswith('v'): | |
v = v[1:] | |
li = v.split('.') | |
lii = li[1].split('-') | |
if len(lii) == 3: | |
v = '{0}.{1}.{2}'.format(li[0],lii[0],lii[1]) | |
else: | |
v = '{0}.{1}'.format(li[0], li[1]) | |
print (v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if
then above produces
1.0.31
which is acceptable by pypi for VERSION inside of setup.py