Skip to contentSkip to conversation

python3-pykickstart: fix options parse error

PATCH In review [email protected] 2 participants 4 messages Mar 11, 2025 – Mar 13, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 python3-pykickstart: fix options parse error

From: Kai Kang <[email protected]>

Backport a patch for python3-pykickstart to fix option parse error:

File "/usr/lib64/python3.12/site-packages/pykickstart/options.py", line 185, in _parse_optional
option = action.option_strings[0]
^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'option_strings'

---
 ...o-behavior-change-in-upstream-_parse.patch | 71 +++++++++++++++++++
 .../python3-pykickstart_3.48.bb               |  1 +
 2 files changed, 72 insertions(+)
 create mode 100644 meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch
meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch new file +71 -0
new file mode 100644
index 0000000000..e2b34ab937
@@ -0,0 +1,71 @@
+From f753d4d6ad1f4846d14735beb3d1b157b9914b51 Mon Sep 17 00:00:00 2001
+From: Adam Williamson <[email protected]>
+Date: Wed, 2 Oct 2024 09:48:39 -0700
+Subject: [PATCH] options: adjust to behavior change in upstream
+ _parse_optional
+
+In Python 3.13 and 3.12.7, the behavior of _parse_optional has
+changed. It used to raise an error on multiple matching actions
+itself, and only ever return None or an option tuple. Now the
+"raise error on multiple matching actions" code was moved out
+into consume_optional, and _parse_optional returns either None
+or a *list* of option tuples, which contains more than one if
+multiple actions match. See:
+
+https://github.com/python/cpython/pull/124631
+https://github.com/python/cpython/issues/58573
+
+This adapts to the change in a way that should work on both older
+and newer Pythons.
+
+Signed-off-by: Adam Williamson <[email protected]>
+
+Upstream-Status: Backport [https://github.com/pykickstart/pykickstart/commit/f753d4d]
+
+Signed-off-by: Kai Kang <[email protected]>
+---
+ pykickstart/options.py | 20 +++++++++++++++++---
+ 1 file changed, 17 insertions(+), 3 deletions(-)
+
+diff --git a/pykickstart/options.py b/pykickstart/options.py
+index 2e3a0721..ca0e18af 100644
+--- a/pykickstart/options.py
++++ b/pykickstart/options.py
+@@ -177,9 +177,23 @@ class KSOptionParser(ArgumentParser):
+         self.lineno = None
+ 
+     def _parse_optional(self, arg_string):
+-        option_tuple = ArgumentParser._parse_optional(self, arg_string)
++        # Before 3.13 and 3.12.7, this returned None or a single
++        # option tuple. From 3.13 / 3.12.7 onwards it returns None
++        # or a *list* of option tuples
++        option_tuple_or_tuples = ArgumentParser._parse_optional(self, arg_string)
++        # all we want to do here is a custom warning if the action is
++        # deprecated. we can only safely do this if there's exactly
++        # one matching action
++        if isinstance(option_tuple_or_tuples, list):
++            if len(option_tuple_or_tuples) == 1:
++                option_tuple = option_tuple_or_tuples[0]
++            else:
++                return option_tuple_or_tuples
++        else:
++            option_tuple = option_tuple_or_tuples
++
+         if option_tuple is None or option_tuple[0] is None:
+-            return option_tuple
++            return option_tuple_or_tuples
+ 
+         action = option_tuple[0]
+         option = action.option_strings[0]
+@@ -191,7 +205,7 @@ class KSOptionParser(ArgumentParser):
+                             "kickstart. Please modify your kickstart file to remove this option.")
+                           % {"lineno": self.lineno, "option": option}, KickstartDeprecationWarning)
+ 
+-        return option_tuple
++        return option_tuple_or_tuples
+ 
+     def add_argument(self, *args, **kwargs):
+         if "introduced" in kwargs:
+-- 
+2.47.1
+
meta-python/recipes-extended/python-pykickstart/python3-pykickstart_3.48.bb +1 -0
index 953068f7c3..657d0df539 100644
@@ -17,6 +17,7 @@ SRC_URI = "git://github.com/rhinstaller/pykickstart.git;protocol=https;branch=ma
            file://0002-pykickstart-parser.py-add-lock-for-readKickstart-and.patch \
            file://0003-comment-out-sections-shutdown-and-environment-in-gen.patch \
            file://0004-load.py-retry-to-invoke-request-with-timeout.patch \
