From 32440ad203116d13e893a5ac37ab848df684011b Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 18 Jul 2024 11:54:06 -0500 Subject: [PATCH] Remove use of pkg_resources package (#3069) --- openmc/lib/__init__.py | 8 +++----- pyproject.toml | 2 +- tests/regression_tests/conftest.py | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/openmc/lib/__init__.py b/openmc/lib/__init__.py index 42d7794414..9bb2efb38a 100644 --- a/openmc/lib/__init__.py +++ b/openmc/lib/__init__.py @@ -13,11 +13,10 @@ functions or objects in :mod:`openmc.lib`, for example: """ from ctypes import CDLL, c_bool, c_int +import importlib.resources import os import sys -import pkg_resources - # Determine shared-library suffix if sys.platform == 'darwin': @@ -27,9 +26,8 @@ else: if os.environ.get('READTHEDOCS', None) != 'True': # Open shared library - _filename = pkg_resources.resource_filename( - __name__, f'libopenmc.{_suffix}') - _dll = CDLL(_filename) + _filename = importlib.resources.files(__name__) / f'libopenmc.{_suffix}' + _dll = CDLL(str(_filename)) # TODO: Remove str() when Python 3.12+ else: # For documentation builds, we don't actually have the shared library # available. Instead, we create a mock object so that when the modules diff --git a/pyproject.toml b/pyproject.toml index ca646323b2..d1b2c335cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ docs = [ "sphinxcontrib-svg2pdfconverter", "sphinx-rtd-theme==1.0.0" ] -test = ["pytest", "pytest-cov", "colorama", "openpyxl"] +test = ["packaging", "pytest", "pytest-cov", "colorama", "openpyxl"] vtk = ["vtk"] [project.urls] diff --git a/tests/regression_tests/conftest.py b/tests/regression_tests/conftest.py index b4a7644762..1cdf414e76 100644 --- a/tests/regression_tests/conftest.py +++ b/tests/regression_tests/conftest.py @@ -1,12 +1,12 @@ import numpy as np import openmc -from pkg_resources import parse_version +from packaging.version import parse import pytest @pytest.fixture(scope='module', autouse=True) def numpy_version_requirement(): - assert parse_version(np.__version__) >= parse_version("1.14"), \ + assert parse(np.__version__) >= parse("1.14"), \ "Regression tests require NumPy 1.14 or greater"