diff --git a/papyri/crosslink.py b/papyri/crosslink.py index fc6f43bb..4aab056d 100644 --- a/papyri/crosslink.py +++ b/papyri/crosslink.py @@ -22,7 +22,7 @@ Fig, Section, SeeAlsoItem, - Signature, + TextSignature, encoder, TocTree, ) @@ -72,7 +72,7 @@ class IngestedBlobs(Node): "aliases", "example_section_data", "see_also", - "signature", + "textsignature", "references", "logo", "qa", @@ -87,7 +87,7 @@ class IngestedBlobs(Node): aliases: List[str] example_section_data: Section see_also: List[SeeAlsoItem] # see also data - signature: Signature + textsignature: TextSignature references: Optional[List[str]] qa: str arbitrary: List[Section] diff --git a/papyri/gen.py b/papyri/gen.py index 91174f5a..6f2f1df3 100644 --- a/papyri/gen.py +++ b/papyri/gen.py @@ -69,7 +69,7 @@ RefInfo, Section, SeeAlsoItem, - Signature, + TextSignature, parse_rst_section, ) from .toc import make_tree @@ -536,7 +536,7 @@ def gen_main( g = Gen(dummy_progress=dummy_progress, config=config) g.log.info("Will write data to %s", target_dir) if debug: - g.log.setLevel("DEBUG") + g.log.setLevel(logging.DEBUG) g.log.debug("Log level set to debug") g.collect_package_metadata( @@ -730,6 +730,20 @@ class DocBlob(Node): as well as link to external references, like images generated. """ + __slots__ = ( + "content", + "example_section_data", + "ordered_sections", + "item_file", + "item_line", + "item_type", + "aliases", + "see_also", + "textsignature", + "references", + "arbitrary", + ) + @classmethod def _deserialise(cls, **kwargs): # print_("will deserialise", cls) @@ -769,7 +783,7 @@ def _deserialise(cls, **kwargs): item_type: Optional[str] aliases: List[str] see_also: List[SeeAlsoItem] # see also data - signature: Signature + textsignature: TextSignature references: Optional[List[str]] arbitrary: List[Section] @@ -784,7 +798,7 @@ def slots(self): "item_file", "item_line", "item_type", - "signature", + "textsignature", "references", "aliases", "arbitrary", @@ -792,30 +806,9 @@ def slots(self): @classmethod def new(cls): - return cls({}, None, None, None, None, None, [], [], Signature(None), None, []) - - # def __init__( - # self, - # content, - # example_section_data, - # ordered_sections, - # item_file, - # item_line, - # item_type, - # aliases, - # see_also, - # signature, - # references, - # arbitrary, - # ): - # self.content = content - # self.example_section_data = example_section_data - # self.ordered_sections = ordered_sections - # self.item_file = item_file - # self.item_line = item_line - # self.item_type = item_type - # self.aliases = aliases - # self.signature = signature + return cls( + {}, None, None, None, None, None, [], [], TextSignature(None), None, [] + ) def _numpy_data_to_section(data: List[Tuple[str, str, List[str]]], title: str, qa): @@ -868,14 +861,25 @@ class APIObjectInfo: kind: str docstring: str - signature: Optional[Signature] + signature: Optional[ObjectSignature] name: str - def __init__(self, kind, docstring, signature, name, qa): + def __repr__(self): + return f"" + + def __init__( + self, + kind: str, + docstring: str, + signature: Optional[ObjectSignature], + name: str, + qa: str, + ): + assert isinstance(signature, (ObjectSignature, type(None))) self.kind = kind self.name = name self.docstring = docstring - self.parsed = [] + self.parsed: List[Any] = [] self.signature = signature self._qa = qa @@ -1347,7 +1351,7 @@ def collect_narrative_docs(self): blob.aliases = [] blob.example_section_data = Section([], None) blob.see_also = [] - blob.signature = Signature(None) + blob.textsignature = TextSignature(None) blob.references = None blob.validate() titles = [s.title for s in blob.arbitrary if s.title] @@ -1533,13 +1537,14 @@ def prepare_doc_for_one_object( item_type = str(type(target_item)) if blob.content["Signature"]: - blob.signature = Signature(blob.content.pop("Signature")) + blob.textsignature = TextSignature(blob.content.pop("Signature")) else: assert blob is not None assert api_object is not None - blob.signature = Signature(api_object.signature) + blob.textsignature = TextSignature(str(api_object.signature)) del blob.content["Signature"] + self.log.debug("%r", blob.textsignature) if api_object.special("Examples"): # warnings this is true only for non-modules @@ -1814,11 +1819,9 @@ def helper_1( "module", item_docstring, None, target_item.__name__, qa ) elif isinstance(target_item, (FunctionType, builtin_function_or_method)): - sig: Optional[str] + sig: Optional[ObjectSignature] try: - sig = str(ObjectSignature(target_item)) - # sig = qa.split(":")[-1] + sig - # sig = re.sub("at 0x[0-9a-f]+", "at 0x0000000", sig) + sig = ObjectSignature(target_item) except (ValueError, TypeError): sig = None try: @@ -1957,6 +1960,7 @@ def collect_api_docs(self, root: str, limit_to: List[str]): qa=qa, target_item=target_item, ) + self.log.debug("%r", api_object) if ecollector.errored: if ecollector._errors.keys(): self.log.warning( @@ -2086,6 +2090,8 @@ def collect_api_docs(self, root: str, limit_to: List[str]): doc_blob.validate() except Exception as e: raise type(e)(f"Error in {qa}") + self.log.debug(doc_blob.textsignature) + self.log.debug(doc_blob.to_dict()) self.put(qa, doc_blob) if figs: self.log.debug("Found %s figures", len(figs)) diff --git a/papyri/html.tpl.j2 b/papyri/html.tpl.j2 index c4b52eb4..03b90a9e 100644 --- a/papyri/html.tpl.j2 +++ b/papyri/html.tpl.j2 @@ -30,13 +30,13 @@ -{% if doc.signature.value -%} - {{doc.signature.value}} +{% if doc.textsignature.value -%} + {{name}}{{doc.textsignature.value}} {%- endif -%} {%- for section in doc.content.keys() if doc.content[section] -%} - {% if (section not in ['Extended Summary','Signature', 'Summary']) and len(doc.content[section]) > 0 -%} + {% if (section not in ['Extended Summary','TextSignature', 'Summary']) and len(doc.content[section]) > 0 -%}

