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

Fix handling of version 2.0b #1651

Merged
merged 3 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# PyNWB Changelog

## PyNWB 2.3.1 (February 24, 2023)

### Bug fixes
- Fixed an issue where NWB files with version "2.0b" could not be read. @rly [#1651](https://github.com/NeurodataWithoutBorders/pynwb/pull/1651)

## PyNWB 2.3.0 (February 23, 2023)

### Enhancements and minor changes
Expand Down
9 changes: 9 additions & 0 deletions src/pynwb/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def get_nwb_version(builder: Builder, include_prerelease=False) -> Tuple[int, ..
If the "nwb_version" attribute on the root builder equals "2.5.1-alpha" and include_prerelease=True,
then (2, 5, 1, "alpha") is returned.

If the "nwb_version" attribute == "2.0b" (the only deviation from semantic versioning in the 2.x series), then
if include_prerelease=True, (2, 0, 0, "b") is returned; else, (2, 0, 0) is returned.

:param builder: Any builder within an NWB file.
:type builder: Builder
:param include_prerelease: Whether to include prerelease information in the returned tuple.
Expand All @@ -28,6 +31,12 @@ def get_nwb_version(builder: Builder, include_prerelease=False) -> Tuple[int, ..
nwb_version = root_builder.attributes.get("nwb_version")
if nwb_version is None:
raise ValueError("'nwb_version' attribute is missing from the root of the NWB file.")
# handle special non-semver case
if nwb_version == "2.0b":
if not include_prerelease:
return (2, 0, 0)
else:
return (2, 0, 0, "b")
nwb_version_match = re.match(r"(\d+\.\d+\.\d+)", nwb_version)[0] # trim off any non-numeric symbols at end
version_list = [int(i) for i in nwb_version_match.split(".")]
if include_prerelease:
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/utils/test_io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@ def test_get_nwb_version_prerelease_true2(self):
builder1 = GroupBuilder(name="root")
builder1.set_attribute(name="nwb_version", value="2.0.0-alpha.sha-test.5114f85")
assert get_nwb_version(builder1, include_prerelease=True) == (2, 0, 0, "alpha.sha-test.5114f85")

def test_get_nwb_version_20b(self):
"""Get the NWB version from a builder where version == "2.0b"."""
builder1 = GroupBuilder(name="root")
builder1.set_attribute(name="nwb_version", value="2.0b")
assert get_nwb_version(builder1) == (2, 0, 0)
assert get_nwb_version(builder1, include_prerelease=True) == (2, 0, 0, "b")