Skip to content

Commit

Permalink
Don't store a file for dynamically generated item.
Browse files Browse the repository at this point in the history
We try to detect where a item was define, sometime methods/objects are
dynamically defined.

When this is the case, we get back a file that contain `<string>` in
it's name. When that's the case we store `None` instead.

I'm wondering if we should store something else, as `None` also mean we
were not able to find what the source was...
  • Loading branch information
Carreau committed Nov 16, 2023
1 parent dcc330c commit aae25f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion papyri/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,9 @@ def _transform_2(self, blob: DocBlob, target_item, qa: str) -> DocBlob:
# try to find relative path WRT site package.
# will not work for dev install. Maybe an option to set the root location ?
item_file = find_file(target_item)
if item_file is not None and item_file.endswith("<string>"):
# dynamically generated object (like dataclass __eq__ method
item_file = None
r = qa.split(".")[0]
if item_file is not None:
for s in SITE_PACKAGE + [
Expand All @@ -1449,7 +1452,6 @@ def _transform_2(self, blob: DocBlob, target_item, qa: str) -> DocBlob:
]:
if item_file.startswith(s):
item_file = item_file[len(s) :]

blob.item_file = item_file
if item_file is None:
if type(target_item).__name__ in (
Expand Down
7 changes: 6 additions & 1 deletion papyri/tests/test_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,15 @@ def test_self_2():
c = Config(dry_run=True, dummy_progress=True)
g = Gen(False, config=c)
g.collect_package_metadata("papyri", ".", {})
g.collect_api_docs("papyri", {"papyri"})
g.collect_api_docs(
"papyri", {"papyri", "papyri.take2:RefInfo", "papyri.take2:RefInfo.__eq__"}
)
assert (
g.data["papyri"].to_dict()["arbitrary"][4]["children"][1]["children"][0]["dt"][
"children"
][0]["reference"]["module"]
== "dask"
)

assert g.data["papyri.take2:RefInfo"].to_dict()["item_file"] == "papyri/take2.py"
assert g.data["papyri.take2:RefInfo.__eq__"].to_dict()["item_file"] is None

0 comments on commit aae25f2

Please sign in to comment.