4
4
5
5
* Davide Grassano (CECAM)
6
6
"""
7
-
7
+ import sys
8
8
import importlib
9
9
from easybuild .tools .config import build_option
10
10
from typing import Callable , List
11
11
12
12
from easybuild .base import fancylogger
13
13
from easybuild .tools .build_log import EasyBuildError
14
14
15
- try :
16
- from importlib .metadata import entry_points , EntryPoints
17
- except ModuleNotFoundError :
18
- HAVE_ENTRY_POINTS = False
19
- else :
15
+
16
+ HAVE_ENTRY_POINTS = False
17
+ HAVE_ENTRY_POINTS_CLS = False
18
+ if sys .version_info >= (3 , 8 ):
20
19
HAVE_ENTRY_POINTS = True
20
+ from importlib .metadata import entry_points
21
+
22
+ if sys .version_info >= (3 , 10 ):
23
+ # Python >= 3.10 uses importlib.metadata.EntryPoints as a type for entry_points()
24
+ HAVE_ENTRY_POINTS_CLS = True
21
25
22
26
23
27
_log = fancylogger .getLogger ('entrypoints' , fname = False )
@@ -34,21 +38,21 @@ def get_group_entrypoints(group: str):
34
38
strict_python = False
35
39
res = set ()
36
40
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
41
+ if not HAVE_ENTRY_POINTS :
42
+ if strict_python :
43
+ msg = "`--use-entrypoints` requires importlib.metadata (Python >= 3.8)"
44
+ _log .warning (msg )
45
+ raise EasyBuildError (msg )
46
+ else :
47
+ _log .debug ("`get_group_entrypoints` called before BuildOptions initialized, with python < 3.8" )
48
+ else :
49
+ if HAVE_ENTRY_POINTS_CLS :
50
+ eps = entry_points (group = group )
51
+ res = set (eps )
52
+ else :
53
+ eps = entry_points ()
49
54
res = set (eps .get (group , []))
50
- except NameError :
51
- _log .debug ("`get_group_entrypoints` called before BuildOptions initialized, with python < 3.8" )
55
+
52
56
return res
53
57
54
58
0 commit comments