From d55901cfb3712fc0e93c5c140f981be6f5e83329 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Fri, 6 Sep 2024 09:35:51 -0700 Subject: [PATCH 1/5] filter out warnings when getting namespaces in test.py --- test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test.py b/test.py index 5bddb7c7d..3b8ead274 100644 --- a/test.py +++ b/test.py @@ -179,7 +179,9 @@ def get_namespaces(nwbfile): if comp.returncode != 0: return [] - return comp.stdout.split() + output_lines = comp.stdout.split('\n') + filtered_output = [line for line in output_lines if not re.search(r'warning', line, re.IGNORECASE) and line != ''] + return filtered_output namespaces = get_namespaces(nwb) From 89ca8d536c7f6b1ba7b6f54a230c44fa099cf6bb Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:14:31 -0700 Subject: [PATCH 2/5] make get_cached_namespaces function public --- src/pynwb/validate.py | 10 +++++----- tests/integration/ros3/test_ros3.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pynwb/validate.py b/src/pynwb/validate.py index aecfb2556..5eeed352d 100644 --- a/src/pynwb/validate.py +++ b/src/pynwb/validate.py @@ -29,7 +29,7 @@ def _validate_helper(io: HDMFIO, namespace: str = CORE_NAMESPACE) -> list: return validator.validate(builder) -def _get_cached_namespaces_to_validate( +def get_cached_namespaces_to_validate( path: str, driver: Optional[str] = None, aws_region: Optional[str] = None, ) -> Tuple[List[str], BuildManager, Dict[str, str]]: """ @@ -40,9 +40,9 @@ def _get_cached_namespaces_to_validate( The following example illustrates how we can use this function to validate against namespaces cached in a file. This is useful, e.g., when a file was created using an extension >>> from pynwb import validate - >>> from pynwb.validate import _get_cached_namespaces_to_validate + >>> from pynwb.validate import get_cached_namespaces_to_validate >>> path = "my_nwb_file.nwb" - >>> validate_namespaces, manager, cached_namespaces = _get_cached_namespaces_to_validate(path) + >>> validate_namespaces, manager, cached_namespaces = get_cached_namespaces_to_validate(path) >>> with NWBHDF5IO(path, "r", manager=manager) as reader: >>> errors = [] >>> for ns in validate_namespaces: @@ -149,7 +149,7 @@ def validate(**kwargs): io_kwargs = dict(path=path, mode="r", driver=driver) if use_cached_namespaces: - cached_namespaces, manager, namespace_dependencies = _get_cached_namespaces_to_validate( + cached_namespaces, manager, namespace_dependencies = get_cached_namespaces_to_validate( path=path, driver=driver ) io_kwargs.update(manager=manager) @@ -231,7 +231,7 @@ def validate_cli(): if args.list_namespaces: for path in args.paths: - cached_namespaces, _, _ = _get_cached_namespaces_to_validate(path=path) + cached_namespaces, _, _ = get_cached_namespaces_to_validate(path=path) print("\n".join(cached_namespaces)) else: validation_errors, validation_status = validate( diff --git a/tests/integration/ros3/test_ros3.py b/tests/integration/ros3/test_ros3.py index 95a891760..2571e6199 100644 --- a/tests/integration/ros3/test_ros3.py +++ b/tests/integration/ros3/test_ros3.py @@ -1,6 +1,6 @@ from pynwb import NWBHDF5IO from pynwb import validate -from pynwb.validate import _get_cached_namespaces_to_validate +from pynwb.validate import get_cached_namespaces_to_validate from pynwb.testing import TestCase import urllib.request import h5py @@ -85,7 +85,7 @@ def test_dandi_get_cached_namespaces(self): ) } } - found_namespaces, _, found_namespace_dependencies = _get_cached_namespaces_to_validate( + found_namespaces, _, found_namespace_dependencies = get_cached_namespaces_to_validate( path=self.s3_test_path, driver="ros3" ) From cf8d129e67acdb7329b92a11c85e4c815bf3ca4a Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:15:06 -0700 Subject: [PATCH 3/5] replace get_namespaces function --- test.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/test.py b/test.py index 3b8ead274..0d9e25990 100644 --- a/test.py +++ b/test.py @@ -153,6 +153,7 @@ def validate_nwbs(): examples_nwbs = glob.glob('*.nwb') import pynwb + from pynwb.validate import get_cached_namespaces_to_validate for nwb in examples_nwbs: try: @@ -171,19 +172,7 @@ def validate_nwbs(): for err in errors: print("Error: %s" % err) - def get_namespaces(nwbfile): - comp = run(["python", "-m", "pynwb.validate", - "--list-namespaces", nwbfile], - stdout=PIPE, stderr=STDOUT, universal_newlines=True, timeout=30) - - if comp.returncode != 0: - return [] - - output_lines = comp.stdout.split('\n') - filtered_output = [line for line in output_lines if not re.search(r'warning', line, re.IGNORECASE) and line != ''] - return filtered_output - - namespaces = get_namespaces(nwb) + namespaces, _, _ = get_cached_namespaces_to_validate(nwb) if len(namespaces) == 0: FAILURES += 1 From 4365cff654222de0ff20cbadb2ec1e96d9f6faa0 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:35:57 -0700 Subject: [PATCH 4/5] update code block in docstring --- src/pynwb/validate.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/pynwb/validate.py b/src/pynwb/validate.py index 5eeed352d..880f860a6 100644 --- a/src/pynwb/validate.py +++ b/src/pynwb/validate.py @@ -39,14 +39,18 @@ def get_cached_namespaces_to_validate( ------- The following example illustrates how we can use this function to validate against namespaces cached in a file. This is useful, e.g., when a file was created using an extension - >>> from pynwb import validate - >>> from pynwb.validate import get_cached_namespaces_to_validate - >>> path = "my_nwb_file.nwb" - >>> validate_namespaces, manager, cached_namespaces = get_cached_namespaces_to_validate(path) - >>> with NWBHDF5IO(path, "r", manager=manager) as reader: - >>> errors = [] - >>> for ns in validate_namespaces: - >>> errors += validate(io=reader, namespace=ns) + + .. code-block:: python + + from pynwb import validate + from pynwb.validate import get_cached_namespaces_to_validate + path = "my_nwb_file.nwb" + validate_namespaces, manager, cached_namespaces = get_cached_namespaces_to_validate(path) + with NWBHDF5IO(path, "r", manager=manager) as reader: + errors = [] + for ns in validate_namespaces: + errors += validate(io=reader, namespace=ns) + :param path: Path for the NWB file :return: Tuple with: - List of strings with the most specific namespace(s) to use for validation. From 7a7798d901dba4a70faae81618da733f4d0ab7ac Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:42:33 -0700 Subject: [PATCH 5/5] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c465adec..62dcfe688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Enhancements and minor changes - Added support for numpy 2.0. @mavaylon1 [#1956](https://github.com/NeurodataWithoutBorders/pynwb/pull/1956) +- Make `get_cached_namespaces_to_validate` a public function @stephprince [#1961](https://github.com/NeurodataWithoutBorders/pynwb/pull/1961) ### Documentation and tutorial enhancements - Added pre-release pull request instructions to release process documentation @stephprince [#1928](https://github.com/NeurodataWithoutBorders/pynwb/pull/1928)