Skip to content

Commit

Permalink
use setuptools-scm style version
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Nov 27, 2024
1 parent 7fe2c02 commit 7ad83d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
29 changes: 23 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,41 @@ class VrsSubmoduleFetchError(Exception):
"""Raise for errors during submodule metadata extraction"""


def get_vrs_submodule_info():
"""Retrieve the commit hash and tag from the vrs submodule."""
def _get_vrs_submodule_info() -> tuple[str, str, int]:
"""Retrieve the commit hash and tag from the vrs submodule.
:return: tuple containing commit hash, latest version tag, and rev distance between them
"""
try:
return subprocess.check_output(
["git", "describe", "--tags", "--abbrev=0"], cwd="submodules/vrs", text=True
vrs_path = "submodules/vrs"
commit = subprocess.check_output(
["git", "rev-parse", "HEAD"], cwd=vrs_path, text=True
).strip()
tag = subprocess.check_output(
["git", "describe", "--tags", "--abbrev=0"], cwd=vrs_path, text=True
).strip()
distance = subprocess.check_output(
["git", "rev-list", f"{tag}..HEAD", "--count"],
cwd=vrs_path,
text=True,
).strip()
return commit, tag, int(distance)
except Exception as e:
raise VrsSubmoduleFetchError from e


def write_metadata_file():
"""Generate a Python module with submodule metadata."""
tag = get_vrs_submodule_info()
commit, tag, distance = _get_vrs_submodule_info()
metadata_path = Path("src/ga4gh/vrs/submodule_metadata.py")
metadata_path.parent.mkdir(parents=True, exist_ok=True)
if distance == 0:
version = tag
else:
version = f"{tag}.dev{distance}+g{commit}"
metadata_path.write_text(
f"# Auto-generated metadata from VRS schema submodule\n"
f"VRS_RELEASE = '{tag}'\n"
f"VRS_VERSION = '{version}'\n"
)


Expand Down
4 changes: 2 additions & 2 deletions src/ga4gh/vrs/submodule_metadata.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Auto-generated metadata for VRS submodule
VRS_TAG = '2.0.0.connect.2024-04.1'
# Auto-generated metadata from VRS schema submodule
VRS_VERSION = '2.0.0.connect.2024-04.1.dev83+gcf968d24a37cefca5a2f363f0e2f36741cd12ad5'

0 comments on commit 7ad83d3

Please sign in to comment.