Skip to content
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

Add tests, add docstrings, and fix small bugs #28

Merged
merged 12 commits into from
Dec 15, 2022

Conversation

consideRatio
Copy link
Member

@consideRatio consideRatio commented Dec 11, 2022

I've worked to understand, document, test, and fix smaller bugs I found.

About tests

The tests/docs folder contains a sphinx project with examples used in the tests, which are overall simple should provide quite good coverage. They ensure that the sphinx directives are executed in various situations without warnings, and render .html strings of relevance.

It could have made sense to not render all the way to .html, but instead for example inspect the rST emitted by the directives somehow - but as I didn't knew how to do that I went for this end-to-end like test which probably is a good starting point to have for anyone looking to rework this further.

About small bugs

About documentation

Understanding autodoc_traits requires understanding of details of how sphinx.ext.autodoc works internally, which lacks documentation. Due to that I've invested a lot of time to help my future self and other contributors understand autodoc_traits by providing relevant references to sphinx source code and comments to summarize the important parts.

Notes for review

I've probably invested ~16-24 hours into this. It took quite a while to onboard myself as I had to learn from comments in the sphinx source code to understand how things worked in more detail.

I ended up adding multiple labels to this PR as it was quite extensive, which will make it show up in multiple categories if github-activity is used. A lot of the refactoring was very relevant documenting, but some refactoring also led to bugfixes etc.

@consideRatio consideRatio force-pushed the pr/refresh-and-add-tests branch from d6cff3c to 1acc764 Compare December 11, 2022 00:51
@consideRatio consideRatio added bug Something isn't working documentation Improvements or additions to documentation maintenance labels Dec 11, 2022
@consideRatio consideRatio force-pushed the pr/refresh-and-add-tests branch from 1acc764 to 5747e4b Compare December 11, 2022 01:05
@consideRatio consideRatio requested a review from minrk December 11, 2022 01:07
@consideRatio consideRatio changed the title maint, fixes: add tests, add docstrings, fix small bugs Add tests, add docstrings, and fix small bugs Dec 12, 2022
Copy link
Member

@minrk minrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is truly wonderful, thanks for putting in all the effort!

Looking through the examples, I think we want to be able to support these cases:

  1. document all config options on the class, but no Python and no inheritance (I think this is what autoconfigurable without members does now)
  2. document all config options including inherited config, still without Python APIs (I think this is infeasible because :inherited-members: also pulls in Python members, so you'd have to identify and manually exclude all non-configurable members, right?

Maybe the answer is to not use :inherit-members:, and instead define a new option like :inherit-config-members:. I'm not sure about needing a :config-members: equivalent to :members:, because autoconfigurable doesn't make any sense if you aren't going to document any configurable traits, since that's just the same output as autoclass, right?

I don't think you need to address these things here, because what you have is already a massive improvement. I think having these wonderful examples and illustrations merely reveals that these are cases we should think about. So maybe it should be an Issue. Then again, nobody's asked for the inherit-config-but-not-python case, so maybe it doesn't matter.

pyproject.toml Outdated Show resolved Hide resolved
tests/docs/test_module.py Outdated Show resolved Hide resolved
tests/README.md Outdated Show resolved Hide resolved
tests/docs/source/autoclass/undoc_members.rst Show resolved Hide resolved
tests/docs/source/conf.py Outdated Show resolved Hide resolved

.. autoconfigurable:: test_module.TestConfigurableSubclass
:noindex:
:inherited-members:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to set :inherited-members: traitlets.HasTraits, since the documentation suggests this should exclude methods inherited from this class, but it doesn't seem to work.

I've tried it on autoclass without autodoc-traits, and :inherited-members: parent.Class seems to simply not do what it says.

Copy link
Member Author

@consideRatio consideRatio Dec 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall reading upstream sphinx source code and noting its used as a boolean flag rather than a list of members.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HMmm, what version of sphinx was used? See sphinx-doc/sphinx#10325 added for sphinx 5.0

Copy link
Member

@minrk minrk Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5.3.0. Not our problem, for now. It seems like it will be desirable pretty often for documenting inheritors of HasTraits, which has a lot of methods.

tests/docs/source/autoconfigurable/no_members.rst Outdated Show resolved Hide resolved
tests/docs/source/index.rst Show resolved Hide resolved
@minrk
Copy link
Member

minrk commented Dec 14, 2022

Actually, now that I think about it, the inherited-members being backwards means we've always been showing inherited config and never showing just on-class. This is the case in jupyterhub, because log_level is inherited from base Application and is documented. I think that's probably what folks usually want, so maybe it is important to keep it working, and maybe even still be the default.

What do you think is the best way to signal that?

@minrk
Copy link
Member

minrk commented Dec 14, 2022

Sorry for mixed messages - that doesn't mean I think it needs to block this PR, but I think it does mean we need to open an Issue about it that blocks release so we can make an explicit decision about it.

The current behavior before and after the PR adding this commit, is that
also the inherited configurable traitlets will be presented. This commit
make us test against a class with inherited configurable traitlets to
clarify that.
@consideRatio
Copy link
Member Author

consideRatio commented Dec 14, 2022

@minrk I've addressed all comments, either by adding commits or commenting. On my end, this is ready for a merge but are pinging you to re-review added commits.

@minrk minrk merged commit 1e435fe into jupyterhub:main Dec 15, 2022
@minrk
Copy link
Member

minrk commented Dec 15, 2022

This is terrific, great work!

@consideRatio
Copy link
Member Author

Thanks for reviewing this @minrk!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation maintenance
Projects
None yet
2 participants