Skip to content
Snippets Groups Projects
Commit 5b5ed35b authored by Tom Osika's avatar Tom Osika
Browse files

Merge branch 'dev/rework-flag-names' into 'master'

Dev/rework flag names

Closes #149

See merge request autopybind11/autopybind11!115
parents c49fdd83 e9849032
No related branches found
No related tags found
No related merge requests found
private_members_as_fields : false
custom_namespace_structure : true
\ No newline at end of file
private_members : false
enforce_namespace_structure : false
ignore_namespace_structure: True
enforce_namespace_structure: False
ignore_namespace_structure: True
enforce_namespace_structure: False
......@@ -39,6 +39,7 @@ class BindingsGenerator:
self.customizer = customizer.Customizer(
self.name_tree[self.opts.module_name]
)
self.cns_flag = False
self.validation_filters = []
self.load_validation_filters()
......@@ -415,7 +416,7 @@ class BindingsGenerator:
free_fun_mod_name = "{}_free_functions".format(self.opts.module_name)
cpp_body = self.opts.non_class_module_cpp_fmt
pybind_module_name = "m"
if module_name != free_fun_mod_name and not self.opts.ins_flag:
if module_name != free_fun_mod_name:
pybind_module_name = module_name
for function in function_data:
cpp_name = function.name
......@@ -441,7 +442,7 @@ class BindingsGenerator:
keys["defs"] = keys["defs"].strip()
file_name = posixpath.join(out_dir, "%s_py.cpp" % module_name)
if module_name != free_fun_mod_name and not self.opts.ins_flag:
if module_name != free_fun_mod_name:
cpp_body = self.opts.non_class_module_return_cpp_fmt
submodules_str = (
self.opts.submodule_signature_fmt.format(name=module_name)
......@@ -1234,7 +1235,7 @@ class BindingsGenerator:
def write_module_data(self, module_name, results_dict, out_dir):
"""
Writes out the "folder" level module for wrapping.
THis file follows
This file follows
:param module_name:
:param results_dict:
:param out_dir:
......@@ -1244,7 +1245,9 @@ class BindingsGenerator:
module_data = {"forwards": [], "init_funs": []}
no_forward_list = set()
nmspcs = set()
if not self.opts.ins_flag:
# Note that this assumes self.name_tree will only be populated
# if we are not ignoring the namespace structure
if self.name_tree:
self.flatten(self.name_tree, nmspcs)
self.build_namespace_structure(
self.name_tree[self.opts.module_name],
......@@ -1297,7 +1300,6 @@ class BindingsGenerator:
def populate_namespace_web(self, mod_name):
self.namespace_web[mod_name] = {
"mod_name": "",
"all_gen_fun_data": list(),
"all_gen_enum_data": list(),
"files_to_include": set(),
......@@ -1372,6 +1374,15 @@ class BindingsGenerator:
data,
)
if custom_mod_name:
# If this is the first we're hearing of a custom
# namespace structure and we're not enforcing the
# namespace structure, move the previous classes, fxns, etc.
# to the global namespace.
if not self.cns_flag and not self.opts.ens_flag:
self.namespace_web = dict()
self.populate_namespace_web(self.opts.module_name)
self.cns_flag = True
self.populate_namespace_web(custom_mod_name)
cust_nmspc_future_file = self.find_future_file_name(
is_class,
......@@ -1387,7 +1398,7 @@ class BindingsGenerator:
else:
ff_name = future_file
obj_to_nmspc = ""
if self.opts.cns_flag or self.opts.ins_flag:
if not self.opts.ens_flag:
if not is_class:
ff_name = free_fun_name + "_py.cpp"
else:
......@@ -1431,26 +1442,19 @@ class BindingsGenerator:
elif key == "namespaces":
for namespace_name in inner_dict:
new_nmspc = self.add_namespace(curr_nmspc, namespace_name)
# Add new namespace to res_dict, rather than current
# prevents functionless namespaces from being dropped
# also will allow us to handle empty namespaces
if not self.opts.ins_flag:
# If cns_flag is enabled, we're writing everything to the
# top level namespace except for objects that define a
# custom namespace.
if not self.cns_flag:
self.populate_namespace_web(namespace_name)
if self.opts.ens_flag:
future_file = self.find_future_file_name(
False, new_nmspc, free_fun_name, new_nmspc
)
if not self.opts.cns_flag:
res_dict["out_names"][future_file] = curr_mod
self.populate_name_tree(
mod_tree, curr_mod, {namespace_name: {}}
)
self.populate_namespace_web(namespace_name)
if curr_nmspc != "":
# Use add_namespace to match templated classes
self.data_web[
self.add_namespace(curr_nmspc, namespace_name)
] = auto_bind_func
if not self.opts.cns_flag:
self.populate_namespace_web(namespace_name)
res_dict["out_names"][future_file] = curr_mod
self.populate_name_tree(
mod_tree, curr_mod, {namespace_name: {}}
)
mod_tree = self.find_module_data(
inner_dict[namespace_name],
res_dict,
......@@ -1629,9 +1633,8 @@ class BindingsGenerator:
)
if py_module_name is None:
if (
self.opts.cns_flag
or mod_name == free_fun_name
or self.opts.ins_flag
mod_name == free_fun_name
or not self.opts.ens_flag
):
py_module_name = self.opts.module_name
else:
......@@ -1667,9 +1670,8 @@ class BindingsGenerator:
py_module_name = self.customizer.get_curr_mod_name(enum_data)
if py_module_name is None:
if (
self.opts.cns_flag
or mod_name == free_fun_name
or self.opts.ins_flag
mod_name == free_fun_name
or not self.opts.ens_flag
):
py_module_name = self.opts.module_name
else:
......@@ -2003,25 +2005,14 @@ def main(argv=None):
dest="pm_flag",
default=False,
)
namespace_mx_arg_group = arg.add_mutually_exclusive_group()
namespace_mx_arg_group.add(
"-ins",
"--ignore_namespace_structure",
required=False,
action="store",
type=lambda x: bool(distutils.util.strtobool(x)),
dest="ins_flag",
default=False,
)
namespace_mx_arg_group.add(
"-cns",
"--custom_namespace_structure",
arg.add(
"-ens",
"--enforce_namespace_structure",
required=False,
action="store",
type=lambda x: bool(distutils.util.strtobool(x)),
dest="cns_flag",
default=False,
dest="ens_flag",
default=True,
)
arg.add(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment