Created
October 19, 2018 11:42
-
-
Save HerrSpace/456ddfb9b64cdb27711c6477d623bca9 to your computer and use it in GitHub Desktop.
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
def git_version(path): | |
# Like v1.0.0 or v1.0.0-1-g963fc39.dirty | |
git_describe = check_output([ | |
'git', '-C', path, 'describe', '--tags', '--dirty=.dirty'] | |
).decode().strip() | |
# Like v1.0.0 | |
last_tag = check_output([ | |
'git', '-C', path, 'describe', '--tags', '--abbrev=0'] | |
).decode().strip() | |
# Strip leading v often used in tag names. | |
last_version = last_tag.lstrip('v') | |
# Like .dev1+g963fc39.dirty | |
diff_to_tag = ( | |
git_describe[len(last_tag):] | |
.replace('-', '.dev', 1) | |
.replace('-', '+', 1) | |
) | |
# Like 1.0.0.dev1+g963fc39.dirty, compatible to PEP440 | |
return last_version + diff_to_tag | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment