From 47678c21841af48c5c8658d82683e7d89927dacf Mon Sep 17 00:00:00 2001 From: Mirek Simek Date: Thu, 10 Jul 2025 15:04:16 +0200 Subject: [PATCH] chores: replaced importlib_metadata with importlib * Added code from invenio-base to handle py3.9 compatibility --- pywebpack/helpers.py | 28 ++++++++++++++++++++++++++-- setup.cfg | 1 - 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/pywebpack/helpers.py b/pywebpack/helpers.py index b86482a..7513ca6 100644 --- a/pywebpack/helpers.py +++ b/pywebpack/helpers.py @@ -10,10 +10,10 @@ """Webpack bundle API.""" +import importlib.metadata as m import re from functools import wraps - -from importlib_metadata import entry_points +from sys import version_info from pywebpack.errors import MergeConflictError @@ -145,3 +145,27 @@ def merge_deps(computed_deps, incoming_deps): else: computed[incoming_pkg] = incoming_version return computed_deps + + +def entry_points(group): + """Entry points. + + Copied here from invenio-base so that we do not introduce a dependency on invenio-base. + """ + if version_info < (3, 10): + eps = m.entry_points() + # the only reason to add this check is to simplify the tests! the tests + # are implemented against python >=3.10 which uses the group keyword. + # since we drop python3.9 soon, this should work! + # in the tests there is a line which patches the return value of + # importlib.metadata.entry_points with a list. this works for + # python>=3.10 but not for 3.9 + # the return value of .get can contain duplicates. the simplest way to + # remove is the set() call, to still return a list, list() is called on + # set() + if isinstance(eps, dict): + eps = list(set(eps.get(group, []))) + else: + eps = m.entry_points(group=group) + + return eps diff --git a/setup.cfg b/setup.cfg index b903847..d3bd463 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,7 +28,6 @@ packages = find: python_requires = >=3.7 zip_safe = False install_requires = - importlib-metadata pynpm>=0.1.0 [options.extras_require]