d4feac Add patch to fix compatibility with python3.11-a7 (rhbz#2057363)

Authored and Committed by Zbigniew Jędrzejewski-Szmek 2 years ago
    Add patch to fix compatibility with python3.11-a7 (rhbz#2057363)
    
        
0001-py3.11-fix-Enum-formatting-to-work-with-python3.11-a.patch ADDED
@@ -0,0 +1,81 @@
1
+ From f73a97aba7f6a586bf96ad970294a332109ab558 Mon Sep 17 00:00:00 2001
2
+ From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
3
+ Date: Sun, 24 Apr 2022 12:54:57 +0200
4
+ Subject: [PATCH] py3.11: fix Enum formatting to work with python3.11-a7
5
+
6
+ Something strange is happening with .__repr__() access in python3.11:
7
+
8
+ >>> mkosi.backend.ManifestFormat.mro()
9
+ [<enum 'ManifestFormat'>, <class 'mkosi.backend.Parseable'>, <enum 'Enum'>, <class 'object'>]
10
+ >>> mkosi.backend.ManifestFormat.changelog.__repr__()
11
+ Traceback (most recent call last):
12
+ File "<stdin>", line 1, in <module>
13
+ File "/usr/lib64/python3.11/enum.py", line 1194, in __repr__
14
+ return "<%s.%s: %s>" % (self.__class__.__name__, self._name_, v_repr(self._value_))
15
+ ^^^^^^^^^^^^^^^^^^^^
16
+ File "/home/zbyszek/src/mkosi/mkosi/backend.py", line 95, in __repr__
17
+ return cast(str, getattr(self, "name"))
18
+ ^^^^^^^^^^^^^^^^^^^^^
19
+ AttributeError: 'str' object has no attribute 'name'
20
+
21
+ Enum somehow subverts normal lookup and makes its own __repr__ function be
22
+ used, even though Parseable is listed first in MRO. This seems to be related to
23
+ PEP 663, which was rejected, and the changes reverted for -a4 [1], but then the revert
24
+ was reverted [2].
25
+
26
+ Let's just sidestep MRO with a method redefinition:
27
+
28
+ >>> mkosi.backend.ManifestFormat.changelog.__repr__
29
+ <bound method ManifestFormat.__repr__ of changelog>
30
+ >>> mkosi.backend.ManifestFormat.changelog.__repr__()
31
+ 'changelog'
32
+
33
+ This should work on all python versions. If python3.11 returns to previous
34
+ semantics before the final release, we can remove the workaround.
35
+
36
+ [1] commit acf7403f9baea3ae1119fc6b4a3298522188bf96
37
+ Author: Ethan Furman <ethan@stoneleaf.us>
38
+ Date: Sat Jan 15 22:41:43 2022 -0800
39
+
40
+ bpo-40066: [Enum] update str() and format() output (GH-30582)
41
+
42
+ Undo rejected PEP-663 changes:
43
+
44
+ - restore `repr()` to its 3.10 status
45
+ - restore `str()` to its 3.10 status
46
+
47
+ [2] commit 42a64c03ec5c443f2a5c2ee4284622f5d1f5326c
48
+ Author: Victor Stinner <vstinner@python.org>
49
+ Date: Mon Jan 17 13:58:40 2022 +0100
50
+
51
+ Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" (GH-30632)
52
+
53
+ This reverts commit acf7403f9baea3ae1119fc6b4a3298522188bf96.
54
+ ---
55
+ mkosi/backend.py | 8 ++++++++
56
+ 1 file changed, 8 insertions(+)
57
+
58
+ diff --git a/mkosi/backend.py b/mkosi/backend.py
59
+ index 78006f392a..3c57ec6295 100644
60
+ --- a/mkosi/backend.py
61
+ +++ b/mkosi/backend.py
62
+ @@ -217,11 +217,19 @@ class OutputFormat(Parseable, enum.Enum):
63
+ def has_fs_compression(self) -> bool:
64
+ return self.is_squashfs() or self.is_btrfs()
65
+
66
+ + def __repr__(self) -> str:
67
+ + return Parseable.__repr__(self)
68
+ + def __str__(self) -> str:
69
+ + return Parseable.__str__(self)
70
+
71
+ class ManifestFormat(Parseable, enum.Enum):
72
+ json = "json" # the standard manifest in json format
73
+ changelog = "changelog" # human-readable text file with package changelogs
74
+
75
+ + def __repr__(self) -> str:
76
+ + return Parseable.__repr__(self)
77
+ + def __str__(self) -> str:
78
+ + return Parseable.__str__(self)
79
+
80
+ class PartitionIdentifier(enum.Enum):
81
+ esp = 'esp'
file modified
+8 -6
mkosi.spec CHANGED
@@ -7,6 +7,8 @@ License: LGPLv2+
7
7
URL: https://github.com/systemd/mkosi
8
8
Source0: https://github.com/systemd/mkosi/archive/v%{version}/%{name}-%{version}.tar.gz
9
9
10
+ Patch: 0001-py3.11-fix-Enum-formatting-to-work-with-python3.11-a.patch
11
+
10
12
BuildArch: noarch
11
13
BuildRequires: python3-devel
12
14
BuildRequires: python3-setuptools
@@ -34,13 +36,13 @@ Recommends: python3dist(cryptography)
34
36
%endif
35
37
36
38
%description
37
- A fancy wrapper around "dnf --installroot", "debootstrap" and
38
- "pacstrap", that may generate disk images with a number of bells and
39
- whistles.
39
+ A fancy wrapper around "dnf --installroot", "debootstrap", "pacman", "zypper",
40
+ "emerge", and "swupd-extract" that may generate disk images with a number of
41
+ bells and whistles.
40
42
41
- Generated images are tailed to the purose. This means GPT disk labels
42
- are used by default, though MBR disk labels are supported, and only
43
- systemd based images may be generated.
43
+ Generated images are tailed to the purose. This means GPT disk labels are used
44
+ by default, though MBR disk labels are supported, and only systemd based images
45
+ may be generated.
44
46
45
47
%prep
46
48
%autosetup -p1