public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/
@ 2023-01-20  7:24 Arthur Zamarin
  0 siblings, 0 replies; 5+ messages in thread
From: Arthur Zamarin @ 2023-01-20  7:24 UTC (permalink / raw
  To: gentoo-commits

commit:     c3024463f81783169aba78ad93bfc0a0502f1daf
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Fri Jan 20 07:24:18 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Fri Jan 20 07:24:18 2023 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=c3024463

cli.arghparse: add missing comma in help metavar text

Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/snakeoil/cli/arghparse.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index 375ffe42..a1d1c0b1 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -519,8 +519,7 @@ class _SubParser(argparse._SubParsersAction):
         Reverts the broken upstream change made in issue #9351 which causes
         issue #23058. This can be dropped when the problem is fixed upstream.
         """
-        parser_name = values[0]
-        arg_strings = values[1:]
+        parser_name, *arg_strings = values
 
         # set the parser name if requested
         if self.dest is not argparse.SUPPRESS:
@@ -555,7 +554,7 @@ class CsvHelpFormatter(argparse.HelpFormatter):
         ):
             result = "%s[,-%s,...]" % get_metavar(2)
         elif isinstance(action, (CommaSeparatedElements, CommaSeparatedElementsAppend)):
-            result = "%s[,-%s,+%s...]" % get_metavar(3)
+            result = "%s[,-%s,+%s,...]" % get_metavar(3)
         elif isinstance(action, Delayed):
             result = self._format_args(action.target, default_metavar)
         else:


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/
@ 2024-04-08 19:37 Arthur Zamarin
  0 siblings, 0 replies; 5+ messages in thread
From: Arthur Zamarin @ 2024-04-08 19:37 UTC (permalink / raw
  To: gentoo-commits

commit:     936902901eb8df408a2bc708b327cf7e1325da16
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Mon Apr  8 19:32:45 2024 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Mon Apr  8 19:32:45 2024 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=93690290

arghparse: fix handling with python 3.11.9

In commit [0], the private function changes the tuple size it returns.
By using `*_` in the middle, we can support both extracted versions (3
and 4) of the function.

This investigation was done by ajak, thank you.

[0] https://github.com/python/cpython/commit/c02b7ae4dd367444aa6822d5fb73b61e8f5a4ff9

Resolves: https://github.com/pkgcore/pkgcheck/issues/676
Resolves: https://github.com/pkgcore/pkgdev/issues/184
Investigated-by: John Helmert III <ajak <AT> gentoo.org>
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/snakeoil/cli/arghparse.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index ab458c8f..80443b7a 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -774,7 +774,7 @@ class OptionalsParser(argparse.ArgumentParser):
         def consume_optional(start_index):
             # get the optional identified at this index
             option_tuple = option_string_indices[start_index]
-            action, option_string, explicit_arg = option_tuple
+            action, option_string, *_, explicit_arg = option_tuple
 
             # identify additional optionals in the same arg string
             # (e.g. -xyz is the same as -x -y -z if no args are required)


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/
@ 2023-01-16 21:00 Arthur Zamarin
  0 siblings, 0 replies; 5+ messages in thread
From: Arthur Zamarin @ 2023-01-16 21:00 UTC (permalink / raw
  To: gentoo-commits

commit:     8addc22ed18f84e1047be4ca71084832bdb1cdd8
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 16 20:55:36 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Mon Jan 16 20:55:36 2023 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=8addc22e

cli.arghparse: improve _format_args for Delayed

Resolves: https://github.com/pkgcore/pkgcheck/issues/520
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/snakeoil/cli/arghparse.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index 09eaed36..375ffe42 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -556,6 +556,8 @@ class CsvHelpFormatter(argparse.HelpFormatter):
             result = "%s[,-%s,...]" % get_metavar(2)
         elif isinstance(action, (CommaSeparatedElements, CommaSeparatedElementsAppend)):
             result = "%s[,-%s,+%s...]" % get_metavar(3)
+        elif isinstance(action, Delayed):
+            result = self._format_args(action.target, default_metavar)
         else:
             result = super()._format_args(action, default_metavar)
         return result


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/
@ 2022-12-31  7:36 Arthur Zamarin
  0 siblings, 0 replies; 5+ messages in thread
From: Arthur Zamarin @ 2022-12-31  7:36 UTC (permalink / raw
  To: gentoo-commits

commit:     103472541ea9df637e52bf01af707df831e872a3
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 31 07:35:40 2022 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sat Dec 31 07:35:40 2022 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=10347254

cli.arghparse: fix bind_final_check

Follows: 47d21307c44cad87641e20f50f57b3f5d218c0f4
Closes: https://github.com/pkgcore/pkgdev/issues/112
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/snakeoil/cli/arghparse.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index a7a29826..a1209092 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -1309,7 +1309,7 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
             self.error(str(exc))
 
         # run final arg validation
-        for check in set(vars(args).keys()):
+        for check in set(args.__dict__.keys()):
             if check.startswith("__final_check__"):
                 functor = args.pop(check)
                 functor(self, args)


^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/
@ 2022-12-30 19:03 Arthur Zamarin
  0 siblings, 0 replies; 5+ messages in thread
From: Arthur Zamarin @ 2022-12-30 19:03 UTC (permalink / raw
  To: gentoo-commits

commit:     47d21307c44cad87641e20f50f57b3f5d218c0f4
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 30 19:03:36 2022 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Fri Dec 30 19:03:36 2022 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=47d21307

little modernization of snakeoil.cli

Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/snakeoil/cli/arghparse.py | 48 +++++++++++++++++++++----------------------
 src/snakeoil/cli/input.py     |  5 ++---
 src/snakeoil/cli/tool.py      |  2 +-
 3 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index 774699ed..a7a29826 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -148,13 +148,13 @@ class CommaSeparatedValues(argparse._AppendAction):
     """Split comma-separated values into a list."""
 
     def parse_values(self, values):
-        items = []
         if isinstance(values, str):
-            items.extend(x for x in values.split(",") if x)
+            return list(filter(None, values.split(",")))
         else:
+            items = []
             for value in values:
                 items.extend(x for x in value.split(",") if x)
-        return items
+            return items
 
     def __call__(self, parser, namespace, values, option_string=None):
         items = self.parse_values(values)
@@ -188,9 +188,9 @@ class CommaSeparatedNegations(argparse._AppendAction):
             values = [values]
         for value in values:
             try:
-                neg, pos = split_negations(x for x in value.split(",") if x)
-            except ValueError as e:
-                raise argparse.ArgumentTypeError(e)
+                neg, pos = split_negations(filter(None, value.split(",")))
+            except ValueError as exc:
+                raise argparse.ArgumentTypeError(exc)
             disabled.extend(neg)
             enabled.extend(pos)
 
@@ -236,9 +236,9 @@ class CommaSeparatedElements(argparse._AppendAction):
             values = [values]
         for value in values:
             try:
-                neg, neu, pos = split_elements(x for x in value.split(",") if x)
-            except ValueError as e:
-                raise argparse.ArgumentTypeError(e)
+                neg, neu, pos = split_elements(filter(None, value.split(",")))
+            except ValueError as exc:
+                raise argparse.ArgumentTypeError(exc)
             disabled.extend(neg)
             neutral.extend(neu)
             enabled.extend(pos)
@@ -323,7 +323,7 @@ class StoreBool(argparse._StoreAction):
             return True
         elif value in ("n", "no", "false", "0"):
             return False
-        raise ValueError("value %r must be [y|yes|true|1|n|no|false|0]" % (value,))
+        raise ValueError(f"value {value!r} must be [y|yes|true|1|n|no|false|0]")
 
 
 class EnableDebug(argparse._StoreTrueAction):
@@ -469,7 +469,7 @@ class Expansion(argparse.Action):
             args = [x % dvals for x in args]
             if not action:
                 raise ValueError(
-                    "unable to find option %r for %r" % (option, self.option_strings)
+                    f"unable to find option {option!r} for {self.option_strings!r}"
                 )
             if action.type is not None:
                 args = list(map(action.type, args))
@@ -1137,7 +1137,7 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
                     help="enable/disable color support",
                     docs="""
                         Toggle colored output support. This can be used to forcibly
-                        enable color support when piping output or other sitations
+                        enable color support when piping output or other situations
                         where stdout is not a tty.
                     """,
                 )
@@ -1273,7 +1273,7 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
                 namespace.main_func = subcmd_parser.__main_func
 
         if unknown_args:
-            self.error("unrecognized arguments: %s" % " ".join(unknown_args))
+            self.error(f"unrecognized arguments: {' '.join(unknown_args)}")
 
         # Two runs are required; first, handle any suppression defaults
         # introduced. Subparsers defaults cannot override the parent parser, as
@@ -1302,19 +1302,17 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
         try:
             for attr, delayed in sorted(i, key=lambda val: val[1].priority):
                 delayed(args, attr)
-        except (TypeError, ValueError) as e:
-            raise TypeError("failed loading/parsing '%s': %s" % (attr, str(e))) from e
+        except (TypeError, ValueError) as exc:
+            raise TypeError(f"failed loading/parsing {attr!r}: {exc}") from exc
         except argparse.ArgumentError:
-            e = sys.exc_info()[1]
-            self.error(str(e))
+            exc = sys.exc_info()[1]
+            self.error(str(exc))
 
         # run final arg validation
-        final_checks = [
-            k for k in args.__dict__.keys() if k.startswith("__final_check__")
-        ]
-        for check in final_checks:
-            functor = args.pop(check)
-            functor(self, args)
+        for check in set(vars(args).keys()):
+            if check.startswith("__final_check__"):
+                functor = args.pop(check)
+                functor(self, args)
 
         return args
 
@@ -1327,7 +1325,7 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
         if self.debug and sys.exc_info() != (None, None, None):
             # output traceback if any exception is on the stack
             traceback.print_exc()
-        self.exit(status, "%s: error: %s\n" % (self.prog, message))
+        self.exit(status, f"{self.prog}: error: {message}\n")
 
     def bind_main_func(self, functor):
         """Decorator to set a main function for the parser."""
@@ -1340,7 +1338,7 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
     def bind_class(self, obj):
         if not isinstance(obj, ArgparseCommand):
             raise ValueError(
-                "expected obj to be an instance of " "ArgparseCommand; got %r" % (obj,)
+                f"expected obj to be an instance of ArgparseCommand; got {obj!r}"
             )
         obj.bind_to_parser(self)
         return self

diff --git a/src/snakeoil/cli/input.py b/src/snakeoil/cli/input.py
index 9db9ea8c..7e63e332 100644
--- a/src/snakeoil/cli/input.py
+++ b/src/snakeoil/cli/input.py
@@ -91,11 +91,10 @@ def userquery(prompt, out, err, responses=None, default_answer=None, limit=3):
             )
         )
         if not results:
-            err.write("Sorry, response %r not understood." % (response,))
+            err.write(f"Sorry, response {response!r} not understood.")
         elif len(results) > 1:
             err.write(
-                "Response %r is ambiguous (%s)"
-                % (response, ", ".join(key for key, val in results))
+                f"Response {response!r} is ambiguous ({', '.join(key for key, _ in results)})"
             )
         else:
             return list(results)[0][1][0]

diff --git a/src/snakeoil/cli/tool.py b/src/snakeoil/cli/tool.py
index d00b3cf2..18b2f89d 100644
--- a/src/snakeoil/cli/tool.py
+++ b/src/snakeoil/cli/tool.py
@@ -234,5 +234,5 @@ class FormattingHandler(logging.Handler):
             self.handleError(record)
         finally:
             self.out.later_prefix.pop()
-            for i in range(len(first_prefix)):
+            for _ in range(len(first_prefix)):
                 self.out.first_prefix.pop()


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-08 19:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-20  7:24 [gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/ Arthur Zamarin
  -- strict thread matches above, loose matches on Subject: below --
2024-04-08 19:37 Arthur Zamarin
2023-01-16 21:00 Arthur Zamarin
2022-12-31  7:36 Arthur Zamarin
2022-12-30 19:03 Arthur Zamarin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox