-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Waiting for review: Add get_members function to apidoc templates (better_apidoc backport) #6768
Conversation
ef88b64
to
cd07183
Compare
This is a backwards-compatible feature addition on However, it appears that currently no |
cd07183
to
61a8f38
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
||
.. data:: basename | ||
|
||
An alias for :data:`qualname`. |
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.
This documentation matches what is currently implemented. Most likely, it's not what was intended, however. I would assume that qualname
should be the fully qualified name of the module (with dots), whereas basename
should only be the part after the last dot. I'll leave fixing this for another PR, though, after this is merged in.
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.
The alternative would be for me to change the documentation of basename
to "The part of the :data:qualname
after the last dot". This would knowingly create my definition of a "bug" (a mismatch between documentation and behavior). If your preferred definition of "bug" is "mismatch between obvious intent and behavior", on the other hand, we can leave this for now.
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.
I guess "qualname" came from PEP-3155's __qualname__
. It is a relative path from its module. It was introduced mainly for nested classes.
https://www.python.org/dev/peps/pep-3155/
Accessing module members in templates | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. versionadded:: 2.3 |
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.
This assumes the PR will be merged and released in v2.3 (the next feature release). Otherwise, this will have to be adjusted.
61a8f38
to
6ef7411
Compare
947fcb8
to
65e707f
Compare
This is now ready for review/merging @tk0miya |
b8e4c92
to
f5f4c97
Compare
The `module.rst_t` and `package.rst_t` templates used by apidoc now have a `get_members` function that allows to obtain the member of the current module or package in various forms and filtered by "type" (exception, class, function, data). This provides a powerful mechanism for writing more advanced templates. Specifically, it allows to generate structured summaries of the contents of a module, preceding the detailed `automodule` references. See https://krotov.readthedocs.io/en/stable/API/krotov.html for an example. Extensive documentation of all the templating capabilities is included in the apidoc man page in the documentation. This functionality is a backport of the "better-apidoc" package (https://github.com/goerz/better-apidoc).
f5f4c97
to
4c29279
Compare
@tk0miya Is there any chance you could review and merge this in the near future? I'd really love to have this in the next release, so that I can start some new projects that don't depend on my |
So it looks like 2.3 and 2.3.1 were released without this PR. Is there any interest in merging this? I'll have to modify the patch to fix the |
eagerly waiting for this merge. |
OMG, I must apologize you not to review this. I'll do it within a week. Please wait a moment. Thanks, |
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.
I'm very sorry to late response. I'd missed your ping so long
I feel this is too complex. It seems the responsibility of this function is listing attributes, filtering, formatting and so on. I can understand some people want to "hack" apidoc. And this would be helpful to them because this is very programatic. But it is hard to use and maintain to me.
I don't say this is rejected. I agreed current apidoc is poor. So improvement is still needed.
|
||
.. data:: basename | ||
|
||
An alias for :data:`qualname`. |
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.
I guess "qualname" came from PEP-3155's __qualname__
. It is a relative path from its module. It was introduced mainly for nested classes.
https://www.python.org/dev/peps/pep-3155/
I don't see how this can move forward then, unless you can think of any way to make it less complex while maintaining the functionality. So probably the only option for me is to maintain this as a permanent hard fork of apidoc (probably under a better name than the original |
I would hate to see the idea dropped of adding the functionality of better-apidoc. |
Any thoughts on reaching a middle-ground, or compromise here? Proposal 1 (Ultra Simple)How about simplifying this to just include a Proposal 2 (Less Simple)Alternatively, What about keeping a Formatting could be handled by users if they have access to Proposal 3? |
Hi Michael (@goerz) -- is this PR no longer required? I missed the reason for closing, sorry. Thanks, |
It’s not going to be merged, and I have switched from Python to Julia for all my work, so why keep it open? |
This make a
get_members
function available to themodule.rst_t
andpackage.rst_t
templates used byapidoc
. This function allows to obtain the members of the current module or package in various forms and filtered by "type" (exception, class, function, data).Building upon the recent addition of templating to
apidoc
in v2.2, this is a backport of https://github.com/goerz/better-apidocThe original motivation for
better-apidoc
was that I findapidoc
's default template to be extremely hard to navigate for modules with a lot of members, see #3545. I strongly prefer to have a summary/table of contents at the beginning of each module's documentation that lists all the members of the module, and specifies which members are available through__all__
Examples of projects that use such a format (currently using
better-apidoc
, but possible with the features added in this PR):The
get_members
function provided in the PR provides an extremely powerful mechanism for custom templates. Thebetter-apidoc
project has had a long gestation period, and has undergone several iterations over the last few years. Based on my experience of using it in a number of projects like the ones linked above, I am fully confident that the functionality provided in this PR can be considered stable. I will be available to maintain this part ofapidoc
going forward.Within a template,
get_members
can be used e.g. as follows:The lists
{{ members }}
,{{ all }}
etc. are then available in the remainder of the template.There is extensive further documentation and examples for the templating features in
apidoc
, both of those added inv2.2
(which were largely undocumented) and for theget_members
function added in this PR. This documentation is in theapidoc
man page. The PR includes tests with full coverage of the new features.