Skip to content

Commit

Permalink
Adds version hash to definition url
Browse files Browse the repository at this point in the history
  • Loading branch information
domna committed Nov 1, 2023
1 parent ab8f360 commit dc9306f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
15 changes: 15 additions & 0 deletions pynxtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
# limitations under the License.
#
import os
import re
from glob import glob
from typing import Union

from pynxtools._build_wrapper import get_vcs_version
from pynxtools.definitions.dev_tools.globals.nxdl import get_nxdl_version

MAIN_BRANCH_NAME = "fairmat"


def _build_version(tag: str, distance: int, node: str, dirty: bool) -> str:
"""
Expand Down Expand Up @@ -69,3 +72,15 @@ def get_nexus_version() -> str:

with open(version_file, encoding="utf-8") as vfile:
return format_version(vfile.read().strip())


def get_nexus_version_hash() -> str:
"""
Gets the git hash from the nexus version string
"""
version = re.search(r"g([a-z0-9]+)", get_nexus_version())

if version is None:
return MAIN_BRANCH_NAME

return version.group(1)
4 changes: 4 additions & 0 deletions pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ def add_default_root_attributes(data, filename):
data["/@file_name"] = filename
data["/@file_time"] = str(datetime.now(timezone.utc).astimezone())
data["/@file_update_time"] = data["/@file_time"]
data["/@NeXus_repository"] = (
"https://github.com/FAIRmat-NFDI/nexus_definitions/"
f"blob/{get_nexus_version_hash()}"
)
data["/@NeXus_version"] = get_nexus_version()
data["/@HDF5_version"] = '.'.join(map(str, h5py.h5.get_libversion())) # pylint: disable=c-extension-no-member
data["/@h5py_version"] = h5py.__version__
Expand Down
4 changes: 2 additions & 2 deletions pynxtools/dataconverter/readers/ellips/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pynxtools.dataconverter.readers.ellips.mock import MockEllips
from pynxtools.dataconverter.helpers import extract_atom_types
from pynxtools.dataconverter.readers.utils import flatten_and_replace, FlattenSettings
from pynxtools import get_nexus_version
from pynxtools import get_nexus_version, get_nexus_version_hash

DEFAULT_HEADER = {'sep': '\t', 'skip': 0}

Expand Down Expand Up @@ -470,7 +470,7 @@ def read(self,
template["/ENTRY[entry]/definition"] = "NXellipsometry"
template["/ENTRY[entry]/definition/@url"] = (
"https://github.com/FAIRmat-NFDI/nexus_definitions/"
"blob/fairmat/contributed_definitions/NXellipsometry.nxdl.xml"
f"blob/{get_nexus_version_hash()}/contributed_definitions/NXellipsometry.nxdl.xml"
)
template["/ENTRY[entry]/definition/@version"] = get_nexus_version()
template["/ENTRY[entry]/program_name"] = "pynxtools"
Expand Down

0 comments on commit dc9306f

Please sign in to comment.