You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You'll soon be able to beta-test @ofek! But first I could use your input!
I can think of several ways to select or unselect members:
exact matches (name)
regular expressions (name)
filtering functions (properties)
I'd like to find an elegant way to address all these possibilities, to have something powerful but not too complex, and easy to configure and reason about.
With the new architecture, selection options will be written as YAML, under the selection key:
::: my.python.object
selection:
here_goes: "my_option"
and_what:
- not
Ofek's link leads to a Markdown file formatted with mkautodoc, so…
How about plainly stealing mkautodoc's :members: directive? No regular expressions, no include/exclude mechanism, no smarts… Just a "manual mode" switch first?
Adapted to fit the YAML style here:
.. Include all members:
::: BankAccount
members:
.. Include only a manual selection of members:
::: BankAccount
members: number get_balance compute_vat
(Note the non-usage of a YAML array, as it would consume a lot of vertical space…)
Besides, since we're using YAML, I'd would prefer we stick to it. Otherwise we start doing implicit split(" ") and it's an open door to more implicit things which then become hard to maintain 😕
Note that in YAML you can still write arrays on one line:
I'm definitely in favor of a members option, whether it's yaml or not doesn't make too much difference, but I especially want to be able to exclude certain members that maybe I didn't create and are inherited from a module's superclass, for example. (__json_encoder__ from a Pydantic model with custom config, is what I'm dealing with at the moment)
Would the members solution mean that filters would not be available? E.g. would love to filter out private methods (which seem to be included by default in the newest release) without having to manually update the function list often. However not a dealbreaker if not, thank you very much for the great updates!
in mkdocstrings, add the filters selection option to reflect pytkdocs filtering, and add a members option as well.
If members is a list of strings, discard global and local filters, translate the list to exact-match filters internally.
If members is yes, use local or global filters to allow fine-grained selection.
If members is no, select nothing.
Example:
# mkdocs.ymlplugins:
- mkdocstrings:
selection:
# include all members by defaultmembers: yesfilters:
# but exclude private members
- name: "^_[^_]"select: no
# Reference file ::: pkg.mod.obj1selection:
# explicit selectionmembers:
- member1
- member2
- etc::: pkg.mod.obj2selection:
# no members at allmembers: no::: pkg.mod.obj3selection:
# global members = yes# cancel global filters to include private members as wellfilters: []
I think it covers most use-cases?
TODO (if it sounds good):
implement this filtering in pytkdocs
allow setting global selection and rendering options directly inside mkdocstrings' config (not just under mkdocstrings: handlers: <default_handler>: selection)
add filters and members option to the Python collector, with respective handling
set a default global filter to exclude private members in the Python collector options (to replicate what was previously done 😅)?
Reacted by Stephen Brown II, Ofek Lev and Christoph Rieke
It turned out to be much, much more complex than I thought. So I kept things simple and I made progress: pytkdocs itself will accept members and filters options. members can be True, False, or a list of names to select. If it's a list of names, we don't apply filters on the top object's members. We still apply filters recursively, on all selected members and their children. Filters are regular expressions, and can (re)select or unselect (when starting with !) objects, so their order matters.
It's not as powerful as I wanted it to be, but who cares if the use-cases are covered 🙂
Activity
pawamoy commentedon Feb 12, 2020
It is not currently possible, but definitely planned!
I'll add a roadmap to the readme to give a better idea of what I'm planning for mkdocstrings :)
ofek commentedon Feb 12, 2020
Thank you, please let me know if I can help or beta test!
pawamoy commentedon Mar 18, 2020
You'll soon be able to beta-test @ofek! But first I could use your input!
I can think of several ways to select or unselect members:
I'd like to find an elegant way to address all these possibilities, to have something powerful but not too complex, and easy to configure and reason about.
With the new architecture, selection options will be written as YAML, under the
selectionkey:What do you have in mind?
ofek commentedon Mar 22, 2020
I suppose regex is most elegant since they can also represent exact matches
pawamoy commentedon Mar 22, 2020
I personally need to filter out modules in
mkdocstringsitself, so I was also thinking about something like:Maybe a filter could be a dict?
ofek commentedon Mar 22, 2020
Seems verbose, though cc @florimondmanca for feedback
florimondmanca commentedon Mar 22, 2020
Oh hi 😄
Ofek's link leads to a Markdown file formatted with
mkautodoc, so…How about plainly stealing mkautodoc's
:members:directive? No regular expressions, no include/exclude mechanism, no smarts… Just a "manual mode" switch first?Adapted to fit the YAML style here:
(Note the non-usage of a YAML array, as it would consume a lot of vertical space…)
Thoughts? :-)
pawamoy commentedon Mar 22, 2020
I'd argue the opposite: long lines are hard to read and generate noise in code diffs 😕
I largely prefer
over
Besides, since we're using YAML, I'd would prefer we stick to it. Otherwise we start doing implicit
split(" ")and it's an open door to more implicit things which then become hard to maintain 😕Note that in YAML you can still write arrays on one line:
Anyway, I think it's wise to start simple, with a
membersoption and maybeexclude_membersas well.florimondmanca commentedon Mar 22, 2020
Sounds good to me @pawamoy!
StephenBrown2 commentedon Mar 24, 2020
I'm definitely in favor of a
membersoption, whether it's yaml or not doesn't make too much difference, but I especially want to be able to exclude certain members that maybe I didn't create and are inherited from a module's superclass, for example. (__json_encoder__from a Pydantic model with custom config, is what I'm dealing with at the moment)chrieke commentedon Mar 24, 2020
Would the members solution mean that filters would not be available? E.g. would love to filter out private methods (which seem to be included by default in the newest release) without having to manually update the function list often. However not a dealbreaker if not, thank you very much for the great updates!
pawamoy commentedon Mar 24, 2020
Here's what I'm thinking doing:
pytkdocs, implement powerful filtering like in the last code snippet of this comment Allow the explicit selection of members #44 (comment)mkdocstrings, add thefiltersselection option to reflectpytkdocsfiltering, and add amembersoption as well.membersis a list of strings, discard global and local filters, translate the list to exact-match filters internally.membersisyes, use local or global filters to allow fine-grained selection.membersisno, select nothing.Example:
I think it covers most use-cases?
TODO (if it sounds good):
pytkdocsselectionandrenderingoptions directly insidemkdocstrings' config (not just undermkdocstrings: handlers: <default_handler>: selection)filtersandmembersoption to the Python collector, with respective handlingStephenBrown2 commentedon Mar 24, 2020
Sounds good to me! 👍
pawamoy commentedon Mar 26, 2020
It turned out to be much, much more complex than I thought. So I kept things simple and I made progress:
pytkdocsitself will acceptmembersandfiltersoptions.memberscan beTrue,False, or a list of names to select. If it's a list of names, we don't apply filters on the top object's members. We still apply filters recursively, on all selected members and their children. Filters are regular expressions, and can (re)select or unselect (when starting with!) objects, so their order matters.It's not as powerful as I wanted it to be, but who cares if the use-cases are covered 🙂
Also changes were minimal 👍
ofek commentedon Mar 27, 2020
Yay! Can we try it yet?
pawamoy commentedon Mar 27, 2020
You can now 🙂 I just released version 0.10.0. And I forgot to implement the second point of the checklist above 😕 Will do in the next one!
To filter out private members (which is now the default again):
Or globally in
mkdocs.yml:To explicitly select members:
To select no members at all:
Keep in mind that even when explicitly selecting members, filters will be applied to their children.
ofek commentedon Mar 28, 2020
Nice, thanks!!! Found a few things:
#64
#65