Skip to content

Commit

Permalink
Create project-level nexus-version file
Browse files Browse the repository at this point in the history
  • Loading branch information
domna committed Oct 30, 2023
1 parent 3112a8c commit 7468544
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
"pynxtools",
"tests"
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.organizeImports": false
}
},
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
Expand Down
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
recursive-include pynxtools/definitions/base_classes/ *.xml
recursive-include pynxtools/definitions/applications/ *.xml
recursive-include pynxtools/definitions/contributed_definitions/ *.xml
include pynxtools/definitions/*.xsd
include pynxtools/definitions/*.xsd
include pynxtools/nexus-version.txt
include pynxtools/definitions/NXDL_VERSION
25 changes: 25 additions & 0 deletions pynxtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
from glob import glob

from pynxtools._build_wrapper import get_vcs_version


def get_nexus_version() -> str:
"""
The version of the Nexus standard and the NeXus Definition language
based on git tags and commits
"""
version = get_vcs_version()
if version is not None:
return version

version_file = os.path.join(os.path.dirname(__file__), "nexus-version.txt")

if not os.path.exists(version_file):
# We are in the limbo, just get the nxdl version from nexus definitions
from pynxtools.definitions.dev_tools.globals.nxdl import get_nxdl_version

return get_nxdl_version()

with open(version_file) as vfile:
return vfile.read().strip()
40 changes: 16 additions & 24 deletions pynxtools/_build_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_vcs_version(tag_match="*[0-9]*") -> Optional[str]:
return (
run(
["git", "describe", "--tags", "--long", "--match", tag_match],
cwd=os.path.join(os.path.dirname(__file__), "definitions"),
cwd=os.path.join(os.path.dirname(__file__), "../pynxtools/definitions"),
check=True,
capture_output=True,
)
Expand All @@ -27,42 +27,34 @@ def get_vcs_version(tag_match="*[0-9]*") -> Optional[str]:
return None


def _write_version_to_metadata(metadata_directory: str, dist_dir: str = None):
def _write_version_to_metadata(directory: str):
version = get_vcs_version()
if version is None or not version:
raise ValueError("Could not determine version from nexus_definitions")

with open(
os.path.join(metadata_directory, dist_dir, "nexus-version.txt")
if dist_dir is not None
else os.path.join(metadata_directory, "nexus-version.txt"),
os.path.join(os.path.dirname(__file__), "nexus-version.txt"),
"w+",
encoding="utf-8",
) as file:
file.write(get_vcs_version())


def prepare_metadata_for_build_editable(metadata_directory, config_settings=None):
dist_dir = _orig.prepare_metadata_for_build_wheel(
metadata_directory, config_settings
)
_write_version_to_metadata(metadata_directory, dist_dir)
return dist_dir


def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
dist_dir = _orig.prepare_metadata_for_build_wheel(
metadata_directory, config_settings
)
_write_version_to_metadata(metadata_directory, dist_dir)
return dist_dir
file.write(version)


def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
# _write_version_to_metadata(metadata_directory)
_write_version_to_metadata(metadata_directory)
ret = _orig.build_editable(wheel_directory, config_settings, metadata_directory)

return ret


def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
# _write_version_to_metadata(metadata_directory)
_write_version_to_metadata(metadata_directory)
ret = _orig.build_wheel(wheel_directory, config_settings, metadata_directory)

return ret


def build_sdist(sdist_directory, config_settings=None):
_write_version_to_metadata(os.path.join(os.path.dirname(__file__), "../"))
sdist_dir = _orig.build_sdist(sdist_directory, config_settings)
return sdist_dir
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.definitions.dev_tools.globals.nxdl import get_vcs_version
from pynxtools import get_nexus_version

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

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

0 comments on commit 7468544

Please sign in to comment.