49
49
str , Platform , Platform , Platform , Optional [str ], Optional [str ], Optional [str ]
50
50
]
51
51
ResolverType = Callable [[Action , Decision ], bool ]
52
-
52
+ QualifierType = str | dict [str , str | bool | Iterable [str ]] | None
53
+ SpecLoadHook = Callable [
54
+ [str , QualifierType , BaseEnv , PRIMITIVE ], tuple [str , QualifierType ]
55
+ ]
53
56
54
57
logger = e3 .log .getLogger ("anod.context" )
55
58
@@ -102,6 +105,7 @@ def __init__(
102
105
spec_repository : AnodSpecRepository ,
103
106
default_env : BaseEnv | None = None ,
104
107
reject_duplicates : bool = False ,
108
+ spec_load_hook : SpecLoadHook | None = None ,
105
109
):
106
110
"""Initialize a new context.
107
111
@@ -112,6 +116,16 @@ def __init__(
112
116
context if the local server
113
117
:param reject_duplicates: if True, raise SchedulingError when two
114
118
duplicated action are generated
119
+ :param spec_load_hook: a function that allows tweaking the anod DAG
120
+ creation by doing substitution of an anod instance by another
121
+ at load time. The hook function has the following signature:
122
+
123
+ hook(name="SPEC_NAME",
124
+ qualifier=SPEC_QUALIFIER,
125
+ env=SPEC_ENV,
126
+ kind=ANOD_PRIMITIVE) -> (NEW_SPEC_NAME, NEW_QUALIFIER)
127
+
128
+ kind can be "install", "build", "test" or "source".
115
129
"""
116
130
self .repo = spec_repository
117
131
if default_env is None :
@@ -126,6 +140,7 @@ def __init__(
126
140
self .add (self .root )
127
141
self .cache : dict [CacheKeyType , Anod ] = {}
128
142
self .sources : dict [str , tuple [str , SourceBuilder ]] = {}
143
+ self .spec_load_hook = spec_load_hook
129
144
130
145
def load (
131
146
self ,
@@ -150,6 +165,12 @@ def load(
150
165
if env is None :
151
166
env = self .default_env
152
167
168
+ # A hook that allows redirection to another spec or automatic adjustment of
169
+ # of qualifiers. This feature is only needed in user mode for development
170
+ # purposes.
171
+ if self .spec_load_hook is not None :
172
+ name , qualifier = self .spec_load_hook (name , qualifier , env , kind )
173
+
153
174
# Key used for the spec instance cache
154
175
if isinstance (qualifier , str ) or qualifier is None :
155
176
qualifier_key = qualifier
0 commit comments