From d0de67fa686a11f0ea361e331b1094f6b26ff2e1 Mon Sep 17 00:00:00 2001 From: cafhach Date: Mon, 4 Oct 2021 13:23:08 +0200 Subject: [PATCH 1/4] More conventional usage of -I Changed syntax of command line argument -I Until now to add multiple paths, you had to put them into one long quotation-mark-separated string, individual paths separated by spaces. This is not viable for paths including space characters and is also rather unconventional. Instead you can now add the "-I" argument multiple times. This is the approach used by e.g. compilers like clang or gcc --- utilities/python/cpp_to_pybind11.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/utilities/python/cpp_to_pybind11.py b/utilities/python/cpp_to_pybind11.py index dc2ad1053..61aa5c522 100644 --- a/utilities/python/cpp_to_pybind11.py +++ b/utilities/python/cpp_to_pybind11.py @@ -22,6 +22,7 @@ import os import sys +from typing import List # Find out the file location within the sources tree this_module_dir_path = os.path.abspath( @@ -231,7 +232,7 @@ def flatten(list_, separator): return sorted(includes) -def parse_file(filename, project_source_directory, include_directories, +def parse_file(filename, project_source_directory, include_directories: List[str], declaration_names, stream): """ Entry point for parsing a file @@ -242,7 +243,7 @@ def parse_file(filename, project_source_directory, include_directories, # Configure the xml generator config = parser.xml_generator_configuration_t( start_with_declarations=declaration_names.split(" "), - include_paths=include_directories.split(" "), + include_paths=include_directories, xml_generator_path=generator_path, xml_generator=generator_name, cflags='-std=c++11 -Wc++11-extensions') @@ -567,7 +568,8 @@ def uncapitalize(s): arg_parser = argparse.ArgumentParser() arg_parser.add_argument('-I', '--include-dirs', help='Add an include directory to the parser', - default="") + action='append', + default=[]) arg_parser.add_argument('-d', '--declaration-name', help='names of C++ classes and functions', @@ -591,8 +593,8 @@ def uncapitalize(s): args = arg_parser.parse_args() - if not args.include_dirs: - args.include_dirs = args.input_directory + if len(args.include_dirs) == 0: + args.include_dirs.append(args.input_directory) def stream_with_line_breaks(stream): def write(string): From 089742d8ae0b48f6f2153828ebd0bd8959ea3187 Mon Sep 17 00:00:00 2001 From: cafhach Date: Mon, 4 Oct 2021 13:29:57 +0200 Subject: [PATCH 2/4] followup change of -I command line argument --- utilities/python/generate_pybind11_module.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utilities/python/generate_pybind11_module.py b/utilities/python/generate_pybind11_module.py index 0a4976b88..57a612daf 100644 --- a/utilities/python/generate_pybind11_module.py +++ b/utilities/python/generate_pybind11_module.py @@ -25,8 +25,9 @@ arg_parser = argparse.ArgumentParser() arg_parser.add_argument('-I', '--include-dirs', + action='append', help='Add an include directory to the parser', - default="") + default=[]) arg_parser.add_argument('-i', '--input-directory', help=' Input directory', @@ -57,8 +58,8 @@ if not os.path.exists(args.input_directory): raise IOError("No directory \"%s\"" % args.input_directory) - if not args.include_dirs: - args.include_dirs = args.input_directory + if len(args.include_dirs) == 0: + args.include_dirs.append(args.input_directory) def stream_with_line_breaks(stream): def write(string): From 5b40715adb17951869c4ecbce243fa9da87323f0 Mon Sep 17 00:00:00 2001 From: cafhach Date: Mon, 4 Oct 2021 13:32:04 +0200 Subject: [PATCH 3/4] followup change of -I command line argument --- doc/userguide/bindings/generating-pybind11-bindings.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/userguide/bindings/generating-pybind11-bindings.rst b/doc/userguide/bindings/generating-pybind11-bindings.rst index 9b7388007..b28e79bed 100644 --- a/doc/userguide/bindings/generating-pybind11-bindings.rst +++ b/doc/userguide/bindings/generating-pybind11-bindings.rst @@ -14,8 +14,8 @@ the module. To generate a C++ header file for a new SMTK class, use ``[smtk-root-directory]/utilities/python/cpp_to_pybind11.py`` with the appropriate arguments for the header file, project root directory, -include directories (e.g. ``-I "[smtk-build-directory] -[smtk-root-directory]/thirdparty/cJSON path/to/vtk/include"``) and +include directories (e.g. ``-I [smtk-build-directory] +-I [smtk-root-directory]/thirdparty/cJSON path/to/vtk/include``) and generated file prefix; the module's binding source file (also located in the ``pybind`` subdirectory of the module) must then be updated to call the functions defined in the generated header file. To generate From 4b04f73e93b78924c43c862f53e03a91f3bbc921 Mon Sep 17 00:00:00 2001 From: cafhach Date: Tue, 5 Oct 2021 20:39:58 +0200 Subject: [PATCH 4/4] Bugfix for case of `-I` being omitted This case didn't work in the trunk version either. I assumed what was meant there and implemented it using `os.path.dirname`. --- utilities/python/cpp_to_pybind11.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities/python/cpp_to_pybind11.py b/utilities/python/cpp_to_pybind11.py index 61aa5c522..77e5718f1 100644 --- a/utilities/python/cpp_to_pybind11.py +++ b/utilities/python/cpp_to_pybind11.py @@ -594,7 +594,7 @@ def uncapitalize(s): args = arg_parser.parse_args() if len(args.include_dirs) == 0: - args.include_dirs.append(args.input_directory) + args.include_dirs.append(os.path.getdirname(args.input)) def stream_with_line_breaks(stream): def write(string):