Skip to content

Commit

Permalink
Merge pull request #1466 from opendatacube/rm_pkg_resources
Browse files Browse the repository at this point in the history
Replace deprecated pkg_resources
  • Loading branch information
Ariana-B committed Jun 26, 2023
2 parents 3affff3 + 16e65ac commit 1e62323
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
9 changes: 2 additions & 7 deletions datacube/drivers/driver_cache.py
Expand Up @@ -26,14 +26,9 @@ def load_drivers(group: str) -> Dict[str, Any]:
"""

def safe_load(ep):
from pkg_resources import DistributionNotFound
# pylint: disable=broad-except,bare-except
try:
driver_init = ep.load()
except DistributionNotFound:
# This happens when entry points were marked with extra features,
# but extra feature were not requested for installation
return None
except Exception as e:
_LOG.warning('Failed to resolve driver %s::%s', group, ep.name)
_LOG.warning('Error was: %s', repr(e))
Expand All @@ -51,8 +46,8 @@ def safe_load(ep):
return driver

def resolve_all(group: str) -> Iterable[Tuple[str, Any]]:
from pkg_resources import iter_entry_points
for ep in iter_entry_points(group=group, name=None):
from importlib.metadata import entry_points
for ep in entry_points(group=group):
driver = safe_load(ep)
if driver is not None:
yield (ep.name, driver)
Expand Down
1 change: 1 addition & 0 deletions docs/about/whats_new.rst
Expand Up @@ -16,6 +16,7 @@ v1.8.next
- Add option to specify maturity timedelta when using ``--archive-less-mature`` option (:pull:`1460`)
- Mark executors as deprecated (:pull:`1461`)
- Mark ingestion as deprecated (:pull:`1463`)
- Replace deprecated ``pkg_resources`` with ``importlib.resources`` and ``importlib.metadata`` (:pull:`1466`)


v1.8.13 (6th June 2023)
Expand Down
6 changes: 3 additions & 3 deletions docs/click_utils.py
Expand Up @@ -2,7 +2,7 @@
#
# Copyright (c) 2015-2023 ODC Contributors
# SPDX-License-Identifier: Apache-2.0
import pkg_resources
from importlib.metadata import entry_points
from docutils.nodes import literal_block, section, title, make_id
from sphinx.domains import Domain
from docutils.parsers.rst import Directive
Expand Down Expand Up @@ -34,8 +34,8 @@ def find_script_callable_from_env(name, env):


def find_script_callable(name):
return list(pkg_resources.iter_entry_points(
'console_scripts', name))[0].load()
return list(entry_points(
group='console_scripts', name=name))[0].load()


def generate_help_text(command, prefix):
Expand Down
2 changes: 2 additions & 0 deletions wordlist.txt
Expand Up @@ -206,6 +206,7 @@ IAM
ident
identifer
img
importlib
INEGI
inegi
ing
Expand Down Expand Up @@ -338,6 +339,7 @@ pgadmin
pgintegration
pgisintegration
pixelquality
pkg
pkgs
Pluggable
pmap
Expand Down

0 comments on commit 1e62323

Please sign in to comment.