11"""Processing module for changelog generation."""
2-
32from typing import Callable , Union
43
5- BUILT_INS = {}
4+ from collections import UserDict
5+
6+
7+ class Registry (UserDict ):
8+ """
9+ Built-in action registry.
10+
11+ This allows setting keys normally. When getting a key, it makes sure the
12+ appropriate modules are imported to fill the internal dictionary before
13+ getting the key.
14+ """
15+
16+ def __init__ (self , initialdata = None ):
17+ super ().__init__ (initialdata )
18+ self ._loaded = False
19+
20+ def __getitem__ (self , key ):
21+ """Make sure the built-in actions are loaded."""
22+ if not self ._loaded :
23+ self .load_builtins ()
24+ return super ().__getitem__ (key )
25+
26+ def load_builtins (self ):
27+ """Import all submodules so the decorated functions get registered."""
28+ import importlib
29+
30+ importlib .import_module (".text_processing" , "generate_changelog.processors" )
31+ importlib .import_module (".file_processing" , "generate_changelog.processors" )
32+ importlib .import_module (".shell" , "generate_changelog.processors" )
33+ importlib .import_module (".metadata" , "generate_changelog.processors" )
34+
35+ self ._loaded = True
36+
37+
38+ BUILT_INS = Registry ()
639"""The registered actions that are considered to be built-in."""
740
841
@@ -21,13 +54,3 @@ def inner(f: Callable) -> Callable:
2154 else :
2255 name = function_or_name
2356 return inner
24-
25-
26- def load_builtins ():
27- """Import all submodules so the decorated functions get registered."""
28- import importlib
29-
30- importlib .import_module (".text_processing" , "generate_changelog.processors" )
31- importlib .import_module (".file_processing" , "generate_changelog.processors" )
32- importlib .import_module (".shell" , "generate_changelog.processors" )
33- importlib .import_module (".metadata" , "generate_changelog.processors" )
0 commit comments