-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: add automatic RST generator for internal API docs #293
feat: add automatic RST generator for internal API docs #293
Conversation
This commit adds functionality to automatically generate .rst files for internal API documentation, addressing tpvasconcelos#290. Changes include: - Add script to automatically generate RST files - Support hierarchical module structure - Maintain consistent module descriptions - Add basic tests for core functionality The script detects all internal modules and generates appropriate .rst files with consistent formatting and structure.
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 submitting your first pull request with us! 🎉
Our response times may vary, but we'll get back to you as soon as we can!
To help us help you, please make sure you have ticked all the boxes in the pull request template.
Welcome aboard! 🚀
…nternal_api_rst.py This PR fixes two issues: Sets the correct executable permissions for the generate_internal_api_rst.py script to ensure it runs properly in the CI/CD pipeline. Resolves issues in test_generate_internal_api_rst.py. Changes: Set executable permissions for generate_internal_api_rst.py. Updated test_generate_internal_api_rst.py to resolve related issues. Testing: Ensure the script runs without permission errors in the CI/CD pipeline. Verify that tests pass successfully.
28b7e87
to
5188dba
Compare
for more information, see https://pre-commit.ci
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.
Thanks a lot for your contribution @imprvhub!
I haven't had the time to properly go through your solution yet but let me leave a few first-pass comments:
-
could you add this to the sphinx build step? We already have one or two custom steps (eg for regenerating the example plots) so you could just copy and adapt for the function you need to call
-
since these will not be automatically generated during the build step, you can remove them from git and add an entry to gitignore (eg
docs/api/internal/
) -
instead of iterating through the python files and local directory tree, I would suggest iterating through the installed package using a standard utility like pkgutil. For instance:
import ridgeplot import pkgutil for _, module_name, is_package in pkgutil.iter_modules(ridgeplot.__path__): # ...
-
I think I like your idea of having a simple dictionary with short descriptions, however I think I would prefer defaulting to adding these short descriptions as module docstrings and only using the dictionary for overriding this default behaviour (e.g. if the module's docstrings is too long for instance)
If some of the comments don't seem to make sense or you think that I somehow misread your implementation/intention here, don't worry too much about it because I'm looking at this on my phone so let me take a proper look at this in the coming days 😁
Again, thanks a lot for wanting to help! I really appreciate it 🙏🏽
@imprvhub this is what I mean by adding this as a build hook in Sphinx: https://github.com/tpvasconcelos/ridgeplot/blob/main/docs/conf.py#L394-L395 But you'll probably need to use a different target event name since this needs to happen before the build step I guess |
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.
Btw some CI checks are failing.
If you find it easier to iterate and test things locally, take a look at: https://ridgeplot.readthedocs.io/en/latest/development/contributing.html#development-environment
tests/cicd_utils/test_scripts/test_generate_internal_api_rst.py
Outdated
Show resolved
Hide resolved
tests/cicd_utils/test_scripts/test_generate_internal_api_rst.py
Outdated
Show resolved
Hide resolved
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.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.
Btw I added Copilot as a "reviewer" because I literally just got access to this new feature and I'm interested in how well/not-so-well it works. So please feel free to completely ignore its comments if you want 😉 |
- Added `.gitignore` entry to exclude `docs/api/internal/` from version control. - Refactored `generate_internal_api_rst.py`: - Improved module scanning logic for internal API documentation. - Enhanced docstring parsing for better description generation. - Added `test_generate_internal_api_rst.py` for coverage of: - Module organization. - RST content generation for internal modules. Pending improvements: - Integration with Sphinx build step (`conf.py`). - Transition to `pkgutil` for module iteration.
for more information, see https://pre-commit.ci
- Adjusted file permissions for `tests/cicd_utils/test_scripts/test_generate_internal_api_rst.py` to remove executable flag. - Applied `chmod -x` to correct invalid or unnecessary file attributes. This change ensures compliance with standard file permission practices for test scripts.
Hey @tpvasconcelos! 👋 Thanks for the detailed review and suggestions! I've implemented most of your feedback in this commit. About the remaining suggestions:
Most tests are passing locally (they are quite thorough! 😅), but I wanted to get your thoughts before making more changes. Thanks again for the opportunity to contribute! Let me know if you'd like me to adjust anything else. |
Added entry to docs/reference/changelog.md to pass peter-evans documentation check. Documents the automatic RST file generation feature.
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.
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
Signed-off-by: Tomas Pereira de Vasconcelos <tomasvasconcelos1@gmail.com>
Hey @imprvhub ! Just tried to run this locally and the docs are currently not rendering properly for me. I think that this is due to two issues:
Let me know if you'd like me to take a closer look or whether you want to try to fix this yourself first! 👍 Btw I pushed a couple of commits to remove the current API docs from git and add your function as a hook to automatically rebuild the pages every time the docs are built. |
- Add missing underscore prefix for private modules in `automodule` directives (e.g., `ridgeplot._figure_factory` instead of `ridgeplot.figure_factory`). - Correct `toctree` definitions to include the `_package/` prefix for nested packages. - Update internal API docs to preserve underscore prefixes in paths. - Adjust `organize_modules` hierarchy tests to reflect updated path expectations.
for more information, see https://pre-commit.ci
- Adjusted file permissions for `tests/cicd_utils/test_scripts/test_generate_internal_api_rst.py` to remove executable flag. - Applied `chmod -x` to correct invalid or unnecessary file attributes. This change ensures compliance with standard file permission practices for test scripts.
Hi @tpvasconcelos, Thanks for the feedback! I’ve made the changes you mentioned: • Added the underscore prefix for private modules in the automodule directives. I’ve tested these changes locally, and it seems to be working well here--though, I can’t promise it’ll pass all the tests just yet. Anyway, it might be worth giving it a shot on your local environment to see if the .rst files are generated correctly according to your expectations. Hopefully, it’ll work better for you too! Let me know how it goes, and thanks again for your help! 👍 |
Hey @imprvhub for some reason I still can't render the docs properly on my machine. Could you share a screenshot of what you see on your end? I still see the private modules without the leading underscore: and the inner packages do now show their children: I also still see this in my terminal output: Let me know if you'd like me to take a look at it 👍 |
@tpvasconcelos Let me clarify what I'm showing in the screenshots: • In the first terminal output, you can see the list of all generated RST files with their proper names including underscores Perhaps I misunderstood how you'd like the RST files to be generated or structured. Could you point out anything specific that looks incorrect? I'm happy to work on adjustments if needed. 👍 |
@imprvhub in the PR's description you will notice a link at the bottom that is automatically generated by our CI pipeline that renders the docs for your branch. If you navigate to https://ridgeplot--293.org.readthedocs.build/en/293/api/index.html you can see what I mean. If you want to iterate locally to try to fix the issue, you can run the following in your terminal: tox -e docs-static If you have any issues getting this to run on your local development environment, please take a look at our contributing docs. |
@imprvhub take a look at a different approach using sphinxcontrib.apidoc here --> #296 I think that this approach is simpler and more reliable than what we are trying to do here. One thing missing from that approach is a nice way to render a similar toc-tree for the internal packages, but maybe we can think of a different solution/approach. I'll sleep on this and try to see if I can think of a better solution. Feel free to take a look at it in the meantime :) |
@tpvasconcelos Thanks for pointing this out! Sounds promising - sphinxcontrib.apidoc seems to offer a more reliable approach. It's quite valuable in open source projects when we can explore different approaches to find the best solution together. I'll make sure to dedicate the necessary time to analyze sphinxcontrib.apidoc in depth and see how we can adapt it to generate that toc-tree you mentioned for internal packages. In the meantime, feel free to share any additional thoughts or improvements you come up with. Thanks for your patience and guidance! 👍
|
@imprvhub sphinx-apidoc doesn't solve all the issues that I have encountered when trying to streamline the maintenance work around the API docs but it does solve the issue of automatically generating the API docs for the entire package. Since this was the main motivation for #290, I'm inclined to merge #297 and the original issue. I think I need to spend some more time in the future looking at other packages in the Python OSS space to see how they do things but after a quick look I have not found any that does everything I want:
|
Btw thanks for the effort in trying to solve this with me! 🙏 It sounds like a simple issue but sometimes the tooling just isn't there (or doesn't address all edge cases). Considering that this is such a common use-case, it is kinda crazy how partitioned the space is (tooling for Sphinx API docs). |
@tpvasconcelos, thanks for your feedback! While sphinx-apidoc addresses (partially) your requirements for automatic API documentation generation (#290), I completely understand your points about the broader gaps in Python documentation tooling and the features we still need. My initial PR relied on a custom RST generator, but sphinx-apidoc has proven to be a partial solution for you now. I haven't tested the sphinx-apidoc approach locally yet, but I'm glad you made some progress on this solution. If I think of any ways to improve this automation, I'll definitely keep you posted - maybe I can contribute more in the future when I have more time. By the way, the plots are awesome! I'll be using ridgeplot from now on. Happy holidays colleague! 🎄
|
This PR adds functionality to automatically generate .rst files for internal API documentation.
Changes:
generate_internal_api_rst.py
script that:The script generates RST files in
docs/api/internal/
with proper modulehierarchy and descriptions, removing the need for manual maintenance.
Testing:
Check generated files in
docs/api/internal/
Run tests:
Note: The script can be integrated into the CI pipeline in a future iteration if needed.
PR check list
docs/api/internal/
.docs/api/index.rst
.versionadded
,versionchanged
, ordeprecated
directives to docstrings.MAJOR.MINOR.PATCH
(e.g., if the current version is0.2.3
, the next release will be0.3.0
).docs/reference/changelog.md
.📚 Documentation preview 📚: https://ridgeplot--293.org.readthedocs.build/en/293/
Closes #290