frejanordsiek / hdf5storage

Python package to read and write a wide range of Python types to/from HDF5 formatted files. Can read/write data to the HDF5 based Matlab v7.3 MAT files.
BSD 2-Clause "Simplified" License
83 stars 24 forks source link

PY312: Remove distutils dependency, possibly require setuptools as runtime dependency #130

Open effigies opened 8 months ago

effigies commented 8 months ago

As of Python 3.12, there is no distutils, and setuptools is not installed by default. This leads to two problems:

  Traceback:
  .tox/py312/lib/python3.12/site-packages/hdf5storage/utilities.py:44: in <module>
      from pkg_resources import parse_version
  E   ModuleNotFoundError: No module named 'pkg_resources'

  During handling of the above exception, another exception occurred:
  /opt/hostedtoolcache/Python/3.12.2/x64/lib/python3.12/importlib/__init__.py:90: in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
  tests/test_data_loader.py:6: in <module>
      from pydfc.data_loader import nifti2timeseries
  pydfc/data_loader.py:10: in <module>
      import hdf5storage
  .tox/py312/lib/python3.12/site-packages/hdf5storage/__init__.py:45: in <module>
      from . import lowlevel
  .tox/py312/lib/python3.12/site-packages/hdf5storage/lowlevel.py:35: in <module>
      from hdf5storage.utilities import *
  .tox/py312/lib/python3.12/site-packages/hdf5storage/utilities.py:46: in <module>
      from distutils.version import StrictVersion as parse_version\
  E   ModuleNotFoundError: No module named 'distutils'

I would switch from distutils.version.StrictVersion to packaging.version.Version (requiring packaging as a runtime dependency). pkg_resources.parse_version can probably also be replaced with packaging.version.

frejanordsiek commented 8 months ago

Yes, that is definitely an issue. I will put in something that still works and will continue to work for a while while still falling back to the current options if not available. The 0.1.x branch still has to support Python 2.6 and 3.0).

Thanks for reporting it

frejanordsiek commented 8 months ago

The problem is fixed. I ended up implementing a very simple version comparison directly without using distutils or setuptools which did just enough.

Unfortunately, I can't test CPython >= 3.9 in my CI pipeline at present due to major incompatibilities between nose and CPython starting in version 3.10.

I have another possible bug or two to check on and then I will make a new bugfix release. I will let you know when it has reached PyPI.