Skip to content

Commit

Permalink
Update _signatures.py
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed Dec 15, 2023
1 parent 596062a commit 850fdf2
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions docs/barret.py → docs/_signatures.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# import griffe.docstrings.dataclasses as ds
import json
from typing import Union

import griffe.dataclasses as dc
import griffe.docstrings.dataclasses as ds
import griffe.expressions as exp
from _renderer import Renderer
from griffe.collections import LinesCollection, ModulesCollection
from griffe.docstrings import Parser
from griffe.loader import GriffeLoader
from plum import dispatch
from quartodoc import MdRenderer, get_object, preview
from quartodoc.parsers import get_parser_defaults
from quartodoc.renderers.base import convert_rst_link_to_md, sanitize

from shiny import reactive, render, ui
Expand All @@ -27,6 +32,18 @@
# preview(obj.parameters)


loader = GriffeLoader(
docstring_parser=Parser("numpy"),
docstring_options=get_parser_defaults("numpy"),
modules_collection=ModulesCollection(),
lines_collection=LinesCollection(),
)


def fast_get_object(path: str):
return get_object(path, loader=loader)


class BarretFnSig(Renderer):
style = "custom_greg_styles"

Expand Down Expand Up @@ -112,9 +129,9 @@ def render(self, el: ds.DocstringSectionParameters):


# TODO-barret; Add sentance in template to describe what the Relevant Function section is: "To learn more about details about the functions covered here, visit the reference links below."
# print(BarretFnSig().render(get_object("shiny:ui.input_action_button")))
# print(BarretFnSig().render(get_object("shiny:ui.input_action_button")))
# preview(get_object("shiny:ui"))
# print(BarretFnSig().render(fast_get_object("shiny:ui.input_action_button")))
# print(BarretFnSig().render(fast_get_object("shiny:ui.input_action_button")))
# preview(fast_get_object("shiny:ui"))
# print("")


Expand All @@ -124,17 +141,30 @@ def render(self, el: ds.DocstringSectionParameters):
("render", render),
("reactive", reactive),
]:
print(f"## Collecting signatures: {mod_name}")
ret[mod_name] = {}
for key, f_obj in mod.__dict__.items():
if key.startswith("_") or key in ("AnimationOptions",):
continue
if not callable(f_obj):
continue
print(f"## {mod_name}.{key}")
signature = BarretFnSig().render(get_object(f"shiny:{mod_name}.{key}"))
# print(f"## {mod_name}.{key}")
signature = BarretFnSig().render(fast_get_object(f"shiny:{mod_name}.{key}"))
ret[mod_name][key] = signature
preview(ret)
# preview(ret)

print("## Saving signatures")


with open("objects.json") as infile:
objects_content = json.load(infile)
objects_content["signatures"] = ret
# Serializing json
json_object = json.dumps(objects_content)

# Writing to sample.json
with open("objects.json", "w") as outfile:
outfile.write(json_object)
# TODO-barret; Include link to GitHub source
# print(BarretFnSig().render(f_obj.annotation))
# print(preview(f_obj))
Expand Down

0 comments on commit 850fdf2

Please sign in to comment.