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

Changed namespace fix to use Sphinx autodoc-process-* events #7103

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions cpp/pybind/docstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,9 @@ std::string FunctionDoc::ToGoogleDocString() const {
return rc.str();
}

std::string FunctionDoc::NamespaceFix(const std::string& s) {
std::string rc = std::regex_replace(s, std::regex("::(\\S)"), ".$1");
rc = std::regex_replace(rc, std::regex("open3d\\.(cpu|cuda)\\.pybind\\."),
"open3d.");
return rc;
}

std::string FunctionDoc::StringCleanAll(std::string& s,
const std::string& white_space) {
std::string rc = utility::StripString(s, white_space);
rc = NamespaceFix(rc);
return rc;
}

Expand All @@ -313,7 +305,7 @@ ArgumentDoc FunctionDoc::ParseArgumentToken(const std::string& argument_token) {
std::smatch matches;
if (std::regex_search(argument_token, matches, rgx_with_default)) {
argument_doc.name_ = matches[1].str();
argument_doc.type_ = NamespaceFix(matches[2].str());
argument_doc.type_ = matches[2].str();
argument_doc.default_ = matches[3].str();

// Handle long default value. Long default has multiple lines and thus
Expand All @@ -335,7 +327,7 @@ ArgumentDoc FunctionDoc::ParseArgumentToken(const std::string& argument_token) {
"([A-Za-z_][A-Za-z\\d_:\\.\\[\\]\\(\\) ,]*)");
if (std::regex_search(argument_token, matches, rgx_without_default)) {
argument_doc.name_ = matches[1].str();
argument_doc.type_ = NamespaceFix(matches[2].str());
argument_doc.type_ = matches[2].str();
}
}

Expand Down
23 changes: 23 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,31 @@ def skip(app, what, name, obj, would_skip, options):
return would_skip


def fix_namespace(text):
"""Fixes namespace in a string by removing .[cpu|cuda].pybind."""
return (text.replace("open3d.cpu.pybind.", "open3d.").replace(
"open3d.cuda.pybind.", "open3d.") if text is not None else None)


def process_signature(app, what, name, obj, options, signature,
return_annotation):
"""Fixes namespace in signature by removing .[cpu|cuda].pybind."""
return (
fix_namespace(signature),
fix_namespace(return_annotation),
)


def process_docstring(app, what, name, obj, options, lines):
"""Fixes namespace in docstring by removing .[cpu|cuda].pybind."""
for i, line in enumerate(lines):
lines[i] = fix_namespace(line)


def setup(app):
app.connect("autodoc-skip-member", skip)
app.connect("autodoc-process-signature", process_signature)
app.connect("autodoc-process-docstring", process_docstring)
# Add Google analytics
app.add_js_file("https://www.googletagmanager.com/gtag/js?id=G-3TQPKGV6Z3",
**{'async': 'async'})
Expand Down
Loading