Skip to content

Commit

Permalink
fix: Support importlib_metadata v5.0.0 (getredash#5840)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tsbkw authored and tharzeez committed Jun 26, 2023
1 parent 66104b3 commit 862fa50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion bin/bundle-extensions
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion redash/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 862fa50

Please sign in to comment.