fix: Support importlib_metadata v5.0.0 (#5840)

* fix: Support importlib_metadata v5.0.0

importlib_metadata removed compatibility shims for deprecated entry point interfaces.
see: https://github.com/python/importlib_metadata/blob/main/CHANGES.rst#v500

Filter result of entry_points function by group parameter.
see: https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.entry_points

* fix: Enable to run in older python version

In circleci frontend-unit-tests, old node image is used and python 3.5 is used.
Support both old version and latest version by checking ijmportlib_metadata version
This commit is contained in:
tsbkw
2023-02-16 11:47:56 +09:00
committed by GitHub
parent 5cf13afafe
commit 82361e7054
2 changed files with 13 additions and 2 deletions

View File

@@ -65,7 +65,18 @@ def load_bundles():
"""
bundles = odict()
for entry_point in importlib_metadata.entry_points().get("redash.bundles", []):
# HACK:
# bin/bundle-extensions is tested in different versions.
# circleci frontend-unit-tests: python 3.5 and importlib-metadata-2.1.3
# circleci backend-unit-tests: python 3.7 and importlib-metadata-5.0.0
if importlib_metadata.version("importlib_metadata") >= "5.0.0":
bundles_entry_points = importlib_metadata.entry_points(group="redash.bundles")
else:
bundles_entry_points = importlib_metadata.entry_points().get(
"redash.bundles", []
)
for entry_point in bundles_entry_points:
logger.info('Loading Redash bundle "%s".', entry_point.name)
module = entry_point_module(entry_point)
# Try to get a list of bundle files

View File

@@ -27,7 +27,7 @@ def entry_point_loader(group_name, mapping, logger=None, *args, **kwargs):
if logger is None:
logger = extension_logger
for entry_point in entry_points().get(group_name, []):
for entry_point in entry_points(group=group_name):
logger.info('Loading entry point "%s".', entry_point.name)
try:
# Then try to load the entry point (import and getattr)