Skip to content

Commit 5276fb6

Browse files
authored
Remove option to validate against ns file, update docs (#1397)
1 parent 0ce7582 commit 5276fb6

File tree

3 files changed

+51
-44
lines changed

3 files changed

+51
-44
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
be provided in place of ``data``. ``OpticalSeries.__init__`` now makes ``data`` optional. However, this has the
5656
side effect of moving the position of ``data`` to later in the argument list, which may break code that relies
5757
on positional arguments for ``OpticalSeries.__init__``. @rly (#1274)
58-
- Fixed `setup.py` not being able to import `versioneer` when installing in an embedded Python environment. @ikhramts (#1395)
58+
- Fixed `setup.py` not being able to import `versioneer` when installing in an embedded Python environment. @ikhramts
59+
(#1395)
60+
- Removed broken option to validate against a given namespace file and updated associated documentation. @rly (#1397)
5961

6062
## PyNWB 1.5.1 (May 24, 2021)
6163

docs/source/validation.rst

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,47 @@
33
Validating NWB files
44
====================
55

6-
Validating NWB files is handled by a command-line tool available in :py:mod:`~pynwb`. The validator can be invoked like so:
6+
Validating NWB files is handled by a command-line tool available in :py:mod:`~pynwb`.
7+
The validator can be invoked like so:
78

89
.. code-block:: bash
910
1011
python -m pynwb.validate test.nwb
1112
12-
This will validate the file ``test.nwb`` against the *core* NWB specification. In case of success the output looks like
13+
If the file contains no NWB extensions, then this command will validate the file ``test.nwb`` against the
14+
*core* NWB specification. On success, the output will is:
1315

1416
.. code-block:: text
1517
16-
Validating test.nwb against cached namespace information using namespace core.
18+
Validating test.nwb against cached namespace information using namespace 'core'.
1719
- no errors found.
1820
19-
and the program exit code is ``0``. On error the program exit code is ``1`` and
20-
the list of errors is outputted.
21+
and the program exit code is ``0``. On error, the program exit code is ``1`` and the list of errors is outputted.
2122

22-
If possible the file is validated against the cached namespace specification
23-
read from the file itself. This can be tweaked with the command line options given below.
23+
If the file contains NWB extensions, then the above validation command will validate the file ``test.nwb`` against
24+
all extensions in the file and the core NWB specification.
2425

25-
CURRENTLY BROKEN!!!
26+
To validate against only one NWB extension that is cached within the file, use the ``-n`` flag.
27+
For example, the following command will validate against the "ndx-my-extension" namespace that is cached
28+
within the ``test.nwb`` file.
2629

27-
Validating against other specifications i.e. extensions
28-
can be done using the ``-p`` and ``-n`` flags. For example, the following command will validate against the specifications referenced in the namespace
29-
file ``mylab.namespace.yaml`` in addition to the core specification.
30+
.. code-block:: bash
31+
32+
python -m pynwb.validate -n ndx-my-extension test.nwb
33+
34+
To validate against the version of the **core** NWB specification that is included with the installed version of
35+
PyNWB, use the ``--no-cached-namespace`` flag. This can be useful in validating files against newer or older versions
36+
of the **core** NWB specification that are installed with newer or older versions of PyNWB.
3037

3138
.. code-block:: bash
3239
33-
python -m pynwb.validate -p mylab.namespace.yaml test.nwb
40+
python -m pynwb.validate --no-cached-namespace test.nwb
3441
35-
.. Last updated 2/2020
42+
.. Last updated 8/13/2021
3643
.. code-block:: text
3744
3845
$python -m pynwb.validate --help
39-
usage: validate.py [-h] [-p NSPATH] [-n NS] [-lns]
40-
[--cached-namespace | --no-cached-namespace]
41-
paths [paths ...]
46+
usage: validate.py [-h] [-n NS] [-lns] [--cached-namespace | --no-cached-namespace] paths [paths ...]
4247
4348
Validate an NWB file
4449
@@ -47,14 +52,14 @@ file ``mylab.namespace.yaml`` in addition to the core specification.
4752
4853
optional arguments:
4954
-h, --help show this help message and exit
50-
-p NSPATH, --nspath NSPATH
51-
the path to the namespace YAML file
5255
-n NS, --ns NS the namespace to validate against
5356
-lns, --list-namespaces
5457
List the available namespaces and exit.
5558
--cached-namespace Use the cached namespace (default).
5659
--no-cached-namespace
5760
Don't use the cached namespace.
5861
59-
use --nspath to validate against an extension. If --ns is not specified,
60-
validate against all namespaces in namespace file.
62+
If --ns is not specified, validate against all namespaces in the NWB file.
63+
64+
Validation against a namespace that is not cached within the schema is not currently possible but is a planned
65+
feature.

src/pynwb/validate.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ def _validate_helper(**kwargs):
2929
def main(): # noqa: C901
3030

3131
ep = """
32-
use --nspath to validate against an extension. If --ns is not specified,
33-
validate against all namespaces in namespace file.
32+
If --ns is not specified, validate against all namespaces in the NWB file.
3433
"""
3534

3635
parser = ArgumentParser(description="Validate an NWB file", epilog=ep)
3736
parser.add_argument("paths", type=str, nargs='+', help="NWB file paths")
38-
parser.add_argument('-p', '--nspath', type=str, help="the path to the namespace YAML file")
37+
# parser.add_argument('-p', '--nspath', type=str, help="the path to the namespace YAML file")
3938
parser.add_argument("-n", "--ns", type=str, help="the namespace to validate against")
4039
parser.add_argument("-lns", "--list-namespaces", dest="list_namespaces",
4140
action='store_true', help="List the available namespaces and exit.")
@@ -50,15 +49,16 @@ def main(): # noqa: C901
5049
args = parser.parse_args()
5150
ret = 0
5251

53-
if args.nspath:
54-
if not os.path.isfile(args.nspath):
55-
print("The namespace file {} is not a valid file.".format(args.nspath), file=sys.stderr)
56-
sys.exit(1)
57-
58-
if args.cached_namespace:
59-
print("Turning off validation against cached namespace information "
60-
"as --nspath was passed.", file=sys.stderr)
61-
args.cached_namespace = False
52+
# TODO Validation against a specific namespace file is currently broken. See pynwb#1396
53+
# if args.nspath:
54+
# if not os.path.isfile(args.nspath):
55+
# print("The namespace file {} is not a valid file.".format(args.nspath), file=sys.stderr)
56+
# sys.exit(1)
57+
#
58+
# if args.cached_namespace:
59+
# print("Turning off validation against cached namespace information "
60+
# "as --nspath was passed.", file=sys.stderr)
61+
# args.cached_namespace = False
6262

6363
for path in args.paths:
6464

@@ -87,17 +87,17 @@ def main(): # noqa: C901
8787
specloc = "pynwb namespace information"
8888
print("The file {} has no cached namespace information. "
8989
"Falling back to {}.".format(path, specloc), file=sys.stderr)
90-
elif args.nspath:
91-
catalog = NamespaceCatalog(NWBGroupSpec, NWBDatasetSpec, NWBNamespace)
92-
namespaces = catalog.load_namespaces(args.nspath)
93-
94-
if len(namespaces) == 0:
95-
print("Could not load namespaces from file {}.".format(args.nspath), file=sys.stderr)
96-
sys.exit(1)
97-
98-
tm = TypeMap(catalog)
99-
manager = BuildManager(tm)
100-
specloc = "--nspath namespace information"
90+
# elif args.nspath:
91+
# catalog = NamespaceCatalog(NWBGroupSpec, NWBDatasetSpec, NWBNamespace)
92+
# namespaces = catalog.load_namespaces(args.nspath)
93+
#
94+
# if len(namespaces) == 0:
95+
# print("Could not load namespaces from file {}.".format(args.nspath), file=sys.stderr)
96+
# sys.exit(1)
97+
#
98+
# tm = TypeMap(catalog)
99+
# manager = BuildManager(tm)
100+
# specloc = "--nspath namespace information"
101101
else:
102102
manager = None
103103
namespaces = [CORE_NAMESPACE]

0 commit comments

Comments
 (0)