Skip to content

Commit 8dbccb6

Browse files
authored
Changed namespace fix to use Sphinx autodoc-process-* events (#7103)
* Moved namespace fix to autodoc event callbacks to fix imports in stubs. * Fixed typo for cuda namespace fix
1 parent 2a67419 commit 8dbccb6

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

cpp/pybind/docstring.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,9 @@ std::string FunctionDoc::ToGoogleDocString() const {
289289
return rc.str();
290290
}
291291

292-
std::string FunctionDoc::NamespaceFix(const std::string& s) {
293-
std::string rc = std::regex_replace(s, std::regex("::(\\S)"), ".$1");
294-
rc = std::regex_replace(rc, std::regex("open3d\\.(cpu|cuda)\\.pybind\\."),
295-
"open3d.");
296-
return rc;
297-
}
298-
299292
std::string FunctionDoc::StringCleanAll(std::string& s,
300293
const std::string& white_space) {
301294
std::string rc = utility::StripString(s, white_space);
302-
rc = NamespaceFix(rc);
303295
return rc;
304296
}
305297

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

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

docs/conf.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,31 @@ def skip(app, what, name, obj, would_skip, options):
264264
return would_skip
265265

266266

267+
def fix_namespace(text):
268+
"""Fixes namespace in a string by removing .[cpu|cuda].pybind."""
269+
return (text.replace("open3d.cpu.pybind.", "open3d.").replace(
270+
"open3d.cuda.pybind.", "open3d.") if text is not None else None)
271+
272+
273+
def process_signature(app, what, name, obj, options, signature,
274+
return_annotation):
275+
"""Fixes namespace in signature by removing .[cpu|cuda].pybind."""
276+
return (
277+
fix_namespace(signature),
278+
fix_namespace(return_annotation),
279+
)
280+
281+
282+
def process_docstring(app, what, name, obj, options, lines):
283+
"""Fixes namespace in docstring by removing .[cpu|cuda].pybind."""
284+
for i, line in enumerate(lines):
285+
lines[i] = fix_namespace(line)
286+
287+
267288
def setup(app):
268289
app.connect("autodoc-skip-member", skip)
290+
app.connect("autodoc-process-signature", process_signature)
291+
app.connect("autodoc-process-docstring", process_docstring)
269292
# Add Google analytics
270293
app.add_js_file("https://www.googletagmanager.com/gtag/js?id=G-3TQPKGV6Z3",
271294
**{'async': 'async'})

0 commit comments

Comments
 (0)