{{section}}

{% endif -%} {% if section in ['Extended Summary', 'Summary', 'Notes'] -%} diff --git a/papyri/render.py b/papyri/render.py index 94c7e907..1f71602d 100644 --- a/papyri/render.py +++ b/papyri/render.py @@ -576,6 +576,7 @@ def render_one( qa=qa, version=meta["version"], module=qa.split(".")[0], + name=qa.split(":")[-1].split(".")[-1], backrefs=backrefs, parts=parts, parts_links=parts_links, diff --git a/papyri/take2.py b/papyri/take2.py index 50016965..734a103e 100644 --- a/papyri/take2.py +++ b/papyri/take2.py @@ -236,7 +236,7 @@ def from_untrusted(cls, module, version, kind, path): @register(4011) -class Signature(Node): +class TextSignature(Node): value: Optional[str] diff --git a/papyri/tests/test_gen.py b/papyri/tests/test_gen.py index 25cc834d..94b6943d 100644 --- a/papyri/tests/test_gen.py +++ b/papyri/tests/test_gen.py @@ -95,3 +95,16 @@ def test_numpy(module, submodules, objects): for o in objects: assert (td / "module" / f"{o}.json").exists() + + +def test_self(): + from papyri.gen import Gen, Config + + c = Config(dry_run=True, dummy_progress=True) + g = Gen(False, config=c) + g.collect_package_metadata("papyri", ".", {}) + g.collect_api_docs("papyri", {"papyri.examples:example1"}) + assert g.data["papyri.examples:example1"].to_dict()["textsignature"] == { + "type": "TextSignature", + "value": "(pos, only, /, var, args, *, kwargs, also=None)", + }