-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set version automatically during release
up until now you had to remember to update the version manually
- Loading branch information
Showing
4 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
# For relative imports to work in Python 3.6 | ||
# See https://stackoverflow.com/a/49375740 | ||
import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__))) | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
__version__ = "0.2.1" | ||
# For relative imports to work in Python 3.6 - see https://stackoverflow.com/a/49375740 | ||
sys.path.append(os.path.dirname(os.path.realpath(__file__))) | ||
|
||
# This is patched by github actions during release | ||
__version__ = "0.0.0" | ||
|
||
|
||
def get_version() -> str: | ||
# the version string was patched by a release - return __version__ which will be correct | ||
if not __version__.startswith("0.0.0"): | ||
return __version__ | ||
|
||
# we are running from an unreleased dev version | ||
try: | ||
# Get the latest git tag | ||
tag = subprocess.check_output(["git", "describe", "--tags"]).decode().strip() | ||
|
||
# Get the current branch name | ||
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode().strip() | ||
|
||
# Check if there are uncommitted changes | ||
status = subprocess.check_output(["git", "status", "--porcelain"]).decode().strip() | ||
dirty = "-dirty" if status else "" | ||
|
||
return f"{tag}-{branch}{dirty}" | ||
|
||
except Exception: | ||
return f"dev-version" |