Conflict between denoising and namespace renaming
I'll try my best to describe the issue.
The problem
My C++ code looks like this
namespace aristarchus::geometry {
class Vector {...};
double angle(Vector const&, Vector const&);
}
Wrapper specifications
files:
src/aristarchus/geometry/euclidian/threed/Vector3D.hpp:
namespaces:
aristarchus:
namespaces:
geometry:
customization:
enable_doc_strings: True
classes:
Vector:
customization:
namespace: geometry
module_local:
angle:
customization:
namespace: geometry
And the configuration file contains
enforce_namespace_structure: False
apply_global_namespace: False
Without the customization.namespace
keys, I ended up with an extra scoping level in my Python module. With a import modulename
, the symbols were in modulename.aristarchus.geometry.(Vector|angle)
whilst I'd them to be modulename.geometry.(Vector|angle)
.
If I add the customization.namespace
key at the class level, it's perfect, Vector
goes to the right place. However if I add it to each function, the C++ code generated is being striped of ::geometry::
and then angle()
signature contains aristarchusVector
instead of aristarchus::geometry::Vector
.
The Solution
The removal (/denoising?) of the intermediary namespace shall not be systematic. I've found out that if I check for is_custom
beforehand, the issue seems fixed. In other words, the following patch seems to solve the issue.
diff --git i/autopybind11/__main__.py w/autopybind11/__main__.py
index 7e8aa67..bb314fc 100644
--- i/autopybind11/__main__.py
+++ w/autopybind11/__main__.py
@@ -784,8 +784,10 @@ class BindingsGenerator:
)
keys["defs"] = submodules_str + keys["defs"]
- if module_name != free_fun_mod_name:
- keys["defs"] = keys["defs"].replace("::%s::" % module_name, "")
+ if not is_custom:
+ # Only works when the full namespace is removed
+ # and if there is a "using namespace"
+ keys["defs"] = keys["defs"].replace("::%s::" % module_name, "")
content = cpp_body.format(**keys)
if self.opts.exdec:
With this I'm even able to have the same name for the python module and my project root namespace name.
Postscriptum
On a side note, it would be nice to tell that all the free functions shall go in modulename.geometry
without having to repeat ourselves. IOW, to put the customization.namespace
key at the upper namespaces:
level.