66import logging
77logger = logging .getLogger (__name__ )
88
9+
910class CategoryCompilerRegistrationError (Exception ):
1011 pass
1112
@@ -22,6 +23,7 @@ class CategoryCompilerRegistrationError(Exception):
2223
2324COMPILE_ORDER = _DEFAULT_COMPILE_ORDER .copy ()
2425
26+
2527def clean_input_key (key ):
2628 # TODO: move this to core
2729 """
@@ -34,12 +36,14 @@ def clean_input_key(key):
3436 key = key .replace ("-" , "_" )
3537 return key
3638
39+
3740### Managing known compilers and aliases to the known compilers ############
3841
3942_COMPILERS = {} # mapping: {canonical_name: CategoryCompiler}
4043_ALIASES = {} # mapping: {alias: canonical_name}
4144# NOTE: _ALIASES does *not* include self-mapping of the canonical names
4245
46+
4347def _canonical_name (alias ):
4448 """Take an alias or a compiler name and return the compiler name
4549
@@ -51,6 +55,7 @@ def _canonical_name(alias):
5155 alias_to_canonical .update ({pname : pname for pname in _COMPILERS })
5256 return alias_to_canonical .get (alias , None )
5357
58+
5459def _get_compiler (category ):
5560 """
5661 _get_compiler must only be used after the CategoryCompilers have been
@@ -69,6 +74,7 @@ def _get_compiler(category):
6974 _COMPILERS [category ] = CategoryCompiler (None , category )
7075 return _COMPILERS [canonical_name ]
7176
77+
7278def _register_compiler_plugin (plugin ):
7379 DUPLICATE_ERROR = CategoryCompilerRegistrationError (
7480 f"The category '{ plugin .name } ' has been reserved by another plugin"
@@ -87,7 +93,7 @@ def _register_compiler_plugin(plugin):
8793
8894
8995### Handling delayed loading of compilers ##################################
90- #
96+
9197# Many objects need to use compilers to create their input parameters. In
9298# order for them to be able to access dynamically-loaded plugins, we delay
9399# the loading of the compiler by using a proxy object.
@@ -111,6 +117,7 @@ def named_objs(self):
111117 def __call__ (self , dct ):
112118 return self ._proxy (dct )
113119
120+
114121def compiler_for (category ):
115122 """Delayed compiler calling.
116123
@@ -142,11 +149,13 @@ def _get_registration_names(plugin):
142149 found_names .add (name )
143150 return ordered_names
144151
152+
145153def _register_builder_plugin (plugin ):
146154 compiler = _get_compiler (plugin .category )
147155 for name in _get_registration_names (plugin ):
148156 compiler .register_builder (plugin , name )
149157
158+
150159def register_plugins (plugins ):
151160 builders = []
152161 compilers = []
@@ -162,6 +171,7 @@ def register_plugins(plugins):
162171 for plugin in builders :
163172 _register_builder_plugin (plugin )
164173
174+
165175### Performing the compiling of user input #################################
166176
167177def _sort_user_categories (user_categories ):
@@ -179,6 +189,7 @@ def _sort_user_categories(user_categories):
179189 )
180190 return sorted_keys
181191
192+
182193def do_compile (dct ):
183194 """Main function for compiling user input to objects.
184195 """
0 commit comments