Skip to content

Commit

Permalink
Adds vcs versioning for git_nxdl_version
Browse files Browse the repository at this point in the history
  • Loading branch information
domna committed Oct 31, 2023
1 parent df84535 commit c4a86e6
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion dev_tools/globals/nxdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,42 @@ class definitions (the NXDL namespace).
relative URI "../nxdl.xsd" which means validation
can only be done for NXDL files in subdirectories.
"""
import os
from subprocess import CalledProcessError
from subprocess import run
from typing import Optional

from .directories import get_nxdl_version_file

XSD_NAMESPACE = "http://www.w3.org/2001/XMLSchema"
NXDL_NAMESPACE = "http://definition.nexusformat.org/nxdl/3.1"


def get_vcs_version(tag_match="*[0-9]*") -> Optional[str]:
"""
The version of the Nexus standard and the NeXus Definition language
based on git tags and commits
"""
try:
return (
run(
["git", "describe", "--tags", "--long", "--match", tag_match],
cwd=os.path.join(os.path.dirname(__file__)),
check=True,
capture_output=True,
)
.stdout.decode("utf-8")
.strip()
)
except CalledProcessError:
return None


def get_nxdl_version() -> str:
"""The version of the NeXus standard and the NeXus Definition language"""
with open(get_nxdl_version_file(), "r") as fh:
version = get_vcs_version()
if version is not None:
return version

with open(get_nxdl_version_file(), "r", encoding="utf-8") as fh:
return fh.read().strip()

0 comments on commit c4a86e6

Please sign in to comment.