Skip to content

Commit 8a247fb

Browse files
jswhit2jswhit2
authored andcommitted
catch InvalidVersion caused by "-development" in netcdf-c lib version
1 parent 08cd4c1 commit 8a247fb

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎test/test_diskless.py‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
import unittest, os, tempfile
2-
from packaging.version import Version
2+
from packaging.version import Version, InvalidVersion
33
import numpy as np
44
from numpy.random.mtrand import uniform
55
from numpy.testing import assert_array_equal, assert_array_almost_equal
66
import netCDF4
7+
import re
8+
9+
def _parse_clean_version(version_str: str) -> Version:
10+
# Normalize "-development" or any variation like "-dev" to ".dev0"
11+
cleaned = re.sub(r'[-_.]?development', '.dev0', version_str, flags=re.IGNORECASE)
12+
# Catch cases where it's just raw text hyphens (e.g., 1.0.0-dev -> 1.0.0.dev0)
13+
cleaned = re.sub(r'-dev(\d*)', r'.dev\1', cleaned, flags=re.IGNORECASE)
14+
try:
15+
return Version(cleaned)
16+
except InvalidVersion:
17+
# Fallback regex to pull just the numerical digits if it's still breaking
18+
match = re.search(r'(\d+(\.\d+)+)', version_str)
19+
if match:
20+
return Version(match.group(1))
21+
raise
722

823
# rudimentary test of diskless file capability.
924

@@ -18,7 +33,7 @@
1833

1934

2035
@unittest.skipIf(
21-
Version(netCDF4.__netcdf4libversion__) < Version('4.2.1')
36+
_parse_clean_version(netCDF4.__netcdf4libversion__) < Version('4.2.1')
2237
or netCDF4.__has_parallel4_support__
2338
or netCDF4.__has_pnetcdf_support__,
2439
"no diskless support",

0 commit comments

Comments
 (0)