Skip to content

Commit

Permalink
safety net in doc creation when adding more dispatchers
Browse files Browse the repository at this point in the history
This should warn when adding new dispatchers, and also
indicate exactly which one is missing.

Also made nice use of the whalrus op.

Signed-off-by: Nick Papior <[email protected]>
  • Loading branch information
zerothi committed Oct 11, 2024
1 parent b8e846a commit ec57db1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,15 @@ def yield_types(obj: object, classes):
pass


_found_dispatch_attributes = set()
for obj in yield_objects(sisl):

for name, attr in yield_types(obj, sisl._dispatcher.AbstractDispatcher):
# Fix the class dispatchers methods
assign_class_dispatcher_methods(obj, name, as_attributes=True)
# Collect all the different names where a dispatcher is associated.
# In this way we die if we add a new one, without documenting it!
_found_dispatch_attributes.add(name)

for name, attr in yield_types(
obj, (sisl.io._multiple.SileBound, sisl.io._multiple.SileBinder)
Expand All @@ -756,6 +760,16 @@ def yield_types(obj: object, classes):
assign_nested_attribute(obj, name, attr.__wrapped__)


if (
len(
diff := _found_dispatch_attributes
- set(autosummary_context["sisl_dispatch_attributes"])
)
> 0
):
raise ValueError(f"Found more sets than defined: {diff}")


def sisl_skip(app, what, name, obj, skip, options):
global autodoc_default_options, autosummary_context
# When adding routines here, please also add them
Expand Down
1 change: 1 addition & 0 deletions src/sisl/_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def dispatch(self, method):
A basic interception would be
.. code:: python
@wraps(method)
def func(*args, **kwargs):
return method(*args, **kwargs)
Expand Down

0 comments on commit ec57db1

Please sign in to comment.