Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make VRS schema release info accessible in VRS-Python #467

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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() -> 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:
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."""
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_VERSION = '{version}'\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 from VRS schema submodule
VRS_VERSION = '2.0.0.connect.2024-04.1.dev83+gcf968d24a37cefca5a2f363f0e2f36741cd12ad5'
Loading