diff options
Diffstat (limited to 'meta-python/recipes-extended/python-pykickstart/files')
| -rw-r--r-- | meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch b/meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch new file mode 100644 index 0000000000..e2b34ab937 --- /dev/null +++ b/meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | From f753d4d6ad1f4846d14735beb3d1b157b9914b51 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Adam Williamson <awilliam@redhat.com> | ||
| 3 | Date: Wed, 2 Oct 2024 09:48:39 -0700 | ||
| 4 | Subject: [PATCH] options: adjust to behavior change in upstream | ||
| 5 | _parse_optional | ||
| 6 | |||
| 7 | In Python 3.13 and 3.12.7, the behavior of _parse_optional has | ||
| 8 | changed. It used to raise an error on multiple matching actions | ||
| 9 | itself, and only ever return None or an option tuple. Now the | ||
| 10 | "raise error on multiple matching actions" code was moved out | ||
| 11 | into consume_optional, and _parse_optional returns either None | ||
| 12 | or a *list* of option tuples, which contains more than one if | ||
| 13 | multiple actions match. See: | ||
| 14 | |||
| 15 | https://github.com/python/cpython/pull/124631 | ||
| 16 | https://github.com/python/cpython/issues/58573 | ||
| 17 | |||
| 18 | This adapts to the change in a way that should work on both older | ||
| 19 | and newer Pythons. | ||
| 20 | |||
| 21 | Signed-off-by: Adam Williamson <awilliam@redhat.com> | ||
| 22 | |||
| 23 | Upstream-Status: Backport [https://github.com/pykickstart/pykickstart/commit/f753d4d] | ||
| 24 | |||
| 25 | Signed-off-by: Kai Kang <kai.kang@windriver.com> | ||
| 26 | --- | ||
| 27 | pykickstart/options.py | 20 +++++++++++++++++--- | ||
| 28 | 1 file changed, 17 insertions(+), 3 deletions(-) | ||
| 29 | |||
| 30 | diff --git a/pykickstart/options.py b/pykickstart/options.py | ||
| 31 | index 2e3a0721..ca0e18af 100644 | ||
| 32 | --- a/pykickstart/options.py | ||
| 33 | +++ b/pykickstart/options.py | ||
| 34 | @@ -177,9 +177,23 @@ class KSOptionParser(ArgumentParser): | ||
| 35 | self.lineno = None | ||
| 36 | |||
| 37 | def _parse_optional(self, arg_string): | ||
| 38 | - option_tuple = ArgumentParser._parse_optional(self, arg_string) | ||
| 39 | + # Before 3.13 and 3.12.7, this returned None or a single | ||
| 40 | + # option tuple. From 3.13 / 3.12.7 onwards it returns None | ||
| 41 | + # or a *list* of option tuples | ||
| 42 | + option_tuple_or_tuples = ArgumentParser._parse_optional(self, arg_string) | ||
| 43 | + # all we want to do here is a custom warning if the action is | ||
| 44 | + # deprecated. we can only safely do this if there's exactly | ||
| 45 | + # one matching action | ||
| 46 | + if isinstance(option_tuple_or_tuples, list): | ||
| 47 | + if len(option_tuple_or_tuples) == 1: | ||
| 48 | + option_tuple = option_tuple_or_tuples[0] | ||
| 49 | + else: | ||
| 50 | + return option_tuple_or_tuples | ||
| 51 | + else: | ||
| 52 | + option_tuple = option_tuple_or_tuples | ||
| 53 | + | ||
| 54 | if option_tuple is None or option_tuple[0] is None: | ||
| 55 | - return option_tuple | ||
| 56 | + return option_tuple_or_tuples | ||
| 57 | |||
| 58 | action = option_tuple[0] | ||
| 59 | option = action.option_strings[0] | ||
| 60 | @@ -191,7 +205,7 @@ class KSOptionParser(ArgumentParser): | ||
| 61 | "kickstart. Please modify your kickstart file to remove this option.") | ||
| 62 | % {"lineno": self.lineno, "option": option}, KickstartDeprecationWarning) | ||
| 63 | |||
| 64 | - return option_tuple | ||
| 65 | + return option_tuple_or_tuples | ||
| 66 | |||
| 67 | def add_argument(self, *args, **kwargs): | ||
| 68 | if "introduced" in kwargs: | ||
| 69 | -- | ||
| 70 | 2.47.1 | ||
| 71 | |||
