This is extra brittle. Hahah why this has to be so damn complex.
# handle modules and packages differently. See also for more info:
# https://stackoverflow.com/a/7948672
else:
- # pybind11 submodules have __package__ set to None for nested modules,
- # the top-level __package__ is '' though. Allow these if parent
- # __package__ is empty (either '' or None).
- if state.config['PYBIND11_COMPATIBILITY'] and object.__package__ is None and not parent.__package__: return False
+ # pybind11 submodules have __package__ set to None (instead of '') for
+ # nested modules. Allow these. The parent's __package__ can be None (if
+ # it's a nested submodule), '' (if it's a top-level module) or a string
+ # (if the parent is a Python package), can't really check further.
+ if state.config['PYBIND11_COMPATIBILITY'] and object.__package__ is None: return False
# The parent is a single-file module (not a package), these don't have
# submodules so this is most definitely an imported module. Source:
set_target_properties(pybind_name_mapping PROPERTIES
OUTPUT_NAME _sub
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pybind_name_mapping/pybind_name_mapping)
+
+# Need a special name for this one
+pybind11_add_module(pybind_submodules_package pybind_submodules_package/sub.cpp)
+set_target_properties(pybind_submodules_package PROPERTIES
+ OUTPUT_NAME sub
+ LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pybind_submodules_package/pybind_submodules_package)
--- /dev/null
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8" />
+ <title>pybind_submodules_package.sub | My Python Project</title>
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,600,600i%7CSource+Code+Pro:400,400i,600" />
+ <link rel="stylesheet" href="m-dark+documentation.compiled.css" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+</head>
+<body>
+<header><nav id="navigation">
+ <div class="m-container">
+ <div class="m-row">
+ <a href="index.html" id="m-navbar-brand" class="m-col-t-8 m-col-m-none m-left-m">My Python Project</a>
+ </div>
+ </div>
+</nav></header>
+<main><article>
+ <div class="m-container m-container-inflatable">
+ <div class="m-row">
+ <div class="m-col-l-10 m-push-l-1">
+ <h1>
+ <span class="m-breadcrumb"><a href="pybind_submodules_package.html">pybind_submodules_package</a>.<wbr/></span>sub <span class="m-thin">module</span>
+ </h1>
+ <p>pybind11 submodule of a Python package</p>
+ <div class="m-block m-default">
+ <h3>Contents</h3>
+ <ul>
+ <li>
+ Reference
+ <ul>
+ <li><a href="#packages">Modules</a></li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ <section id="namespaces">
+ <h2><a href="#namespaces">Modules</a></h2>
+ <dl class="m-doc">
+ <dt>module <a href="pybind_submodules_package.sub.another.html" class="m-doc">another</a></dt>
+ <dd>Yay another</dd>
+ <dt>module <a href="pybind_submodules_package.sub.subsub.html" class="m-doc">subsub</a></dt>
+ <dd>Yay a submodule</dd>
+ </dl>
+ </section>
+ </div>
+ </div>
+ </div>
+</article></main>
+</body>
+</html>
--- /dev/null
+import pybind_submodules_package.sub
+
+__all__ = ['sub']
--- /dev/null
+#include <pybind11/pybind11.h>
+
+PYBIND11_MODULE(sub, m) {
+ m.doc() = "pybind11 submodule of a Python package";
+
+ m.def_submodule("subsub", "Yay a submodule");
+ m.def_submodule("another", "Yay another");
+}
})
self.assertEqual(*self.actual_expected_contents('pybind_submodules.html'))
+class SubmodulesPackage(BaseInspectTestCase):
+ def __init__(self, *args, **kwargs):
+ super().__init__(__file__, 'submodules_package', *args, **kwargs)
+
+ def test(self):
+ self.run_python({
+ 'PYBIND11_COMPATIBILITY': True
+ })
+ self.assertEqual(*self.actual_expected_contents('pybind_submodules_package.sub.html'))
+
class NameMapping(BaseInspectTestCase):
def __init__(self, *args, **kwargs):
super().__init__(__file__, 'name_mapping', *args, **kwargs)