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

Map to basesections reorganized 2 #427

Merged
merged 40 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e94b706
import basesections
lukaspie Sep 2, 2024
35b1356
initiate base section map
lukaspie Sep 2, 2024
b532f64
implement mapping in __to_section
lukaspie Sep 2, 2024
7bd19b3
type hinting
lukaspie Sep 2, 2024
af715bf
name testing
lukaspie Sep 2, 2024
6fb0cd4
create own basesections with mapping
lukaspie Sep 2, 2024
deb79bd
dynamically create class that inherits from base section
lukaspie Sep 2, 2024
7a23859
use base section mapping function
lukaspie Sep 2, 2024
86d3840
add base section directly
lukaspie Sep 3, 2024
76ac1aa
rename nexus to nomad.
RubelMozumder Sep 3, 2024
4ed032b
rename nexus to nomad.
RubelMozumder Sep 3, 2024
b1deab7
harmonize collaborative work, functionality to get the correct defini…
lukaspie Sep 3, 2024
1b5e669
rename file with remote definitions url
lukaspie Sep 3, 2024
de4aa07
add .txt to MANIFEST
lukaspie Sep 3, 2024
bb378ec
test for definitions url retrieval
lukaspie Sep 3, 2024
4f2efaa
remove unneeded function
lukaspie Sep 3, 2024
3fb908e
Fix error Parsing NeXus file: Error from resolve_variadic_name function.
RubelMozumder Sep 3, 2024
579795e
Test effort to fix error in parsing nexus file.
RubelMozumder Sep 4, 2024
7c3e024
revert changes to parser
lukaspie Sep 4, 2024
b850b8f
revert changes to parser
lukaspie Sep 4, 2024
341284c
Nomad BaseSeection implemented properly.
RubelMozumder Sep 5, 2024
ec3a8a2
Attempt: Add normalize function.
RubelMozumder Sep 5, 2024
fd71d09
linting fix
lukaspie Sep 6, 2024
f1ce2e8
reorganize, dont use new classes
lukaspie Sep 6, 2024
49b8647
implement both options
lukaspie Sep 6, 2024
fe6cb1e
tests in schema.py
GinzburgLev Sep 6, 2024
9be00c3
reasonable test for normalizing NXfabrication
sanbrock Sep 7, 2024
a0744ae
ruff formatting
lukaspie Sep 9, 2024
3f84666
initial work on NXsample normalization
lukaspie Sep 9, 2024
6042b99
Attempt to reference NXsample.
RubelMozumder Sep 9, 2024
60bd60a
lab_id can be populated properly, nut not sure CompositeSystemReferen…
RubelMozumder Sep 9, 2024
fe08109
reference aadding with lev and sandor
Sep 10, 2024
2c03ad1
RB
RubelMozumder Sep 12, 2024
f69cad9
creating Entity entries via json files
sanbrock Sep 10, 2024
6e1cad5
create proper Entity ELN
sanbrock Sep 10, 2024
d61d387
Clean up schema.py
RubelMozumder Sep 11, 2024
704bf78
converting NX to BS works properly in nexus parser.
RubelMozumder Sep 11, 2024
620ce87
test fix.
RubelMozumder Sep 12, 2024
fde8058
typo and test.
RubelMozumder Sep 12, 2024
e602092
automat prefix of base classes and application definition.
RubelMozumder Sep 12, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ cython_debug/
!dev-requirements.txt
!mkdocs-requirements.txt
!src/pynxtools/nexus-version.txt
!src/pynxtools/remote_definitions_url.txt
build/
nexusparser.egg-info/PKG-INFO
.python-version
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ recursive-include src/pynxtools/definitions/applications/ *.xml
recursive-include src/pynxtools/definitions/contributed_definitions/ *.xml
include src/pynxtools/definitions/*.xsd
include src/pynxtools/nexus-version.txt
include src/pynxtools/definitions/NXDL_VERSION

include src/pynxtools/remote_definitions_url.txt
include src/pynxtools/definitions/NXDL_VERSION
7 changes: 7 additions & 0 deletions src/pynxtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ def get_nexus_version_hash() -> str:
return MAIN_BRANCH_NAME

return version.group(1)


def get_definitions_url() -> str:
"""Get the URL of the NeXus definitions that are submoduled in pynxtools."""
url_file = os.path.join(os.path.dirname(__file__), "remote_definitions_url.txt")
with open(url_file, encoding="utf-8") as file:
return file.read().strip()
54 changes: 52 additions & 2 deletions src/pynxtools/_build_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,71 @@ def _write_version_to_metadata():
file.write(version)


def get_definitions_submodule_url():
"""
The URL of the definitions submodule in pynxtools.
"""
submodule_path = "src/pynxtools/definitions"

try:
# Define the command to run
url_line = run(
[
"git",
"config",
"--file",
".git/config",
"--get-regexp",
f"^submodule\\.{submodule_path}\\.url",
],
text=True,
capture_output=True,
check=True,
).stdout.strip()

if url_line:
url = url_line.split(" ")[1]
return url
else:
return None

except (FileNotFoundError, CalledProcessError):
return None


def _write_definitions_remote_url():
"""Write the URL of the definitions remote to file."""
remote_repo_url = get_definitions_submodule_url()
if remote_repo_url is None or not remote_repo_url:
return

with open(
os.path.join(os.path.dirname(__file__), "remote_definitions_url.txt"),
"w+",
encoding="utf-8",
) as file:
file.write(remote_repo_url)


# pylint: disable=function-redefined
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
"""
PEP 517 compliant build wheel hook.
This is a wrapper for setuptools and adds a nexus version file.
This is a wrapper for setuptools and adds a nexus version file and a
file with the remote of the definitions submodule.
"""
_write_version_to_metadata()
_write_definitions_remote_url()
return _orig.build_wheel(wheel_directory, config_settings, metadata_directory)


# pylint: disable=function-redefined
def build_sdist(sdist_directory, config_settings=None):
"""
PEP 517 compliant build sdist hook.
This is a wrapper for setuptools and adds a nexus version file.
This is a wrapper for setuptools and adds a nexus version file and a
file with the remote of the definitions submodule.
"""
_write_version_to_metadata()
_write_definitions_remote_url()
return _orig.build_sdist(sdist_directory, config_settings)
27 changes: 24 additions & 3 deletions src/pynxtools/nomad/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,34 @@
import pynxtools.nomad.schema as nexus_schema
from pynxtools.nexus.nexus import HandleNexus

__REPLACEMENT_FOR_NX = "BS"
__REPLACEMENT_LEN = len(__REPLACEMENT_FOR_NX)


def _rename_nx_to_nomad(name: str) -> Optional[str]:
"""
Rename the NXDL name to NOMAD.
For example: NXdata -> BSdata,
except NXobject -> NXobject
"""
if name == "NXobject":
return name
if name is not None:
if name.startswith("NX"):
return name.replace("NX", __REPLACEMENT_FOR_NX)
return name


def _to_group_name(nx_node: ET.Element):
"""
Normalise the given group name
"""
# assuming always upper() is incorrect, e.g. NXem_msr is a specific one not EM_MSR!
return nx_node.attrib.get("name", nx_node.attrib["type"][2:].upper())
grp_nm = nx_node.attrib.get(
"name", nx_node.attrib["type"][__REPLACEMENT_LEN:].upper()
)

return grp_nm


# noinspection SpellCheckingInspection
Expand Down Expand Up @@ -203,7 +224,6 @@ def _populate_data(
target_name=attr_name,
exc_info=exc,
)

if parent_field_name in current.__dict__:
quantity = current.__dict__[parent_field_name]
if isinstance(quantity, dict):
Expand Down Expand Up @@ -328,7 +348,8 @@ def __nexus_populate(self, params: dict, attr=None): # pylint: disable=W0613

hdf_path: str = hdf_info["hdf_path"]
hdf_node = hdf_info["hdf_node"]

if nx_def is not None:
nx_def = _rename_nx_to_nomad(nx_def)
if nx_path is None:
return

Expand Down
Loading
Loading