Skip to content

Commit

Permalink
setup: Improve version retrieval from git describe
Browse files Browse the repository at this point in the history
Avoid retrieving the version from an upper Git repository in case
pyroute2 files are simply copied in the said repository, and not cloned.
  • Loading branch information
JeThWifirst committed Jul 11, 2023
1 parent c7da937 commit 5baeaaf
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions util/update_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
import subprocess
from pathlib import Path

version_module = "pyroute2/config/version.py"
version_output_file = "VERSION"
Expand All @@ -13,11 +14,24 @@ def get_project_version():
1. fetch version from git
2. if not available, fallback to the version file in the repo
"""
version = None

try:
version = subprocess.check_output(
("git", "describe"), stderr=subprocess.DEVNULL
).decode("utf-8")
git_top_level = Path(
subprocess.check_output(
("git", "rev-parse", "--show-toplevel"), stderr=subprocess.DEVNULL
).decode("utf-8").strip()
)
pyroute2_top_level = Path(__file__).parent.parent.absolute()
# Only retrieve the git description from the pyroute2 directory
if git_top_level == pyroute2_top_level:
version = subprocess.check_output(
("git", "describe"), stderr=subprocess.DEVNULL
).decode("utf-8")
except (FileNotFoundError, subprocess.CalledProcessError):
pass

if version is None:
with open(version_input_file, "r") as f:
version = f.read()

Expand Down

0 comments on commit 5baeaaf

Please sign in to comment.