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

Generalize Validation #1511

Merged
merged 48 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
88eb7ac
branch from dev
CodyCBakerPhD Jul 18, 2022
8f094e5
Merge branch 'dev' into generalize_validate_from_dev
CodyCBakerPhD Sep 1, 2022
c7c892e
major work
CodyCBakerPhD Sep 1, 2022
c783345
Merge branch 'dev' into generalize_validate_from_dev
CodyCBakerPhD Sep 1, 2022
6246598
fix flake8 at least
CodyCBakerPhD Sep 1, 2022
8b233ab
fix flake8 at least
CodyCBakerPhD Sep 1, 2022
1fc72c1
update changelog
CodyCBakerPhD Sep 1, 2022
200b871
try moving order
CodyCBakerPhD Sep 1, 2022
ebbb0c8
restore validate for -m cli
CodyCBakerPhD Sep 1, 2022
cac3836
fixed
CodyCBakerPhD Sep 2, 2022
7e55ba9
removed comments
CodyCBakerPhD Sep 2, 2022
8bf4a3b
adjust CLI flag
CodyCBakerPhD Sep 2, 2022
fb5c674
debugs
CodyCBakerPhD Sep 2, 2022
e96c1a6
Merge branch 'dev' into generalize_validate_from_dev
CodyCBakerPhD Sep 2, 2022
d6f029f
fix flake8
CodyCBakerPhD Sep 2, 2022
fd38a00
Merge branch 'generalize_validate_from_dev' of https://github.com/neu…
CodyCBakerPhD Sep 2, 2022
d949296
fix import structure for tox
CodyCBakerPhD Sep 2, 2022
f403525
Fix tests
rly Sep 14, 2022
ccf2282
Undo changelog change
rly Sep 14, 2022
e82ac2c
Fix tests
rly Sep 15, 2022
8872394
Merge branch 'dev' into generalize_validate_from_dev
CodyCBakerPhD Sep 20, 2022
be4c65e
small debug
CodyCBakerPhD Sep 20, 2022
881e44d
Add test to validate against file with extension
rly Sep 20, 2022
6efe21f
Add test file
rly Sep 20, 2022
ce89646
Fix test read
rly Sep 20, 2022
71d60e4
Fix conda CircleCI issue
rly Sep 20, 2022
d19d951
Fix flake8
rly Sep 20, 2022
c182794
Fix conda
rly Sep 20, 2022
9a5a3d8
Merge branch 'dev' into generalize_validate_from_dev
CodyCBakerPhD Sep 21, 2022
626b5d3
revert to previous init structure for core
CodyCBakerPhD Sep 21, 2022
90783d7
remaining debug
CodyCBakerPhD Sep 21, 2022
ab9b789
correct tests
CodyCBakerPhD Sep 21, 2022
dd6d7d9
Merge branch 'dev' into generalize_validate_from_dev
rly Sep 27, 2022
b5529ab
debugging miniconda37 error
rly Sep 27, 2022
af07474
Merge branch 'dev' into generalize_validate_from_dev
rly Sep 27, 2022
a8e4575
Restore config.yml
rly Sep 27, 2022
0dc6827
Merge branch 'dev' into generalize_validate_from_dev
rly Oct 11, 2022
00c9c59
Merge branch 'dev' into generalize_validate_from_dev
rly Oct 11, 2022
4e90651
Update CHANGELOG.md
rly Oct 14, 2022
765312a
Cleanup, prep for invalid file test
rly Oct 18, 2022
2334dfd
Try again to make test file
rly Oct 18, 2022
6164a78
Try again
rly Oct 18, 2022
a884905
Fix
rly Oct 18, 2022
6ec27be
Fix, cleanup
rly Oct 18, 2022
5108f2c
Fix error with --list-namespaces
rly Oct 18, 2022
78b0638
Add test, retcode=1 should print error msg
rly Oct 18, 2022
effd64e
Fix
rly Oct 18, 2022
06ca152
Clean up comments
rly Oct 19, 2022
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 .github/workflows/generate_test_files.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Generate test files
on:
workflow_dispatch:
# pull_request:

jobs:
gen-test-files:
Expand Down
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# PyNWB Changelog

## PyNWB 2.2.0 (October 11, 2022)
## PyNWB 2.2.0 (October 19, 2022)

