Skip to content

Commit

Permalink
Merge pull request #494 from aiven/ivanyu/3.3.x-version
Browse files Browse the repository at this point in the history
Allow specifying version directly during build
  • Loading branch information
jjaakola-aiven authored Nov 21, 2022
2 parents bc0983a + 2549e3e commit 67f5da0
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@ def get_project_version(version_file: str) -> str:
module = importlib.util.module_from_spec(module_spec)
file_ver = getattr(module, "__version__", None)

os.chdir(os.path.dirname(__file__) or ".")
try:
git_out = subprocess.check_output(
["git", "describe", "--always", "--tags"], stderr=getattr(subprocess, "DEVNULL", None)
)
except (OSError, subprocess.CalledProcessError):
pass
else:
git_ver = git_out.splitlines()[0].strip().decode("utf-8")
if "." not in git_ver:
git_ver = "0.0.1-0-unknown-{}".format(git_ver)
if save_version(git_ver, file_ver, version_file):
return git_ver
version = os.getenv("KARAPACE_VERSION")
if version is None:
os.chdir(os.path.dirname(__file__) or ".")
try:
git_out = subprocess.check_output(
["git", "describe", "--always", "--tags"], stderr=getattr(subprocess, "DEVNULL", None)
)
except (OSError, subprocess.CalledProcessError):
pass
else:
git_ver = git_out.splitlines()[0].strip().decode("utf-8")
if "." not in git_ver:
git_ver = "0.0.1-0-unknown-{}".format(git_ver)
version = git_ver

if save_version(version, file_ver, version_file):
return version

if not file_ver:
raise Exception("version not available from git or from file {!r}".format(version_file))
Expand Down

0 comments on commit 67f5da0

Please sign in to comment.