+           file://0005-options-adjust-to-behavior-change-in-upstream-_parse.patch \
            "
 SRCREV = "fa6c80c0e5c6bee29d089899a10d26e6f7f8afd8"
 
Signature · 1 line
2.34.1
#1 lore raw

This is needed on master as well. Please add [master] to the subject line as well in future, else I might end up ignoring such patches accidentally thinking they are backports to stable branches.

Quoted 118 lines · Kai Kang via lists.openembedded.org

From: Kai Kang <[email protected]>

Backport a patch for python3-pykickstart to fix option parse error:

File "/usr/lib64/python3.12/site-packages/pykickstart/options.py", line 185, in _parse_optional
option = action.option_strings[0]
^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'option_strings'

---
 ...o-behavior-change-in-upstream-_parse.patch | 71 +++++++++++++++++++
 .../python3-pykickstart_3.48.bb               |  1 +
 2 files changed, 72 insertions(+)
 create mode 100644 meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch
meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch new file +71 -0
new file mode 100644
index 0000000000..e2b34ab937
@@ -0,0 +1,71 @@
+From f753d4d6ad1f4846d14735beb3d1b157b9914b51 Mon Sep 17 00:00:00 2001
+From: Adam Williamson <[email protected]>
+Date: Wed, 2 Oct 2024 09:48:39 -0700
+Subject: [PATCH] options: adjust to behavior change in upstream
+ _parse_optional
+
+In Python 3.13 and 3.12.7, the behavior of _parse_optional has
+changed. It used to raise an error on multiple matching actions
+itself, and only ever return None or an option tuple. Now the
+"raise error on multiple matching actions" code was moved out
+into consume_optional, and _parse_optional returns either None
+or a *list* of option tuples, which contains more than one if
+multiple actions match. See:
+
+https://github.com/python/cpython/pull/124631
+https://github.com/python/cpython/issues/58573
+
+This adapts to the change in a way that should work on both older
+and newer Pythons.
+
+Signed-off-by: Adam Williamson <[email protected]>
+
+Upstream-Status: Backport [https://github.com/pykickstart/pykickstart/commit/f753d4d]
+
+Signed-off-by: Kai Kang <[email protected]>
+---
+ pykickstart/options.py | 20 +++++++++++++++++---
+ 1 file changed, 17 insertions(+), 3 deletions(-)
+
+diff --git a/pykickstart/options.py b/pykickstart/options.py
+index 2e3a0721..ca0e18af 100644
+--- a/pykickstart/options.py
++++ b/pykickstart/options.py
+@@ -177,9 +177,23 @@ class KSOptionParser(ArgumentParser):
+         self.lineno = None
+
+     def _parse_optional(self, arg_string):
+-        option_tuple = ArgumentParser._parse_optional(self, arg_string)
++        # Before 3.13 and 3.12.7, this returned None or a single
++        # option tuple. From 3.13 / 3.12.7 onwards it returns None
++        # or a *list* of option tuples
++        option_tuple_or_tuples = ArgumentParser._parse_optional(self, arg_string)
++        # all we want to do here is a custom warning if the action is
++        # deprecated. we can only safely do this if there's exactly
++        # one matching action
++        if isinstance(option_tuple_or_tuples, list):
++            if len(option_tuple_or_tuples) == 1:
++                option_tuple = option_tuple_or_tuples[0]
++            else:
++                return option_tuple_or_tuples
++        else:
++            option_tuple = option_tuple_or_tuples
++
+         if option_tuple is None or option_tuple[0] is None:
+-            return option_tuple
++            return option_tuple_or_tuples
+
+         action = option_tuple[0]
+         option = action.option_strings[0]
+@@ -191,7 +205,7 @@ class KSOptionParser(ArgumentParser):
+                             "kickstart. Please modify your kickstart file to remove this option.")
+                           % {"lineno": self.lineno, "option": option}, KickstartDeprecationWarning)
+
+-        return option_tuple
++        return option_tuple_or_tuples
+
+     def add_argument(self, *args, **kwargs):
+         if "introduced" in kwargs:
+--
+2.47.1
+
meta-python/recipes-extended/python-pykickstart/python3-pykickstart_3.48.bb +1 -1
index 953068f7c3..657d0df539 100644
@@ -17,6 +17,7 @@ SRC_URI = "git://github.com/rhinstaller/pykickstart.git;protocol=https;branch=ma
            file://0002-pykickstart-parser.py-add-lock-for-readKickstart-and.patch \
            file://0003-comment-out-sections-shutdown-and-environment-in-gen.patch \
            file://0004-load.py-retry-to-invoke-request-with-timeout.patch \
