From 5767a98fc2710a427d77afe59b00191beb276eda Mon Sep 17 00:00:00 2001 From: Neil Girdhar Date: Sun, 24 Sep 2023 01:52:18 -0400 Subject: [PATCH] Remove deprecated pkg_resources --- src/orion/core/utils/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/orion/core/utils/__init__.py b/src/orion/core/utils/__init__.py index 48e5179a5..31411ce6a 100644 --- a/src/orion/core/utils/__init__.py +++ b/src/orion/core/utils/__init__.py @@ -9,6 +9,7 @@ import logging import os import signal +import sys from abc import ABCMeta from collections import defaultdict from contextlib import contextmanager @@ -16,7 +17,11 @@ from importlib import import_module from tempfile import NamedTemporaryFile -import pkg_resources +if sys.version_info >= (3, 10): + from importlib.metadata import entry_points +else: + from pkg_resources import iter_entry_points + log = logging.getLogger(__name__) @@ -72,7 +77,15 @@ def _import_modules(cls): # base = import_module(cls.__base__.__module__) # Get types advertised through entry points! - for entry_point in pkg_resources.iter_entry_points(cls.__name__): + if sys.version_info >= (3, 10): + entry_point_iterable = ( + entry_point + for entry_point in entry_points() + if entry_point.group == cls.__name__ + ) + else: + entry_point_iterable = iter_entry_points(cls.__name__) + for entry_point in entry_point_iterable: entry_point.load() assert entry_point.dist is not None log.debug(