Skip to content

Commit

Permalink
feat: make VRS schema release info accessible in VRS-Python
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Nov 27, 2024
1 parent 7c5629e commit 412012d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from setuptools import setup
from pathlib import Path
import subprocess


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."""
try:
try:
tag = subprocess.check_output(
["git", "describe", "--tags", "--abbrev=0"], cwd="submodules/vrs", text=True
).strip()
except subprocess.CalledProcessError:
raise VrsSubmoduleFetchError
return tag
except Exception as e:
raise VrsSubmoduleFetchError from e


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


write_metadata_file()

# Use setuptools for the actual build (delegates to pyproject.toml)
setup()
2 changes: 2 additions & 0 deletions src/ga4gh/vrs/submodule_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto-generated metadata for VRS submodule
VRS_TAG = '2.0.0.connect.2024-04.1'

0 comments on commit 412012d

Please sign in to comment.