From 684d085fcbc8bed0f6fe8eb3117ece496e139941 Mon Sep 17 00:00:00 2001 From: lcjohnso Date: Thu, 13 Jun 2024 09:35:12 -0500 Subject: [PATCH] replace pkg_resources with importlib.metadata --- docs/conf.py | 4 ++-- panoptes_client/panoptes.py | 4 ++-- panoptes_client/subject.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 7e799f23..67c27324 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,7 +18,7 @@ # import datetime import os -import pkg_resources +import importlib.metadata import sys sys.path.insert(0, os.path.abspath('..')) @@ -62,7 +62,7 @@ # built documents. # # The full version, including alpha/beta/rc tags. -release = pkg_resources.require("panoptes_client")[0].version +release = importlib.metadata.version("panoptes_client") # The short X.Y version. version = '.'.join(release.split('.')[:2]) diff --git a/panoptes_client/panoptes.py b/panoptes_client/panoptes.py index 26602ad2..9eb21cf0 100644 --- a/panoptes_client/panoptes.py +++ b/panoptes_client/panoptes.py @@ -6,7 +6,7 @@ import os import requests import threading -import pkg_resources +import importlib.metadata from datetime import datetime, timedelta from redo import retrier @@ -57,7 +57,7 @@ class Panoptes(object): _http_headers = { 'default': { 'Accept': 'application/vnd.api+json; version=1', - 'User-Agent': 'panoptes-python-client/version=' + pkg_resources.require('panoptes_client')[0].version + 'User-Agent': 'panoptes-python-client/version=' + importlib.metadata.version('panoptes_client') }, 'GET': {}, 'PUT': { diff --git a/panoptes_client/subject.py b/panoptes_client/subject.py index 87ae9431..092202f6 100644 --- a/panoptes_client/subject.py +++ b/panoptes_client/subject.py @@ -21,16 +21,16 @@ import magic MEDIA_TYPE_DETECTION = 'magic' except ImportError: - import pkg_resources + import importlib.metadata try: - pkg_resources.require("python-magic") + importlib.metadata.version("python-magic") logging.getLogger('panoptes_client').warn( 'Broken libmagic installation detected. The python-magic module is' ' installed but can\'t be imported. Please check that both ' 'python-magic and the libmagic shared library are installed ' 'correctly. Uploading media other than images may not work.' ) - except pkg_resources.DistributionNotFound: + except importlib.metadata.PackageNotFoundError: pass import imghdr MEDIA_TYPE_DETECTION = 'imghdr'