From 12c733ebec33a5dc6239fe3b8f2f75b28f5a8169 Mon Sep 17 00:00:00 2001 From: "Ilya (Marshal)" Date: Mon, 16 Dec 2024 22:58:51 +0100 Subject: [PATCH] make validators clickable --- docs/source/alias_resolver.py | 25 +++++++++++++++++-- .../atproto_client/models/string_formats.py | 3 ++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/source/alias_resolver.py b/docs/source/alias_resolver.py index 56780c46..9026d3c1 100644 --- a/docs/source/alias_resolver.py +++ b/docs/source/alias_resolver.py @@ -14,8 +14,21 @@ # FIXME(MarshalX): I didn't find a fast way to fix aliases resolving after migration to Pydantic. # I hope this is temporary and resolving will be on the Sphinx side. - -def get_alias_from_db(alias: str) -> t.Optional[str]: +_GLOBAL_ALIASES_DB = { + 'string_formats.validate_at_uri': 'atproto_client.models.string_formats.validate_at_uri', + 'string_formats.validate_cid': 'atproto_client.models.string_formats.validate_cid', + 'string_formats.validate_datetime': 'atproto_client.models.string_formats.validate_datetime', + 'string_formats.validate_did': 'atproto_client.models.string_formats.validate_did', + 'string_formats.validate_handle': 'atproto_client.models.string_formats.validate_handle', + 'string_formats.validate_language': 'atproto_client.models.string_formats.validate_language', + 'string_formats.validate_nsid': 'atproto_client.models.string_formats.validate_nsid', + 'string_formats.validate_record_key': 'atproto_client.models.string_formats.validate_record_key', + 'string_formats.validate_tid': 'atproto_client.models.string_formats.validate_tid', + 'string_formats.validate_uri': 'atproto_client.models.string_formats.validate_uri', +} + + +def _get_model_alias(alias: str) -> t.Optional[str]: # FIXME(MarshalX): Resolving of models.AppBskyGraphDefs ListPurpose is not working. alias_split = alias.rsplit('.', maxsplit=1) if len(alias_split) < 2: @@ -28,6 +41,14 @@ def get_alias_from_db(alias: str) -> t.Optional[str]: return f'{ALIASES_DB[alias_prefix]}.{alias_suffix}' +def get_alias_from_db(alias: str) -> t.Optional[str]: + model_alias = _get_model_alias(alias) + if model_alias: + return model_alias + + return _GLOBAL_ALIASES_DB.get(alias) + + # annotate def resolve_intersphinx_aliases( app: 'Sphinx', env: 'BuildEnvironment', node: pending_xref, contnode: 'TextElement' diff --git a/packages/atproto_client/models/string_formats.py b/packages/atproto_client/models/string_formats.py index 851111ea..3ab4a826 100644 --- a/packages/atproto_client/models/string_formats.py +++ b/packages/atproto_client/models/string_formats.py @@ -64,7 +64,8 @@ def __call__(self, v: str, info: ValidationInfo) -> str: return self.validate_fn(v, info) def __str__(self) -> str: - return f'Validated by: {self.validate_fn.__name__} (only when `strict_string_format=True`)' + func_str = f':func:`string_formats.{self.validate_fn.__name__}`' + return f'Validated by: {func_str} (only when `strict_string_format=True`)' def only_validate_if_strict(validate_fn: Callable[..., str]) -> Callable[..., str]: