Skip to content

Commit d02afe4

Browse files
committed
add custom griffe extension for inspection of the Sync implementations
1 parent c9d52c1 commit d02afe4

3 files changed

Lines changed: 30 additions & 16 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from griffe_extensions.sync_stubs_inspector import InspectSpecificObjects
2+
3+
__all__ = ["InspectSpecificObjects"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import griffe
2+
3+
logger = griffe.get_logger("griffe_inspect_specific_objects")
4+
5+
6+
class InspectSpecificObjects(griffe.Extension):
7+
"""Only inspect specific objects (such as ones with stubs)"""
8+
9+
def __init__(self, paths: list[str]) -> None:
10+
self.objects = paths
11+
12+
def on_instance(self, *, obj: griffe.Object, **kwargs) -> None:
13+
if obj.path not in self.objects:
14+
return
15+
16+
# Skip over the stub files themselves
17+
if str(obj.filepath).endswith(".pyi"):
18+
return
19+
# Load the stub file instead of importing the .py
20+
inspected_module = griffe.inspect(obj.module.path, filepath=obj.filepath)
21+
obj.parent.set_member(obj.name, inspected_module[obj.name])

python/mkdocs.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,10 @@ plugins:
3939
options:
4040
load_external_modules: true
4141
show_source: false
42-
allow_inspection: true
4342
find_stubs_package: true
4443
show_if_no_docstring: true
45-
# TODO: custom griffe plugin instead
46-
force_inspection: true # Needed for run-time generated sync_stubs
47-
# filters: [ "!^__", "!^_abc_", "!^_", "!TYPE_CHECKING" ]
4844
filters: "public"
4945
show_submodules: false
50-
# Explicitly include stubs directory
51-
search_path: [ "../lib" ]
5246
# Styling
5347
group_by_category: true
5448
docstring_section_style: spacy
@@ -62,18 +56,14 @@ plugins:
6256
show_symbol_type_heading: true
6357
show_symbol_type_toc: true
6458
summary: true
65-
# Disabled until custom griffe plugin otherwise fails due to force_inspection
66-
# extensions:
67-
# - griffe_pydantic:
68-
# schema: true
59+
# Custom Griffe extension to only inspect sync_stubs
60+
extensions:
61+
- griffe_extensions/sync_stubs_inspector.py:InspectSpecificObjects:
62+
paths:
63+
- sift_client.resources.sync_stubs
64+
6965

7066
- api-autonav:
7167
modules: [ lib/sift_client ] #, lib/sift ]
7268
exclude_private: true
7369
nav_item_prefix: ""
74-
module_options:
75-
# special filters to avoid rendering the async again
76-
sift_client.resources.sync_stubs:
77-
filters: [ "!Async$", "!^__", "!^_abc_", "!^generate" ]
78-
79-

0 commit comments

Comments
 (0)