+           file://0005-options-adjust-to-behavior-change-in-upstream-_parse.patch \
            "
 SRCREV = "fa6c80c0e5c6bee29d089899a10d26e6f7f8afd8"
 
--

2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#115888): https://lists.openembedded.org/g/openembedded-devel/message/115888
Mute This Topic: https://lists.openembedded.org/mt/111636553/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

author
#2 lore raw
Quoted 3 lines · Khem Raj

This is needed on master as well. Please add [master] to the subject line as well in future, else I might end up ignoring such patches accidentally thinking they are backports to stable branches.

I didn't verify this patch on master since I planned to upgrade it on master. And I'll consider master first next time.

Sorry for inconvenience.

Kai

Quoted 120 lines
Quoted 117 lines · Kai Kang via lists.openembedded.org

From: Kai Kang <[email protected]>

Backport a patch for python3-pykickstart to fix option parse error:

File "/usr/lib64/python3.12/site-packages/pykickstart/options.py", line 185, in _parse_optional
option = action.option_strings[0]
^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'option_strings'

---
  ...o-behavior-change-in-upstream-_parse.patch | 71 +++++++++++++++++++
  .../python3-pykickstart_3.48.bb               |  1 +
  2 files changed, 72 insertions(+)

create mode 100644 meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch

meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch new file +71 -0
new file mode 100644
index 0000000000..e2b34ab937
@@ -0,0 +1,71 @@
+From f753d4d6ad1f4846d14735beb3d1b157b9914b51 Mon Sep 17 00:00:00 2001
+From: Adam Williamson <[email protected]>
+Date: Wed, 2 Oct 2024 09:48:39 -0700
+Subject: [PATCH] options: adjust to behavior change in upstream
+ _parse_optional
+
+In Python 3.13 and 3.12.7, the behavior of _parse_optional has
+changed. It used to raise an error on multiple matching actions
+itself, and only ever return None or an option tuple. Now the
+"raise error on multiple matching actions" code was moved out
+into consume_optional, and _parse_optional returns either None
+or a *list* of option tuples, which contains more than one if
+multiple actions match. See:
+
+https://github.com/python/cpython/pull/124631
+https://github.com/python/cpython/issues/58573
+
+This adapts to the change in a way that should work on both older
+and newer Pythons.
+
+Signed-off-by: Adam Williamson <[email protected]>
+
+Upstream-Status: Backport [https://github.com/pykickstart/pykickstart/commit/f753d4d]
+
+Signed-off-by: Kai Kang <[email protected]>
+---
+ pykickstart/options.py | 20 +++++++++++++++++---
+ 1 file changed, 17 insertions(+), 3 deletions(-)
+
+diff --git a/pykickstart/options.py b/pykickstart/options.py
+index 2e3a0721..ca0e18af 100644
+--- a/pykickstart/options.py
++++ b/pykickstart/options.py
+@@ -177,9 +177,23 @@ class KSOptionParser(ArgumentParser):
+         self.lineno = None
+
+     def _parse_optional(self, arg_string):
+-        option_tuple = ArgumentParser._parse_optional(self, arg_string)
++        # Before 3.13 and 3.12.7, this returned None or a single
++        # option tuple. From 3.13 / 3.12.7 onwards it returns None
++        # or a *list* of option tuples
++        option_tuple_or_tuples = ArgumentParser._parse_optional(self, arg_string)
++        # all we want to do here is a custom warning if the action is
++        # deprecated. we can only safely do this if there's exactly
++        # one matching action
++        if isinstance(option_tuple_or_tuples, list):
++            if len(option_tuple_or_tuples) == 1:
++                option_tuple = option_tuple_or_tuples[0]
++            else:
++                return option_tuple_or_tuples
++        else:
++            option_tuple = option_tuple_or_tuples
++
+         if option_tuple is None or option_tuple[0] is None:
+-            return option_tuple
++            return option_tuple_or_tuples
+
+         action = option_tuple[0]
+         option = action.option_strings[0]
+@@ -191,7 +205,7 @@ class KSOptionParser(ArgumentParser):
+                             "kickstart. Please modify your kickstart file to remove this option.")
+                           % {"lineno": self.lineno, "option": option}, KickstartDeprecationWarning)
+
+-        return option_tuple
++        return option_tuple_or_tuples
+
+     def add_argument(self, *args, **kwargs):
+         if "introduced" in kwargs:
+--
+2.47.1
+
meta-python/recipes-extended/python-pykickstart/python3-pykickstart_3.48.bb +1 -1
index 953068f7c3..657d0df539 100644
@@ -17,6 +17,7 @@ SRC_URI = "git://github.com/rhinstaller/pykickstart.git;protocol=https;branch=ma
             file://0002-pykickstart-parser.py-add-lock-for-readKickstart-and.patch \
             file://0003-comment-out-sections-shutdown-and-environment-in-gen.patch \
             file://0004-load.py-retry-to-invoke-request-with-timeout.patch \
+           file://0005-options-adjust-to-behavior-change-in-upstream-_parse.patch \
             "
  SRCREV = "fa6c80c0e5c6bee29d089899a10d26e6f7f8afd8"
 
--

2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#115888): https://lists.openembedded.org/g/openembedded-devel/message/115888
Mute This Topic: https://lists.openembedded.org/mt/111636553/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 2 lines
Kai Kang
Wind River Linux
author
#3 lore raw
Quoted 5 lines · Kai
Quoted 3 lines · Khem Raj

This is needed on master as well. Please add [master] to the subject line as well in future, else I might end up ignoring such patches accidentally thinking they are backports to stable branches.

Hi Khem,

Quoted 1 line

I didn't verify this patch on master since I planned to upgrade it on master. And I'll consider master first next time.

It seems it will take more time than expect to upgrade python3-pykickstart. Please apply this patch for master branch too.

Thanks,
Kai

Quoted 139 lines

Sorry for inconvenience.

Kai

Quoted 133 lines
Quoted 130 lines · Kai Kang via lists.openembedded.org

From: Kai Kang <[email protected]>

Backport a patch for python3-pykickstart to fix option parse error:

     File "/usr/lib64/python3.12/site-packages/pykickstart/options.py", line 185, in _parse_optional option = action.option_strings[0]
                ^^^^^^^^^^^^^^^^^^^^^
   AttributeError: 'tuple' object has no attribute 'option_strings'

---
  ...o-behavior-change-in-upstream-_parse.patch | 71
+++++++++++++++++++
  .../python3-pykickstart_3.48.bb               |  1 +

  2 files changed, 72 insertions(+)

  create mode 100644 meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch

meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch +0 -0

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

meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch +23 -0
@@ -0,0 +1,71 @@
+From f753d4d6ad1f4846d14735beb3d1b157b9914b51 Mon Sep 17 00:00:00 2001
+From: Adam Williamson <[email protected]>
+Date: Wed, 2 Oct 2024 09:48:39 -0700
+Subject: [PATCH] options: adjust to behavior change in upstream
+ _parse_optional
+
+In Python 3.13 and 3.12.7, the behavior of _parse_optional has
+changed. It used to raise an error on multiple matching actions
+itself, and only ever return None or an option tuple. Now the
+"raise error on multiple matching actions" code was moved out
+into consume_optional, and _parse_optional returns either None
+or a *list* of option tuples, which contains more than one if
+multiple actions match. See:
+
+https://github.com/python/cpython/pull/124631
+https://github.com/python/cpython/issues/58573
+
+This adapts to the change in a way that should work on both older
+and newer Pythons.
+
+Signed-off-by: Adam Williamson <[email protected]>
+
+Upstream-Status: Backport 

[https://github.com/pykickstart/pykickstart/commit/f753d4d]

meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch +15 -0
+
+Signed-off-by: Kai Kang <[email protected]>
+---
+ pykickstart/options.py | 20 +++++++++++++++++---
+ 1 file changed, 17 insertions(+), 3 deletions(-)
+
+diff --git a/pykickstart/options.py b/pykickstart/options.py
+index 2e3a0721..ca0e18af 100644
+--- a/pykickstart/options.py
++++ b/pykickstart/options.py
+@@ -177,9 +177,23 @@ class KSOptionParser(ArgumentParser):
+         self.lineno = None
+
+     def _parse_optional(self, arg_string):
+-        option_tuple = ArgumentParser._parse_optional(self, 

arg_string)
++        # Before 3.13 and 3.12.7, this returned None or a single ++        # option tuple. From 3.13 / 3.12.7 onwards it returns None ++        # or a *list* of option tuples
++        option_tuple_or_tuples = ArgumentParser._parse_optional(self, arg_string)
++        # all we want to do here is a custom warning if the action is ++        # deprecated. we can only safely do this if there's exactly ++        # one matching action
++        if isinstance(option_tuple_or_tuples, list):
++            if len(option_tuple_or_tuples) == 1:
++                option_tuple = option_tuple_or_tuples[0] ++            else:
++                return option_tuple_or_tuples
++        else:
++            option_tuple = option_tuple_or_tuples
++
+         if option_tuple is None or option_tuple[0] is None:
+-            return option_tuple
++            return option_tuple_or_tuples
+
+         action = option_tuple[0]
+         option = action.option_strings[0]
+@@ -191,7 +205,7 @@ class KSOptionParser(ArgumentParser):
+                             "kickstart. Please modify your kickstart file to remove this option.")
+                           % {"lineno": self.lineno, "option":
option}, KickstartDeprecationWarning)

meta-python/recipes-extended/python-pykickstart/files/0005-options-adjust-to-behavior-change-in-upstream-_parse.patch +9 -0
+
+-        return option_tuple
++        return option_tuple_or_tuples
+
+     def add_argument(self, *args, **kwargs):
+         if "introduced" in kwargs:
+--
+2.47.1
+
meta-python/recipes-extended/python-pykickstart/python3-pykickstart_3.48.bb +0 -0

index 953068f7c3..657d0df539 100644
---
a/meta-python/recipes-extended/python-pykickstart/python3-pykickstart_3.48.bb
+++
b/meta-python/recipes-extended/python-pykickstart/python3-pykickstart_3.48.bb

meta-python/recipes-extended/python-pykickstart/python3-pykickstart_3.48.bb +0 -0
@@ -17,6 +17,7 @@ SRC_URI = 

"git://github.com/rhinstaller/pykickstart.git;protocol=https;branch=ma file://0002-pykickstart-parser.py-add-lock-for-readKickstart-and.patch \
file://0003-comment-out-sections-shutdown-and-environment-in-gen.patch \
file://0004-load.py-retry-to-invoke-request-with-timeout.patch \
+ file://0005-options-adjust-to-behavior-change-in-upstream-_parse.patch \
             "
  SRCREV = "fa6c80c0e5c6bee29d089899a10d26e6f7f8afd8"

Signature · 10 lines
2.34.1


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#115888): https://lists.openembedded.org/g/openembedded-devel/message/115888
Mute This Topic: https://lists.openembedded.org/mt/111636553/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Signature · 2 lines
Kai Kang
Wind River Linux