From ae7c6b4afc65fdc0845273d8d5f7ef76a5f64545 Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Fri, 29 Sep 2023 09:34:19 -0700 Subject: [PATCH] update some config docstrings --- autoregistry/config.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/autoregistry/config.py b/autoregistry/config.py index ce5ecf7..5d00bc5 100644 --- a/autoregistry/config.py +++ b/autoregistry/config.py @@ -59,6 +59,7 @@ def update(self, new: dict) -> None: setattr(self, key, value) def getitem(self, registry: dict, key: str): + """Key/Value lookup with keysplitting and optional case-insensitivity.""" keys = key_split(key) for key in keys: if not self.case_sensitive: @@ -70,10 +71,30 @@ def getitem(self, registry: dict, key: str): def format(self, name: str) -> str: """Convert and validate a function or class name to a registry key. + Operations are performed in the following order (if configured): + 1. ``regex`` validator + 2. ``prefix`` validation, then stripping. + 3. ``suffix`` validation, then stripping. + 4. ``snake_case`` transform (``FooBar`` -> ``foo_bar``). + 5. ``hyphen`` transform (``foo_bar`` -> ``foo-bar``). + 6. ``transform`` arbitrary user-provided string transform. + 7. The lookup string representation is then stored as all + lowercase if ``case_sensitive=False``. + Parameters ---------- name: str Name to convert to a registry key. + + Raises + ------ + InvalidNameError + If the provided name fails a validation check (``prefix``, ``suffix``, ``regex``). + + Returns + ------- + str + New name after applying all transformation and validation rules. """ if self._regex_validator and not self._regex_validator.match(name): raise InvalidNameError(f"{name} name must match regex {self.regex}")