### Internal enhancements:
### Enhancements and minor changes
- Enhanced `pynwb.validate` API function to accept a list of file paths as well as the ability to operate on cached
namespaces. Also adjusted the validate CLI to directly use the API function. @CodyCBakerPhD
[#1511](https://github.com/NeurodataWithoutBorders/pynwb/pull/1511)

### Internal enhancements
- Moved CI to GitHub Actions. @rly [#1560](https://github.com/NeurodataWithoutBorders/pynwb/pull/1560),
[#1566](https://github.com/NeurodataWithoutBorders/pynwb/pull/1566)

Expand Down
15 changes: 1 addition & 14 deletions src/pynwb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
from hdmf.utils import docval, getargs, popargs, get_docval
from hdmf.backends.io import HDMFIO
from hdmf.backends.hdf5 import HDF5IO as _HDF5IO
from hdmf.validate import ValidatorMap
from hdmf.build import BuildManager, TypeMap
import hdmf.common


CORE_NAMESPACE = 'core'
__core_ns_file_name = 'nwb.namespace.yaml'

from .spec import NWBDatasetSpec, NWBGroupSpec, NWBNamespace # noqa E402
from .validate import validate # noqa: F401, E402


def __get_resources():
Expand Down Expand Up @@ -186,18 +185,6 @@ def get_sum(self, a, b):
return __TYPE_MAP.get_dt_container_cls(neurodata_type, namespace)


@docval({'name': 'io', 'type': HDMFIO, 'doc': 'the HDMFIO object to read from'},
{'name': 'namespace', 'type': str, 'doc': 'the namespace to validate against', 'default': CORE_NAMESPACE},
returns="errors in the file", rtype=list,
is_method=False)
def validate(**kwargs):
"""Validate an NWB file against a namespace"""
io, namespace = getargs('io', 'namespace', kwargs)
builder = io.read_builder()
validator = ValidatorMap(io.manager.namespace_catalog.get_namespace(name=namespace))
return validator.validate(builder)


class NWBHDF5IO(_HDF5IO):

@docval({'name': 'path', 'type': (str, Path), 'doc': 'the path to the HDF5 file', 'default': None},
Expand Down
57 changes: 54 additions & 3 deletions src/pynwb/testing/make_test_files.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from datetime import datetime
import numpy as np
from pathlib import Path

from datetime import datetime
from pynwb import NWBFile, NWBHDF5IO, __version__, TimeSeries
from pynwb import NWBFile, NWBHDF5IO, __version__, TimeSeries, get_class, load_namespaces
from pynwb.image import ImageSeries
from pynwb.spec import NWBNamespaceBuilder, export_spec, NWBGroupSpec, NWBAttributeSpec


# pynwb 1.0.2 should be installed with hdmf 1.0.3
# pynwb 1.0.3 should be installed with hdmf 1.0.5
Expand Down Expand Up @@ -149,12 +150,61 @@ def _make_imageseries_nonmatch_starting_frame():
_write(test_name, nwbfile)


def _make_empty_with_extension():
ns_builder = NWBNamespaceBuilder(
doc="An NWB test extension",
name="ndx-testextension",
version="0.1.0",
author="PyNWB Test File Generator",
contact="[email protected]",
)

ns_builder.include_type('TimeSeries', namespace='core')
tetrode_series = NWBGroupSpec(
neurodata_type_def='TimeSeriesWithID',
neurodata_type_inc='TimeSeries',
doc=('An extension of TimeSeries to include an ID.'),
attributes=[
NWBAttributeSpec(
name='id',
doc='The time series ID.',
dtype='int32'
),
],
)

new_data_types = [tetrode_series]

# export the spec to yaml files in the current directory
export_spec(ns_builder, new_data_types, output_dir=".")

nwbfile = NWBFile(session_description='ADDME',
identifier='ADDME',
session_start_time=datetime.now().astimezone())

load_namespaces("ndx-testextension.namespace.yaml") # load from the current directory
TimeSeriesWithID = get_class("TimeSeriesWithID", "ndx-testextension")
ts = TimeSeriesWithID(
name="test_ts",
data=[1., 2., 3.],
description="ADDME",
unit="ADDME",
rate=1.,
id=1,
)
nwbfile.add_acquisition(ts)
test_name = 'nwbfile_with_extension'
_write(test_name, nwbfile)


if __name__ == '__main__':
# install these versions of PyNWB and run this script to generate new files
# python src/pynwb/testing/make_test_files.py
# files will be made in src/pynwb/testing/
# files should be moved to tests/back_compat/

# NOTE: this script is run in the GitHub Actions workflow generate_test_files.yml

if __version__ == '1.1.2':
_make_empty()
_make_str_experimenter()
Expand All @@ -170,3 +220,4 @@ def _make_imageseries_nonmatch_starting_frame():
_make_imageseries_no_data()
_make_imageseries_non_external_format()
_make_imageseries_nonmatch_starting_frame()
_make_empty_with_extension()
Loading