From 35eddc461070e26355bd8ee9099cfd8c9df4a321 Mon Sep 17 00:00:00 2001 From: Shakeeb Alireza Date: Tue, 3 Oct 2023 11:32:36 +0300 Subject: [PATCH] Fix for multiple extension entry bug (+ api change) in 'build' subcmd (#170) In the prior commit there was a bug which prevented multiple extensions from being entered via the `build` subcmd (it would always take the last one entered). The below code ```python build_sp.add_argument("-n", "--ext-name", nargs=True, help="name of extension") build_sp.add_argument("-p", "--ext-path", nargs=True, help="path of extension") ``` really should have been ```python build_sp.add_argument("-n", "--ext-name", nargs='+', help="name of extension") build_sp.add_argument("-p", "--ext-path", nargs='+', help="path of extension") ``` But it was found that this would force the user to enter names and files separately: ```bash python -m pydust build \ --ext-name 'fib._lib' 'fib._hello' \ --ext-path 'fib/fib.zig' 'fib/hello.zig' ``` While this is not terrible, this PR proposes the following new api for entering extensions from the commandline instead: ```python build_sp.add_argument("-e", "--extensions", nargs='+', help="space separated list of extension '=' entries") ``` which would allow the entry of multiple extensions as follows: ```bash python -m pydust build --extensions 'fib._lib=fib/fib.zig' 'fib._hello=fib/hello.zig' # or python -m pydust build -e 'fib._lib=fib/fib.zig' 'fib._hello=fib/hello.zig' ``` --- pydust/__main__.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pydust/__main__.py b/pydust/__main__.py index ba8ffb78..d0e3e654 100644 --- a/pydust/__main__.py +++ b/pydust/__main__.py @@ -29,9 +29,7 @@ build_sp.add_argument("-b", "--build-zig", default="build.zig", help="build.zig file") build_sp.add_argument("-m", "--self-managed", default=False, action="store_true", help="self-managed mode") build_sp.add_argument("-a", "--limited-api", default=True, action="store_true", help="use limited python c-api") -build_sp.add_argument("-n", "--ext-name", nargs=True, help="name of extension") -build_sp.add_argument("-p", "--ext-path", nargs=True, help="path of extension") - +build_sp.add_argument("-e", "--extensions", nargs='+', help="space separated list of extension '=' entries") def main(): args = parser.parse_args() @@ -43,11 +41,12 @@ def main(): build(args) def build(args): - """Given a list of (name, path) pairs, compiles zig-based python extensions""" - names, paths = args.ext_name, args.ext_path - assert (names and paths) and (len(names) == len(paths)), "requires at least one pair of --ext-name and --ext-path" + """Given a list of '=' entries, compiles corresponding zig-based python extensions""" + assert args.extensions and all('=' in ext for ext in args.extensions),\ + "requires at least one --extensions '='" + ext_items = [tuple(ext.split('=')) for ext in args.extensions] _extensions = [] - for name, path in zip(names, paths): + for name, path in ext_items: _extensions.append( config.ExtModule(name=name, root=path, limited_api=args.limited_api) )