Skip to content

Commit

Permalink
Fix handling of version 2.0b (#1651)
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored Feb 25, 2023
1 parent 1dc9125 commit 26538b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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")

0 comments on commit 26538b3

Please sign in to comment.