Skip to content

Instantly share code, notes, and snippets.

@styk-tv
Created September 30, 2019 22:57
Show Gist options
  • Save styk-tv/330f7ef66263499813455273a431e645 to your computer and use it in GitHub Desktop.
Save styk-tv/330f7ef66263499813455273a431e645 to your computer and use it in GitHub Desktop.
semantic version from git describe tags (python3)
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)
@styk-tv
Copy link
Author

styk-tv commented Sep 30, 2019

if

git describe --tags
v1.0-31-g1c5614b

then above produces
1.0.31
which is acceptable by pypi for VERSION inside of setup.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment