Skip to content

Commit 0ddafc2

Browse files
committed
get_nwbfile_version/get_nwb_version: Fix parsing pre-semver version specifiers
In commit NeurodataWithoutBorders/nwb-schema@dba02ff (update YAML specs with 2.1.0 specs, 2019-08-19) the help for nwb_version was changed in the following regard: --- a/core/nwb.file.yaml +++ b/core/nwb.file.yaml @@ -2,220 +2,231 @@ groups: [...] - name: nwb_version dtype: text - doc: 'File version string. COMMENT: Eg, NWB-1.0.0. This will be the name of the - format with trailing major, minor and patch numbers.' - value: 2.0b + value: 2.0.2 + doc: File version string. Use semantic versioning, e.g. 1.2.1. This will be the + name of the format with trailing major, minor and patch numbers. While adopting semantic versioning for nwb_version is a good step, care needs to be taken to allow reading older files. Versions of IPNWB prior to AllenInstitute/IPNWB@70c65d4 (Switch to newer NWB specification 2.2.4, 2020-04-15) did follow the old suggestion in prefixing nwb_version with `NWB-`. Let's disregard that prefix as was previsously done with the suffix 'b' in 26538b3 (Fix handling of version 2.0b (#1651), 2023-02-24).
1 parent 43cfa7b commit 0ddafc2

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/pynwb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def get_nwbfile_version(**kwargs):
297297
nwb_version_string = nwb_version_string.decode()
298298

299299
# Parse the version string
300-
nwb_version_parts = nwb_version_string.replace("-", ".").replace("_", ".").split(".")
300+
nwb_version_parts = nwb_version_string.replace("NWB-", "").replace("-", ".").replace("_", ".").split(".")
301301
nwb_version = tuple([int(i) if i.isnumeric() else i
302302
for i in nwb_version_parts])
303303
return nwb_version_string, nwb_version

src/pynwb/io/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def get_nwb_version(builder: Builder, include_prerelease=False) -> Tuple[int, ..
3737
return (2, 0, 0)
3838
else:
3939
return (2, 0, 0, "b")
40+
41+
nwb_version = nwb_version.removeprefix("NWB-")
4042
nwb_version_match = re.match(r"(\d+\.\d+\.\d+)", nwb_version)[0] # trim off any non-numeric symbols at end
4143
version_list = [int(i) for i in nwb_version_match.split(".")]
4244
if include_prerelease:

tests/integration/utils/test_io_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ def test_get_nwb_version_20b(self):
5757
assert get_nwb_version(builder1) == (2, 0, 0)
5858
assert get_nwb_version(builder1, include_prerelease=True) == (2, 0, 0, "b")
5959

60+
def test_get_nwb_version_NWB_prefix(self):
61+
"""Get the NWB version from a builder where version == "NWB-2.1.3"."""
62+
builder1 = GroupBuilder(name="root")
63+
builder1.set_attribute(name="nwb_version", value="NWB-2.1.3")
64+
assert get_nwb_version(builder1) == (2, 1, 3)
65+
assert get_nwb_version(builder1, include_prerelease=True) == (2, 1, 3, "")
66+
6067
class TestGetNWBBackend(TestCase):
6168
def setUp(self):
6269
self.nwbfile = NWBFile(session_description='a test NWB File',

0 commit comments

Comments
 (0)