openrig.naming.rules module

Configuration rules for the naming convention.

Responsible for loading naming/config.json, building the rule set, and validating the assembled convention at import time, so any configuration error is caught immediately rather than at the first call to build_name.

Exported constants (consumed by __init__.py and Manager):
  • TOKENS: ordered list of token names.

  • SEPARATOR: the separator character.

  • TOKEN_RULES: mapping of token name → ConcreteRule.

  • NORMALIZERS: mapping of token name → normalizer callable.

  • GLOBAL_RULES: the validated GlobalRules instance.

exception openrig.naming.rules.RuleBuilderError[source]

Bases: Exception

Raised when the naming convention cannot be assembled from configuration.

openrig.naming.rules.build_rules(rules_config: Mapping[str, RuleConfig | GlobalRules]) tuple[dict[str, RegexRule | ListRule | CallableRule], GlobalRules][source]

Builds the token rule mapping and global rules from parsed configuration.

Parameters:

rules_config – The parsed rules mapping from _load_config().

Returns:

A tuple of (token_rules, global_rules) where token_rules maps each token name to its ConcreteRule and global_rules is the validated GlobalRules dataclass.

Raises:

RuleBuilderError – If __global__ is missing or invalid, if an unknown rule type is encountered, or if a provider fails.

openrig.naming.rules.build_normalizers(normalizers_config: dict[str, str]) dict[str, Callable[[object], str]][source]

Resolves normalizer function names into callable normalizers.

Parameters:

normalizers_config – The parsed normalizers mapping from _load_config().

Returns:

A mapping of token name → normalizer callable.

Raises:

RuleBuilderError – If a declared normalizer name is not found in NORMALIZER_MAP.

openrig.naming.rules.validate_convention(tokens: list[str], separator: str, token_rules: Mapping[str, RegexRule | ListRule | CallableRule], global_rules: GlobalRules) None[source]

Validates the structural integrity of the assembled naming convention.

Parameters:
  • tokens – The ordered list of token names.

  • separator – The separator character.

  • token_rules – The assembled token rule mapping.

  • global_rules – The global rules dataclass.

Raises:

RuleBuilderError – If any structural constraint is violated.