From 02f9faf211284d5e8b0c9b49d258a5318d6d15b9 Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:05:25 +0200 Subject: [PATCH 1/2] remove setuptools from dependencies --- src/pynxtools/_build_wrapper.py => _build_wrapper.py | 0 pyproject.toml | 2 -- tests/dataconverter/test_convert.py | 6 +++--- tests/dataconverter/test_helpers.py | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) rename src/pynxtools/_build_wrapper.py => _build_wrapper.py (100%) diff --git a/src/pynxtools/_build_wrapper.py b/_build_wrapper.py similarity index 100% rename from src/pynxtools/_build_wrapper.py rename to _build_wrapper.py diff --git a/pyproject.toml b/pyproject.toml index e3a5a81f2..51b266a36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,5 @@ [build-system] requires = ["setuptools>=64.0.1", "setuptools-scm[toml]>=6.2"] -backend-path = ["src/pynxtools"] build-backend = "_build_wrapper" [project] @@ -35,7 +34,6 @@ dependencies = [ "importlib-metadata", "lxml>=4.9.1", "anytree", - "setuptools>=64.0.1" ] [project.urls] diff --git a/tests/dataconverter/test_convert.py b/tests/dataconverter/test_convert.py index 55570e4d0..3ee09e8a8 100644 --- a/tests/dataconverter/test_convert.py +++ b/tests/dataconverter/test_convert.py @@ -20,12 +20,12 @@ import logging import os from pathlib import Path +import shutil import click import h5py import pytest from click.testing import CliRunner -from setuptools import distutils import pynxtools.dataconverter.convert as dataconverter from pynxtools.dataconverter.readers.base.reader import BaseReader @@ -34,7 +34,7 @@ def move_xarray_file_to_tmp(tmp_path): """Moves the xarray file, which is used to test linking into the tmp_path directory.""" - distutils.file_util.copy_file( + shutil.copy( os.path.join( os.getcwd(), "src", "pynxtools", "data", "xarray_saved_small_calibration.h5" ), @@ -49,7 +49,7 @@ def restore_xarray_file_from_tmp(tmp_path): os.getcwd(), "src", "pynxtools", "data", "xarray_saved_small_calibration.h5" ) ) - distutils.file_util.move_file( + shutil.move( os.path.join(tmp_path, "xarray_saved_small_calibration.h5"), os.path.join( os.getcwd(), "src", "pynxtools", "data", "xarray_saved_small_calibration.h5" diff --git a/tests/dataconverter/test_helpers.py b/tests/dataconverter/test_helpers.py index 0401862db..32582b5e2 100644 --- a/tests/dataconverter/test_helpers.py +++ b/tests/dataconverter/test_helpers.py @@ -21,10 +21,10 @@ import os import xml.etree.ElementTree as ET from typing import Optional +import shutil import numpy as np import pytest -from setuptools import distutils from pynxtools.dataconverter import helpers from pynxtools.dataconverter.template import Template @@ -148,7 +148,7 @@ def fixture_filled_test_data(template, tmp_path): # Copy original measurement file to tmp dir, # because h5py.ExternalLink is modifying it while # linking the nxs file. - distutils.file_util.copy_file( + shutil.copy( os.path.join( os.getcwd(), "src", "pynxtools", "data", "xarray_saved_small_calibration.h5" ), From 96f8e00eba297d21cb378adbe6e22a6c6f29e1e3 Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:21:55 +0200 Subject: [PATCH 2/2] copy get_vcs_version function --- _build_wrapper.py | 4 +++- pyproject.toml | 1 + src/pynxtools/__init__.py | 31 ++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/_build_wrapper.py b/_build_wrapper.py index ababdb96f..6e2dac695 100644 --- a/_build_wrapper.py +++ b/_build_wrapper.py @@ -28,7 +28,9 @@ def get_vcs_version(tag_match="*[0-9]*") -> Optional[str]: "--match", tag_match, ], - cwd=os.path.join(os.path.dirname(__file__), "../pynxtools/definitions"), + cwd=os.path.join( + os.path.dirname(__file__), "src/pynxtools/definitions" + ), check=True, capture_output=True, ) diff --git a/pyproject.toml b/pyproject.toml index 51b266a36..796aeda8e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,6 @@ [build-system] requires = ["setuptools>=64.0.1", "setuptools-scm[toml]>=6.2"] +backend-path = ["."] build-backend = "_build_wrapper" [project] diff --git a/src/pynxtools/__init__.py b/src/pynxtools/__init__.py index 52a749e5b..1b7a222f1 100644 --- a/src/pynxtools/__init__.py +++ b/src/pynxtools/__init__.py @@ -19,13 +19,42 @@ import os import re from datetime import datetime +from subprocess import CalledProcessError, run +from typing import Optional -from pynxtools._build_wrapper import get_vcs_version from pynxtools.definitions.dev_tools.globals.nxdl import get_nxdl_version MAIN_BRANCH_NAME = "fairmat" +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", + "--dirty", + "--tags", + "--long", + "--match", + tag_match, + ], + cwd=os.path.join(os.path.dirname(__file__), "../pynxtools/definitions"), + check=True, + capture_output=True, + ) + .stdout.decode("utf-8") + .strip() + ) + except (FileNotFoundError, CalledProcessError): + return None + + def _build_version(tag: str, distance: int, node: str, dirty: bool) -> str: """ Builds the version string for a given set of git states.