precise_imports
Utility functions for importing modules. During first import, all plugins are imported and cached.
cached_import
cached_import(type_name, base_module)
Imports a module entry point by name. All imports are cached, so overhead after first import is minimal. This is for internal use only: for importing modules use import_executor, import_sampler etc.
Parameters
type_name : str Class name of the type that should be imported. base_module : str For non-plugin modules, the module name. Eg. 'samplers'
Returns
class Class entry point. To construct an instance, use eg. cached_import(type_name, base_module)(**kwargs)
Raises
ImportError If the module or class cannot be found.
Source code in src/enchanted_surrogates/utils/precise_imports.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
cached_import_external
cached_import_external(type_name, module)
Imports a module entry point by name. All imports are cached, so overhead after first import is minimal. This is for internal use only: for importing modules use import_executor, import_sampler etc.
Parameters
type_name : str Class name of the type that should be imported. module : str Name of the python module from which to import
Returns
class Class entry point. To construct an instance, use eg. cached_import_external(type_name, module)(**kwargs)
Raises
ImportError If the module or class cannot be found.
Source code in src/enchanted_surrogates/utils/precise_imports.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
camel_or_pascal_to_snake
camel_or_pascal_to_snake(s)
Converts a camelCase or PascalCase string to snake_case.
Parameters
s : str A string in camelCase or PascalCase format.
Returns
str The converted snake_case string.
Source code in src/enchanted_surrogates/utils/precise_imports.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
clear_import_cache
clear_import_cache()
Clears everything from import cache.
Source code in src/enchanted_surrogates/utils/precise_imports.py
110 111 112 113 114 115 | |
detect_case_style
detect_case_style(s)
Detects the naming convention of a given string.
Parameters
s : str The string to analyze.
Returns
str One of: 'snake_case', 'camelCase', 'PascalCase', 'kebab-case', or 'unknown'.
Source code in src/enchanted_surrogates/utils/precise_imports.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
get_snake_and_pascal
get_snake_and_pascal(string)
Given a string in either snake_case or PascalCase, returns both formats.
Parameters
string : str The input string to normalize.
Returns
tuple of str (snake_case version, PascalCase version)
Notes
If the input is already in snake_case or PascalCase, it is preserved. camelCase and other formats are not supported.
Source code in src/enchanted_surrogates/utils/precise_imports.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
import_executor
import_executor(executor_type, executor_config)
Dynamically imports and instantiates a executor class based on naming convention.
Parameters
executor_type : str The name of the executor (in snake_case or PascalCase). executor_config : dict Keyword arguments to pass to the executor constructor.
Returns
object An instance of the executor class.
Raises
ImportError If the module or class cannot be found.
Source code in src/enchanted_surrogates/utils/precise_imports.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
import_parser
import_parser(parser_type, parser_config)
Dynamically imports and instantiates a parser class based on naming convention.
Parameters
parser_type : str The name of the parser (in snake_case or PascalCase). parser_config : dict Keyword arguments to pass to the sampler constructor.
Returns
object An instance of the parser class.
Raises
ImportError If the module or class cannot be found.
Source code in src/enchanted_surrogates/utils/precise_imports.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
import_runner
import_runner(runner_type, runner_config)
Dynamically imports and instantiates a runner class based on naming convention.
Parameters
runner_type : str The name of the sampler (in snake_case or PascalCase). sampler_config : dict Keyword arguments to pass to the sampler constructor.
Returns
object An instance of the sampler class.
Raises
ImportError If the module or class cannot be found.
Source code in src/enchanted_surrogates/utils/precise_imports.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
import_sampler
import_sampler(sampler_type, sampler_config)
Dynamically imports and instantiates a sampler class based on naming convention.
Parameters
sampler_type : str The name of the sampler (in snake_case or PascalCase). sampler_config : dict Keyword arguments to pass to the sampler constructor.
Returns
object An instance of the sampler class.
Raises
ImportError If the module or class cannot be found.
Source code in src/enchanted_surrogates/utils/precise_imports.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
snake_to_pascal
snake_to_pascal(s)
Converts a snake_case string to PascalCase.
Parameters
s : str A string in snake_case format.
Returns
str The converted PascalCase string.
Source code in src/enchanted_surrogates/utils/precise_imports.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |