From 00fdb0c6bbabbfa3cbd9675160b014ae3f0f169d Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Sat, 23 Mar 2024 07:48:53 +0000 Subject: [PATCH 1/2] #15 simplify includes --- .github/workflows/build-and-test.yml | 5 +---- README.md | 5 +---- cppwg/__main__.py | 18 ++++++++++++++---- tests/test_shapes.py | 28 ++++++++++++++-------------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 5b43891..247e4ea 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -52,10 +52,7 @@ jobs: cppwg src/ \ --wrapper_root wrapper/ \ --package_info wrapper/package_info.yaml \ - --include src/geometry/ \ - --include src/math_funcs/ \ - --include src/primitives/ \ - --include src/python/ + --includes src/*/ - name: Build Python module run: | diff --git a/README.md b/README.md index 980e258..8245f62 100644 --- a/README.md +++ b/README.md @@ -100,10 +100,7 @@ cd examples/shapes cppwg src/ \ --wrapper_root wrapper/ \ --package_info wrapper/package_info.yaml \ - --include src/geometry/ \ - --include src/math_funcs/ \ - --include src/primitives/ \ - --include src/python/ + --includes src/geometry/ src/math_funcs/ src/primitives/ ``` To build the example package do: diff --git a/cppwg/__main__.py b/cppwg/__main__.py index 2c849fb..07243df 100644 --- a/cppwg/__main__.py +++ b/cppwg/__main__.py @@ -2,6 +2,8 @@ import argparse import logging +import shlex +from typing import List, Optional from cppwg import CppWrapperGenerator @@ -53,10 +55,9 @@ def parse_args() -> argparse.Namespace: parser.add_argument( "-i", - "--include", + "--includes", type=str, - action="append", - help="Path to an include directory. Specify multiple times for multiple directories.", + help="List of paths to include directories.", ) parser.add_argument( @@ -80,9 +81,18 @@ def generate(args: argparse.Namespace) -> None: args : argparse.Namespace The parsed command line arguments. """ + # Convert includes string to list - split by space, comma, colon or semicolon + source_includes: Optional[List[str]] = None + if args.includes: + spaced_includes = ( + args.includes.replace(":", " ").replace(";", " ").replace(",", " ") + ) + source_includes = shlex.split(spaced_includes) # preserves quoted strings + + # Generate the wrappers generator = CppWrapperGenerator( source_root=args.source_root, - source_includes=args.include, + source_includes=source_includes, wrapper_root=args.wrapper_root, package_info_path=args.package_info, castxml_binary=args.castxml_binary, diff --git a/tests/test_shapes.py b/tests/test_shapes.py index 3e89056..ef78455 100644 --- a/tests/test_shapes.py +++ b/tests/test_shapes.py @@ -74,22 +74,22 @@ def test_wrapper_generation(self) -> None: package_info_path = os.path.join(wrapper_root_ref, "package_info.yaml") self.assertTrue(os.path.isfile(package_info_path)) - includes = [] - for dirname in glob(shapes_src + "/*/"): - includes.extend(["--include", dirname]) + includes = " ".join(glob(shapes_src + "/*/")) # Generate the wrappers - call_args = [ - "python", - generate_script, - shapes_src, - "--wrapper_root", - wrapper_root_gen, - "--package_info", - package_info_path, - ] + includes - - subprocess.call(call_args) + subprocess.call( + [ + "python", + generate_script, + shapes_src, + "--wrapper_root", + wrapper_root_gen, + "--package_info", + package_info_path, + "--includes", + includes, + ] + ) self.assertTrue(os.path.isdir(wrapper_root_gen)) From a4e06401988f8efbe1642d499db018d4191fbdd0 Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Sat, 23 Mar 2024 08:10:34 +0000 Subject: [PATCH 2/2] #15 use nargs for includes --- cppwg/__main__.py | 14 ++------------ tests/test_shapes.py | 4 ++-- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/cppwg/__main__.py b/cppwg/__main__.py index 07243df..d9374b9 100644 --- a/cppwg/__main__.py +++ b/cppwg/__main__.py @@ -2,8 +2,6 @@ import argparse import logging -import shlex -from typing import List, Optional from cppwg import CppWrapperGenerator @@ -57,6 +55,7 @@ def parse_args() -> argparse.Namespace: "-i", "--includes", type=str, + nargs="*", help="List of paths to include directories.", ) @@ -81,18 +80,9 @@ def generate(args: argparse.Namespace) -> None: args : argparse.Namespace The parsed command line arguments. """ - # Convert includes string to list - split by space, comma, colon or semicolon - source_includes: Optional[List[str]] = None - if args.includes: - spaced_includes = ( - args.includes.replace(":", " ").replace(";", " ").replace(",", " ") - ) - source_includes = shlex.split(spaced_includes) # preserves quoted strings - - # Generate the wrappers generator = CppWrapperGenerator( source_root=args.source_root, - source_includes=source_includes, + source_includes=args.includes, wrapper_root=args.wrapper_root, package_info_path=args.package_info, castxml_binary=args.castxml_binary, diff --git a/tests/test_shapes.py b/tests/test_shapes.py index ef78455..45ff30b 100644 --- a/tests/test_shapes.py +++ b/tests/test_shapes.py @@ -74,7 +74,7 @@ def test_wrapper_generation(self) -> None: package_info_path = os.path.join(wrapper_root_ref, "package_info.yaml") self.assertTrue(os.path.isfile(package_info_path)) - includes = " ".join(glob(shapes_src + "/*/")) + includes = glob(shapes_src + "/*/") # Generate the wrappers subprocess.call( @@ -87,8 +87,8 @@ def test_wrapper_generation(self) -> None: "--package_info", package_info_path, "--includes", - includes, ] + + includes ) self.assertTrue(os.path.isdir(wrapper_root_gen))