Skip to content

Commit

Permalink
Merge pull request #131 from arighi/git-version
Browse files Browse the repository at this point in the history
version: generate verison string based on git information
  • Loading branch information
Andrea Righi authored Jul 2, 2024
2 parents 6f19a9c + 5cdb2f0 commit 22fb61a
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions virtme_ng/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,39 @@

"""virtme-ng version"""

VERSION = "1.25"
from subprocess import check_output, DEVNULL, CalledProcessError

if __name__ == '__main__':
PKG_VERSION = "1.25"


def get_version_string():
try:
# Get the version from git describe
version = (
check_output(
"git describe --always --long --dirty",
shell=True,
stderr=DEVNULL,
)
.decode("utf-8")
.strip()
)

# Remove the 'v' prefix if present
if version.startswith("v"):
version = version[1:]

# Replace hyphens with plus sign for build metadata
version_pep440 = version.replace("-", "+", 1).replace("-", ".")

return version_pep440
except CalledProcessError:
# Default version if git describe fails (e.g., when building virtme-ng
# from a source package.
return PKG_VERSION


VERSION = get_version_string()

if __name__ == "__main__":
print(VERSION)

0 comments on commit 22fb61a

Please sign in to comment.