|
1 | 1 | import unittest |
2 | 2 | import os |
3 | 3 | import tempfile |
4 | | -from packaging.version import Version |
| 4 | +import re |
| 5 | +from packaging.version import Version, InvalidVersion |
5 | 6 |
|
6 | 7 | import numpy as np |
7 | 8 | from numpy import ma |
8 | 9 | from numpy.testing import assert_array_equal |
9 | 10 | from netCDF4 import Dataset, __netcdf4libversion__ |
10 | 11 |
|
| 12 | +def _parse_clean_version(version_str: str) -> Version: |
| 13 | + # Normalize "-development" or any variation like "-dev" to ".dev0" |
| 14 | + cleaned = re.sub(r'[-_.]?development', '.dev0', version_str, flags=re.IGNORECASE) |
| 15 | + # Catch cases where it's just raw text hyphens (e.g., 1.0.0-dev -> 1.0.0.dev0) |
| 16 | + cleaned = re.sub(r'-dev(\d*)', r'.dev\1', cleaned, flags=re.IGNORECASE) |
| 17 | + try: |
| 18 | + return Version(cleaned) |
| 19 | + except InvalidVersion: |
| 20 | + # Fallback regex to pull just the numerical digits if it's still breaking |
| 21 | + match = re.search(r'(\d+(\.\d+)+)', version_str) |
| 22 | + if match: |
| 23 | + return Version(match.group(1)) |
| 24 | + raise |
| 25 | + |
11 | 26 | # Test use of vector of missing values. |
12 | 27 |
|
13 | 28 | class VectorMissingValues(unittest.TestCase): |
@@ -56,7 +71,7 @@ def test_scaled(self): |
56 | 71 | # issue 730 |
57 | 72 | # this part fails with netcdf 4.1.3 |
58 | 73 | # a bug in vlen strings? |
59 | | - if Version(__netcdf4libversion__) >= Version('4.4.0'): |
| 74 | + if _parse_clean_version(__netcdf4libversion__) >= Version('4.4.0'): |
60 | 75 | assert v2[0] == 'first' |
61 | 76 | assert v2[1] == '<missing>' |
62 | 77 |
|
|
0 commit comments