Skip to content

Commit 26538b3

Browse files
authored
Fix handling of version 2.0b (#1651)
1 parent 1dc9125 commit 26538b3

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# PyNWB Changelog
22

3+
## PyNWB 2.3.1 (February 24, 2023)
4+
5+
### Bug fixes
6+
- Fixed an issue where NWB files with version "2.0b" could not be read. @rly [#1651](https://github.com/NeurodataWithoutBorders/pynwb/pull/1651)
7+
38
## PyNWB 2.3.0 (February 23, 2023)
49

510
### Enhancements and minor changes

src/pynwb/io/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def get_nwb_version(builder: Builder, include_prerelease=False) -> Tuple[int, ..
1313
If the "nwb_version" attribute on the root builder equals "2.5.1-alpha" and include_prerelease=True,
1414
then (2, 5, 1, "alpha") is returned.
1515
16+
If the "nwb_version" attribute == "2.0b" (the only deviation from semantic versioning in the 2.x series), then
17+
if include_prerelease=True, (2, 0, 0, "b") is returned; else, (2, 0, 0) is returned.
18+
1619
:param builder: Any builder within an NWB file.
1720
:type builder: Builder
1821
:param include_prerelease: Whether to include prerelease information in the returned tuple.
@@ -28,6 +31,12 @@ def get_nwb_version(builder: Builder, include_prerelease=False) -> Tuple[int, ..
2831
nwb_version = root_builder.attributes.get("nwb_version")
2932
if nwb_version is None:
3033
raise ValueError("'nwb_version' attribute is missing from the root of the NWB file.")
34+
# handle special non-semver case
35+
if nwb_version == "2.0b":
36+
if not include_prerelease:
37+
return (2, 0, 0)
38+
else:
39+
return (2, 0, 0, "b")
3140
nwb_version_match = re.match(r"(\d+\.\d+\.\d+)", nwb_version)[0] # trim off any non-numeric symbols at end
3241
version_list = [int(i) for i in nwb_version_match.split(".")]
3342
if include_prerelease:

tests/integration/utils/test_io_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ def test_get_nwb_version_prerelease_true2(self):
4646
builder1 = GroupBuilder(name="root")
4747
builder1.set_attribute(name="nwb_version", value="2.0.0-alpha.sha-test.5114f85")
4848
assert get_nwb_version(builder1, include_prerelease=True) == (2, 0, 0, "alpha.sha-test.5114f85")
49+
50+
def test_get_nwb_version_20b(self):
51+
"""Get the NWB version from a builder where version == "2.0b"."""
52+
builder1 = GroupBuilder(name="root")
53+
builder1.set_attribute(name="nwb_version", value="2.0b")
54+
assert get_nwb_version(builder1) == (2, 0, 0)
55+
assert get_nwb_version(builder1, include_prerelease=True) == (2, 0, 0, "b")

0 commit comments

Comments
 (0)