8000 Python auto doc by wrongbad · Pull Request #665 · elalish/manifold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Python auto doc #665

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 occasionall 8000 y send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 26, 2023
Merged

Python auto doc #665

merged 8 commits into from
Dec 26, 2023

Conversation

wrongbad
Copy link
Contributor

This is based on top of the "more numpy" branch, so look at just the top commit for now.

I threw together a quick proof of concept. Obviously the script can use a lot of refactoring to add more sources with less redundancy.

One pain point already is method overloading and how to generate keys/ids to reference them. I put a simple "_1", "_2" mechanism in, but this can cause problems when adding new overloads and docstrings silently get shifted to wrong functions. I looked at doxygen XML outputs and it seems they generate some arbitrary hash for overloads, so it would likely not be a stable reference from the binding cpp file.

I could also try parentheses matching to scoop the full function name, remove all whitespace and hash it, then you only need to update the key if the function signature changes.

Copy link
codecov bot commented Dec 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7d564cf) 91.66% compared to head (50ab9f7) 91.66%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #665   +/-   ##
=======================================
  Coverage   91.66%   91.66%           
=======================================
  Files          37       37           
  Lines        4737     4737           
=======================================
  Hits         4342     4342           
  Misses        395      395           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pca006132
Copy link
Collaborator

For overloads, we can probably use the parameter names as keys. It will be nice if we can make some macro that set the nb::arg and fill in the parameter name in the docstring.

@wrongbad
Copy link
Contributor Author

While parsing parameters names and types would be nice, I fear it quickly spirals into general-purpose c++ parsing, which is more than a 100-line python script can handle

@pca006132
Copy link
Collaborator

I think the function signature is simple in our case, we can make sure that there are no parenthesis in the parameter type. This can make it readable using regex. We can just change our source file to make it easy to parse, instead of changing the script to parse whatever c++ madness.

@wrongbad
Copy link
Contributor Author

Ah I'm reminded why I prefer to amend and force-push when working on PR. Rebasing this branch on master is a huge mess

@elalish
Copy link
Owner
elalish commented Dec 20, 2023

No need to bother with rebasing - just use a regular merge. That's why we squash.

#pragma once
#include <string>
namespace manifold_docs {
const auto cross_section__area_f5458809be32 = R"___(Return the total area covered by complex polygons making up the
Copy link
Owner

Choose a reason for hiding this comment

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

Is this file generated by your script? Would be great to have some documentation about how the system works and the right way to maintain it. Looks promising though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generated a comment in the file, and added comments in the gen_docs.py script.

@elalish
Copy link
Owner
elalish commented Dec 21, 2023

This is looking great - is it ready for review?

@zalo
Copy link
Contributor
zalo commented Dec 21, 2023

Is the “_1”, “_2” overload handling mechanism still in there; how does it work? (I would be kind of sad if callers had to disambiguate overloads by appending the number of the overload to the function name… OpenCascade.js eventually went this direction for typescript annotations)

If that’s the case, perhaps a lesser evil would be marking non-intersecting args as optional?

@pca006132
Copy link
Collaborator

I think the auto doc is just for documentation, it does not affect overload resolution in the runtime. And it is using the argument names as suffices to disambiguate different overloads, e.g. manifold__manifold vs manifold__manifold__mesh_gl__property_tolerance.

@wrongbad
Copy link
Contributor Author
wrongbad commented Dec 21, 2023

Yes I think it's ready for review.

And yes the _1 is gone and these overload names don't affect API, only binding sources for maintainers.

0