-
-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link partially qualified identifiers when documenting single module #544
Conversation
Regarding this, I created a new branch from main and modified a docstring in the Here is the new docstring: # test/testdata/demopackage/child_c.py
class C(child_b.B):
"""This class is defined in .child_c and inherits from .child_b.B
Here's an identifier that isn't enclosed in back ticks: demopackage.child_b.B
"""
def c(self):
return 2 And this is what pdoc generated: From what I can see, linkify is being called from a macro in the I'm not sure if this is intentional behaviour, since the pdoc API docs state that you can enclose references in backticks, not that you must. However, it is certainly unexpected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR and sorry for letting it sit so long! 🙈
Honestly I'm not a big fan of this change - I feel this muddies the waters on what an absolute and what a relative identifier is. I really appreciate your work on markdown2 though, so I'd like to accomodate your use case if somehow possible.
As an alternative, how would you feel about making relative links start with .
or ..
? For example, you'd write Do `.helpers.something` with a `.types.BigThing`.
. That'd be a bit more complex to implement, but at least it's not ambiguous.
No worries! Apologies for the delay in getting back to you.
Yep, that makes alot more sense actually. I've updated the branch to only link partially qualified names if the name is prefixed with |
…package This is particularly useful when documenting a single package with an inconveniently long name
12de851
to
9988ab6
Compare
Thanks for keeping this up-to-date. I don't have the capacity to review this thoroughly at the moment, but I will get back to this once I have a bit of time for pdoc again. :) |
Thanks for waiting so patiently! I've now had a chance to look at the implementation more closely and tweak some things. Let me know if that looks good from your end, and I'll be happy to merge things and ship a pdoc release right after. 😃 |
Is the intention to only do relative links if the link starts with There are a few instances in the
Debugging this, when the code gets to It seems that Edit: Perhaps stripping the current module name from the |
If we are in module I'll look into the issues you mentioned momentarily. :) |
Thanks! Your review caught an importan bug, I was testing from Looking better now? |
Thanks for the thorough testing! This is a really useful collaboration. 🍰 |
All the links in |
Currently, to link to another identifier using pdoc, the item in question must either be part of the current file or you must give the fully qualified name, including the module name.
This is very inconvenient when documenting a single module with a long name. For example:
This PR changes the
possible_sources
function inrender_helpers.py
to check if every module name inall_modules
starts with the same top-level package name. For example, the following list shares the top-level module name ofmy_long_module_name
:If a common, global package name can be identified and the
identifier
does not start with this package name, the package name is prefixed to the identifier.This means that
helpers.something
from earlier will becomemy_long_module_name.helpers.something
, allowing thea()
function to have the intended link put in.This does change how some existing code is rendered. The
demopackage._child_c.C
docstring in thedemopackage
test used to say...inherits from .child_b.B
but now will be auto-linked as...inherits from .<a href="#B">demopackage.B</a>
.This docstring doesn't contain any links so it seems like a bug that it's being linkified in the first place, but I'd like to know your thoughts.