diff --git a/SConstruct b/SConstruct index 7f23af5c4..418913116 100644 --- a/SConstruct +++ b/SConstruct @@ -78,7 +78,10 @@ import subprocess import re import json import textwrap -from pkg_resources import parse_version +try: + from packaging.version import parse as parse_version +except ImportError: + from pkg_resources import parse_version import SCons # ensure that Python and SCons versions are sufficient for the build process diff --git a/interfaces/cython/cantera/_utils.pyx b/interfaces/cython/cantera/_utils.pyx index 2083a3303..4fc168517 100644 --- a/interfaces/cython/cantera/_utils.pyx +++ b/interfaces/cython/cantera/_utils.pyx @@ -6,13 +6,13 @@ import os import warnings from cpython.ref cimport PyObject import numbers -import pkg_resources +import importlib.metadata import numpy as np # avoid explicit dependence of cantera on scipy try: - pkg_resources.get_distribution('scipy') -except pkg_resources.DistributionNotFound: + importlib.metadata.version('scipy') +except importlib.metadata.PackageNotFoundError: _scipy_sparse = ImportError('Method requires a working scipy installation.') else: from scipy import sparse as _scipy_sparse @@ -103,8 +103,8 @@ def hdf_support(): """ out = [] try: - pkg_resources.get_distribution("h5py") - except pkg_resources.DistributionNotFound: + importlib.metadata.version("h5py") + except importlib.metadata.PackageNotFoundError: pass else: out.append("h5py") diff --git a/interfaces/cython/cantera/composite.py b/interfaces/cython/cantera/composite.py index 2b26c3c4b..5e1ad4dcb 100644 --- a/interfaces/cython/cantera/composite.py +++ b/interfaces/cython/cantera/composite.py @@ -6,24 +6,22 @@ from ._cantera import * import numpy as np from collections import OrderedDict import csv as _csv +import importlib.metadata def _import_h5py(): # avoid explicit dependence of cantera on h5py - import pkg_resources # local import to reduce overall import time try: - pkg_resources.get_distribution('h5py') - except pkg_resources.DistributionNotFound: + importlib.metadata.version('h5py') + except importlib.metadata.PackageNotFoundError: raise ImportError('Method requires a working h5py installation.') else: import h5py return h5py # avoid explicit dependence of cantera on pandas -import pkg_resources - try: - pkg_resources.get_distribution('pandas') -except pkg_resources.DistributionNotFound: + importlib.metadata.version('pandas') +except importlib.metadata.PackageNotFoundError: _pandas = ImportError('Method requires a working pandas installation.') else: import pandas as _pandas diff --git a/interfaces/cython/setup.cfg.in b/interfaces/cython/setup.cfg.in index 642a9b2ef..cd0aef3ba 100644 --- a/interfaces/cython/setup.cfg.in +++ b/interfaces/cython/setup.cfg.in @@ -42,6 +42,7 @@ include_package_data = True install_requires = numpy >= 1.12.0 ruamel.yaml >= 0.15.34 + packaging python_requires = >=@py_min_ver_str@ packages = cantera diff --git a/interfaces/python_sdist/setup.cfg.in b/interfaces/python_sdist/setup.cfg.in index db4c04635..2c42e85c1 100644 --- a/interfaces/python_sdist/setup.cfg.in +++ b/interfaces/python_sdist/setup.cfg.in @@ -42,6 +42,7 @@ include_package_data = True install_requires = numpy >= 1.12.0 ruamel.yaml >= 0.15.34 + packaging python_requires = >=@py_min_ver_str@ packages = cantera diff --git a/site_scons/buildutils.py b/site_scons/buildutils.py index bfc234293..276c4c1f1 100644 --- a/site_scons/buildutils.py +++ b/site_scons/buildutils.py @@ -11,7 +11,10 @@ import time import shutil import enum from pathlib import Path -from pkg_resources import parse_version +try: + from packaging.version import parse as parse_version +except ImportError: + from pkg_resources import parse_version import logging from typing import TYPE_CHECKING from collections.abc import Mapping as MappingABC @@ -1352,7 +1355,10 @@ def get_pip_install_location( root = quoted(root) if root is not None else None install_script = textwrap.dedent(f""" from pip import __version__ as pip_version - from pkg_resources import parse_version + try: + from packaging.version import parse as parse_version + except ImportError: + from pkg_resources import parse_version import pip import json pip_version = parse_version(pip_version) diff --git a/test/python/test_kinetics.py b/test/python/test_kinetics.py index 44d91e3cc..c2fb3d3f3 100644 --- a/test/python/test_kinetics.py +++ b/test/python/test_kinetics.py @@ -1,7 +1,7 @@ import numpy as np import re import itertools -import pkg_resources +import importlib.metadata import pytest import cantera as ct @@ -10,8 +10,8 @@ from .utilities import allow_deprecated # avoid explicit dependence of cantera on scipy try: - pkg_resources.get_distribution('scipy') -except pkg_resources.DistributionNotFound: + importlib.metadata.version('scipy') +except importlib.metadata.PackageNotFoundError: _scipy_sparse = ImportError('Method requires a working scipy installation.') else: from scipy import sparse as _scipy_sparse