Skip to content

Commit

Permalink
Adds build wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
domna committed Oct 26, 2023
1 parent d9ef1ee commit 7f5e908
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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
68 changes: 68 additions & 0 deletions pynxtools/_build_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import os
from glob import glob
from subprocess import CalledProcessError, run
from typing import Optional

from setuptools import build_meta as _orig
from setuptools.build_meta import *


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__), "definitions"),
check=True,
capture_output=True,
)
.stdout.decode("utf-8")
.strip()
)
except (FileNotFoundError, CalledProcessError):
return None


def _write_version_to_metadata(metadata_directory: str, dist_dir: str = None):
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"),
"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


def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
# _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)
ret = _orig.build_wheel(wheel_directory, config_settings, metadata_directory)

return ret
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[build-system]
requires = ["setuptools>=64.0.1", "setuptools-scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"
backend-path = ["pynxtools"]
build-backend = "_build_wrapper"

[project]
name = "pynxtools"
Expand All @@ -10,7 +11,7 @@ authors = [
]
description = "Extend NeXus for materials science experiment and serve as a NOMAD parser implementation for NeXus."
readme = "README.md"
license = { file = "LICENSE.txt" }
license = { file = "LICENSE" }
requires-python = ">=3.8,<3.11"
classifiers = [
"Programming Language :: Python :: 3.8",
Expand Down

0 comments on commit 7f5e908

Please sign in to comment.