From 415e7364f4e1e27562ff7e457aef5ac1065e93b9 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Tue, 30 Apr 2024 09:13:39 -0700 Subject: [PATCH] pmb.parse: add get_parser for returning ArgumentParser obj (MR 2266) This is needed for sphinx autoprogram since that expects an argparse.ArgumentParser, and arguments() returns some argparse "Namespace" obj. Useful for sphinx/autoprogram and maybe other things later that want to get at pmb's full args. --- pmb/parse/__init__.py | 2 +- pmb/parse/arguments.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pmb/parse/__init__.py b/pmb/parse/__init__.py index ee628c45..3ea1df0c 100644 --- a/pmb/parse/__init__.py +++ b/pmb/parse/__init__.py @@ -1,6 +1,6 @@ # Copyright 2023 Oliver Smith # SPDX-License-Identifier: GPL-3.0-or-later -from pmb.parse.arguments import arguments, arguments_install, arguments_flasher +from pmb.parse.arguments import arguments, arguments_install, arguments_flasher, get_parser from pmb.parse._apkbuild import apkbuild from pmb.parse._apkbuild import function_body from pmb.parse.binfmt_info import binfmt_info diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 01bc0538..642ce798 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -624,7 +624,7 @@ def add_kernel_arg(subparser, name="package", nargs="?", *args, **kwargs): arg.completer = kernel_completer -def arguments(): +def get_parser(): parser = argparse.ArgumentParser(prog="pmbootstrap") arch_native = pmb.config.arch_native arch_choices = set(pmb.config.build_device_architectures + [arch_native]) @@ -930,8 +930,13 @@ def arguments(): if "argcomplete" in sys.modules: argcomplete.autocomplete(parser, always_complete_options="long") + return parser + +def arguments(): + # Parse and extend arguments (also backup unmodified result from argparse) - args = parser.parse_args() + args = get_parser().parse_args() + setattr(args, "from_argparse", copy.deepcopy(args)) setattr(args.from_argparse, "from_argparse", args.from_argparse)