|
13 | 13 | from easybuild.tools.build_log import EasyBuildError |
14 | 14 |
|
15 | 15 | try: |
16 | | - from importlib.metadata import entry_points |
| 16 | + from importlib.metadata import entry_points, EntryPoints |
17 | 17 | except ModuleNotFoundError: |
18 | 18 | HAVE_ENTRY_POINTS = False |
19 | 19 | else: |
|
25 | 25 |
|
26 | 26 | def get_group_entrypoints(group: str): |
27 | 27 | """Get all entrypoints for a group""" |
28 | | - # Default True needed to work with commands like --list-toolchains that do not initialize the BuildOptions |
29 | | - if not build_option('use_entrypoints', default=True): |
30 | | - return set() |
31 | | - if not HAVE_ENTRY_POINTS: |
32 | | - msg = "Python importlib.metadata requires Python >= 3.8" |
33 | | - _log.warning(msg) |
34 | | - raise EasyBuildError(msg) |
35 | | - # Can't use the group keyword argument in entry_points() for Python < 3.10 |
36 | | - return set(ep for ep in entry_points() if ep.group == group) |
| 28 | + strict_python = True |
| 29 | + use_eps = build_option('use_entrypoints', default=None) |
| 30 | + if use_eps is None: |
| 31 | + # Default True needed to work with commands like --list-toolchains that do not initialize the BuildOptions |
| 32 | + use_eps = True |
| 33 | + # Needed to work with older Python versions: do not raise errors when entry points are default enabled |
| 34 | + strict_python = False |
| 35 | + res = set() |
| 36 | + if use_eps: |
| 37 | + if not HAVE_ENTRY_POINTS and strict_python: |
| 38 | + msg = "`--use-entrypoints` requires importlib.metadata (Python >= 3.8)" |
| 39 | + _log.warning(msg) |
| 40 | + raise EasyBuildError(msg) |
| 41 | + # Can't use the group keyword argument in entry_points() for Python < 3.10 |
| 42 | + try: |
| 43 | + eps = entry_points() |
| 44 | + if isinstance(eps, EntryPoints): |
| 45 | + # Python >= 3.10 |
| 46 | + res = set(ep for ep in eps if ep.group == group) |
| 47 | + elif isinstance(eps, dict): |
| 48 | + # Python < 3.10 |
| 49 | + res = set(eps.get(group, [])) |
| 50 | + except NameError: |
| 51 | + _log.debug("`get_group_entrypoints` called before BuildOptions initialized, with python < 3.8") |
| 52 | + return res |
37 | 53 |
|
38 | 54 |
|
39 | 55 | # EASYCONFIG_ENTRYPOINT = "easybuild.easyconfig" |
|
0 commit comments