Source code for pytconf.registry

[docs] class Registry: def __init__(self): self.names = set() self.configs = set() self.name_to_data = {} self.name_to_config = {} self.config_names = {}
[docs] def register(self, config, name, data): if name in self.names: raise ValueError( f"pytconf: name [{name}] appears more than once" ) self.names.add(name) self.configs.add(config) if config not in self.config_names: self.config_names[config] = {} self.name_to_data[name] = data self.name_to_config[name] = config self.config_names[config][name] = data
[docs] def yield_configs(self): yield from self.configs
[docs] def yield_names_for_config(self, config): yield from self.config_names[config].keys()
[docs] def yield_name_data_for_config(self, config): yield from self.config_names[config].items()
[docs] def get_data_for_name(self, name): return self.name_to_data[name]
[docs] def get_config_for_name(self, name): return self.name_to_config[name]
[docs] def has_name(self, name): return name in self.names
the_registry: Registry = Registry()