Skip to content

Commit

Permalink
replace distutils with packaging for version comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
dmeliza committed Jan 13, 2024
1 parent d74fb86 commit cce5fa0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
12 changes: 6 additions & 6 deletions arf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def open_file(name, mode=None, driver=None, libver=None, userblock_size=None, **
"""
import os
import sys
from distutils.version import StrictVersion
from packaging.version import Version

from h5py import File, h5p

Expand All @@ -77,19 +77,19 @@ def open_file(name, mode=None, driver=None, libver=None, userblock_size=None, **
fp = File(name, mode=mode, driver=driver, libver=libver, **kwargs)
else:
posargs = []
if StrictVersion(h5py_version) >= StrictVersion("2.9"):
if Version(h5py_version) >= Version("2.9"):
posargs += ["rdcc_nslots", "rdcc_nbytes", "rdcc_w0"]
if StrictVersion(h5py_version) >= StrictVersion("3.5"):
if Version(h5py_version) >= Version("3.5"):
posargs += ["locking", "page_buf_size", "min_meta_keep", "min_raw_keep"]
if StrictVersion(h5py_version) >= StrictVersion("3.7"):
if Version(h5py_version) >= Version("3.7"):
# integer is needed
kwargs.update(
{
arg: kwargs.get(arg, 1)
for arg in ["alignment_threshold", "alignment_interval"]
}
)
if StrictVersion(h5py_version) >= StrictVersion("3.8"):
if Version(h5py_version) >= Version("3.8"):
posargs += ["meta_block_size"]
kwargs.update({arg: kwargs.get(arg, None) for arg in posargs})
fapl = _files.make_fapl(driver, libver, **kwargs)
Expand Down Expand Up @@ -279,7 +279,7 @@ def check_file_version(file):
Returns the version for the file
"""
from distutils.version import StrictVersion as Version
from packaging.version import Version

try:
ver = file.attrs.get("arf_version", None)
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ setup_requires =
install_requires =
numpy<2
h5py>=2.8,!=3.3.*
packaging >= 23.0
test_suite = tests

[options.extras_require]
test =
pytest >= 7.0
10 changes: 5 additions & 5 deletions tests/test_arf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import time
import unittest
from distutils import version
from packaging import version

import numpy as nx
from h5py.version import version as h5py_version
Expand Down Expand Up @@ -30,7 +30,7 @@
),
dict(
name="neural",
data=(randn(100000) * 2 ** 16).astype("h"),
data=(randn(100000) * 2**16).astype("h"),
sampling_rate=20000,
datatype=arf.DataTypes.EXTRAC_HP,
compression=9,
Expand Down Expand Up @@ -117,7 +117,7 @@ def test00_create_entries(self):
N = 5
for i in range(N):
yield self.create_entry, entry_base % i
self.assertEqual(len(self.fp), N)
assert len(self.fp) == N

def test01_create_existing_entry(self):
with self.assertRaises(ValueError):
Expand All @@ -135,7 +135,7 @@ def test04_create_bad_dataset(self):
self.create_dataset(self.entry, dset)

def test05_set_attributes(self):
""" tests the set_attributes convenience function """
"""tests the set_attributes convenience function"""
arf.set_attributes(self.entry, mystr="myvalue", myint=5000)
self.assertEqual(self.entry.attrs["myint"], 5000)
self.assertEqual(self.entry.attrs["mystr"], "myvalue")
Expand Down Expand Up @@ -170,7 +170,7 @@ def test09_append_to_table(self):


@unittest.skipIf(
version.StrictVersion(h5py_version) < version.StrictVersion("2.2"),
version.Version(h5py_version) < version.Version("2.2"),
"not supported on h5py < 2.2",
)
class TestArfNavigation(unittest.TestCase):
Expand Down

0 comments on commit cce5fa0

Please sign in to comment.