Skip to content

Allow the explicit selection of members #44

Closed

Description

@ofek

Often, you'll only want to document a subset of methods & attributes. For example: https://raw.githubusercontent.com/DataDog/integrations-core/hack-a-doc/docs/developer/base/api.md

Is that possible currently? If so, we'll switch to this from mkautodoc 😄

cc @pawamoy

Activity

  1. pawamoy commented on Feb 12, 2020

    @pawamoy
    Member

    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 :)

  2. ofek commented on Feb 12, 2020

    @ofek
    ContributorAuthor

    Thank you, please let me know if I can help or beta test!

  3. added
    config
    feature
    on Feb 18, 2020
  4. pawamoy commented on Mar 18, 2020

    @pawamoy
    Member

    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
    

    What do you have in mind?

  5. ofek commented on Mar 22, 2020

    @ofek
    ContributorAuthor

    I suppose regex is most elegant since they can also represent exact matches

  6. pawamoy commented on Mar 22, 2020

    @pawamoy
    Member

    I personally need to filter out modules in mkdocstrings itself, so I was also thinking about something like:

    ::: mkdocstrings.handlers
        selection:
          recurse_on:
            modules: no
    

    Maybe a filter could be a dict?

    filters:
      - categoy: module
        select: no
      - property:
          - private
          - special
        select: no
      - category: method
        name: "^__init__$"
        select: yes
  7. ofek commented on Mar 22, 2020

    @ofek
    ContributorAuthor

    Seems verbose, though cc @florimondmanca for feedback

  8. florimondmanca commented on Mar 22, 2020

    @florimondmanca
    Contributor

    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:

    .. 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…)

    Thoughts? :-)

  9. pawamoy commented on Mar 22, 2020

    @pawamoy
    Member

    (Note the non-usage of a YAML array, as it would consume a lot of vertical space…)

    I'd argue the opposite: long lines are hard to read and generate noise in code diffs 😕

    I largely prefer

    ::: datadog_checks.base.stubs.aggregator.AggregatorStub
        selection:
          members:
            - assert_metric
            - assert_metric_has_tag
            - assert_metric_has_tag_prefix
            - assert_service_check
            - assert_event
            - assert_all_metrics_covered
            - assert_no_duplicate_metrics
            - assert_no_duplicate_service_checks
            - assert_no_duplicate_all
            - reset

    over

    ::: datadog_checks.base.stubs.aggregator.AggregatorStub
        selection:
          members: assert_metric assert_metric_has_tag assert_metric_has_tag_prefix assert_service_check assert_event assert_all_metrics_covered assert_no_duplicate_metrics assert_no_duplicate_service_checks assert_no_duplicate_all reset

    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:

    ::: datadog_checks.base.stubs.aggregator.AggregatorStub
        selection:
          members: [assert_metric, assert_metric_has_tag, assert_metric_has_tag_prefix, assert_service_check, assert_event, assert_all_metrics_covered, assert_no_duplicate_metrics, assert_no_duplicate_service_checks, assert_no_duplicate_all, reset]

    Anyway, I think it's wise to start simple, with a members option and maybe exclude_members as well.

  10. florimondmanca commented on Mar 22, 2020

    @florimondmanca
    Contributor

    Sounds good to me @pawamoy!

  11. StephenBrown2 commented on Mar 24, 2020

    @StephenBrown2
    Contributor

    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)

  12. chrieke commented on Mar 24, 2020

    @chrieke

    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!

  13. pawamoy commented on Mar 24, 2020

    @pawamoy
    Member

    Here's what I'm thinking doing:

    • in pytkdocs, implement powerful filtering like in the last code snippet of this comment Allow the explicit selection of members #44 (comment)
    • 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.yml
    
    plugins:
    - mkdocstrings:
        selection:
          # include all members by default
          members: yes
          filters:
            # but exclude private members
            - name: "^_[^_]"
              select: no
    # Reference file 
    
    ::: pkg.mod.obj1
        selection:
          # explicit selection
          members:
            - member1
            - member2
            - etc
    
    
    ::: pkg.mod.obj2
        selection:
          # no members at all
          members: no
    
    
    ::: pkg.mod.obj3
        selection:
          # global members = yes
          # cancel global filters to include private members as well
          filters: []

    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 😅)?
  14. StephenBrown2 commented on Mar 24, 2020

    @StephenBrown2
    Contributor

    Sounds good to me! 👍

  15. pawamoy commented on Mar 26, 2020

    @pawamoy
    Member

    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 🙂

    Also changes were minimal 👍

  16. ofek commented on Mar 27, 2020

    @ofek
    ContributorAuthor

    Yay! Can we try it yet?

  17. pawamoy commented on Mar 27, 2020

    @pawamoy
    Member

    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):

    ::: pkg.mod.obj
        selection:
          filters:
            - "!^_[^_]"
    

    Or globally in mkdocs.yml:

    plugins:
      - mkdocstrings:
          handlers:
            python:
              selection:
                filters:
                  - "!^_[^_]"
    

    To explicitly select members:

    ::: pkg.mod.obj
        selection:
          members:
            - hello
            - world
    

    To select no members at all:

    ::: pkg.mod.obj
        selection:
          members: no
    

    Keep in mind that even when explicitly selecting members, filters will be applied to their children.

  18. ofek commented on Mar 28, 2020

    @ofek
    ContributorAuthor

    Nice, thanks!!! Found a few things:

    #64
    #65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    configfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions