From 7b46fcc307479f7432563daa194dc5ad04f2e418 Mon Sep 17 00:00:00 2001 From: Alif Be Date: Wed, 11 Oct 2023 12:22:28 +0200 Subject: [PATCH] Remove deprecated `pkg_resources` --- pyproject.toml | 1 - src/subscript/__init__.py | 6 +++--- src/subscript/hook_implementations/jobs.py | 8 ++++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 508819fd7..bb7e60a8a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,6 @@ tests = [ "rstcheck-core", "types-Jinja2", "types-PyYAML", - "types-pkg_resources", "types-python-dateutil", ] docs = [ diff --git a/src/subscript/__init__.py b/src/subscript/__init__.py index 1b7425ca4..7ec9c3453 100644 --- a/src/subscript/__init__.py +++ b/src/subscript/__init__.py @@ -2,10 +2,10 @@ import sys try: - import pkg_resources + from importlib import metadata - __version__ = pkg_resources.get_distribution(__name__).version -except pkg_resources.DistributionNotFound: + __version__ = metadata.version(__name__) +except metadata.PackageNotFoundError: pass diff --git a/src/subscript/hook_implementations/jobs.py b/src/subscript/hook_implementations/jobs.py index 29cbae08c..db0d101c1 100644 --- a/src/subscript/hook_implementations/jobs.py +++ b/src/subscript/hook_implementations/jobs.py @@ -1,10 +1,10 @@ import importlib import os +import pkgutil from typing import Any, Optional from ert.shared.plugins.plugin_manager import hook_implementation from ert.shared.plugins.plugin_response import plugin_response -from pkg_resources import resource_filename # pylint: disable=no-value-for-parameter @@ -12,7 +12,11 @@ def _get_jobs_from_directory(directory): """Do a filesystem lookup in a directory to check for available ERT forward models""" - resource_directory = resource_filename("subscript", directory) + resource_directory = ( + os.path.dirname(pkgutil.get_loader("subscript").get_filename()) + + "/" + + directory + ) all_files = [ os.path.join(resource_directory, f)