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

Adds git based versioning for get_nxdl_version #1318

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 30 additions & 1 deletion dev_tools/globals/nxdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,42 @@ class definitions (the NXDL namespace).
can only be done for NXDL files in subdirectories.
"""

import os
from subprocess import CalledProcessError
from subprocess import run
domna marked this conversation as resolved.
Show resolved Hide resolved
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()
Loading