Skip to contentSkip to conversation

Python: Add 3.13 support, play linter whackamole

PATCH In review John Snow 3 participants 14 messages Jun 26, 2024 – Jul 5, 2024

lore
Share & tools
lore

John Snow

author
#0 lore raw

cover Python: Add 3.13 support, play linter whackamole

Fix some regressions in check-python-tox that have crept in since Pylint 3.x, and add Python 3.13 support to the pipeline.

GitLab pipeline (before I fixed the missing DCO, but let's be honest, it can't possibly be worth re-running so many tests for just that):
https://gitlab.com/jsnow/qemu/-/pipelines/1349737188

John Snow (4):
python: linter changes for pylint 3.x
python: Do not use pylint 3.2.4 with python 3.8
iotests: Change imports for Python 3.13
python: enable testing for 3.13

 python/qemu/machine/machine.py         | 1 +
 python/qemu/utils/qemu_ga_client.py    | 2 +-
 python/setup.cfg                       | 4 +++-
 tests/docker/dockerfiles/python.docker | 1 +
 tests/qemu-iotests/testenv.py          | 7 ++++++-
 tests/qemu-iotests/testrunner.py       | 9 ++++++---
 6 files changed, 18 insertions(+), 6 deletions(-)
Signature · 1 line
2.45.0
author
#1 lore raw

PATCH 1/4 python: linter changes for pylint 3.x

New bleeding edge versions, new nits to iron out. This addresses the 'check-python-tox' optional GitLab test, while 'check-python-minreqs' saw no regressions, since it's frozen on an older version of pylint.

Fixes:
qemu/machine/machine.py:345:52: E0606: Possibly using variable 'sock' before assignment (possibly-used-before-assignment) qemu/utils/qemu_ga_client.py:168:4: R1711: Useless return at end of function or method (useless-return)

---
 python/qemu/machine/machine.py      | 1 +
 python/qemu/utils/qemu_ga_client.py | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
python/qemu/machine/machine.py +1 -0
index f648f6af451..ebb58d5b68c 100644
@@ -335,6 +335,7 @@ def binary(self) -> str:
 
     def _pre_launch(self) -> None:
         if self._qmp_set:
+            sock = None
             if self._monitor_address is None:
                 self._sock_pair = socket.socketpair()
                 os.set_inheritable(self._sock_pair[0].fileno(), True)
python/qemu/utils/qemu_ga_client.py +1 -1
index 9a665e6e990..cf0fcf9a8bb 100644
@@ -174,7 +174,7 @@ def suspend(self, mode: str) -> None:
             # On error exception will raise
         except asyncio.TimeoutError:
             # On success command will timed out
-            return
+            pass
 
     def shutdown(self, mode: str = 'powerdown') -> None:
         if mode not in ['powerdown', 'halt', 'reboot']:
Signature · 1 line
2.45.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] python: linter changes for pylint 3.x

Quoted 9 lines · John Snow

New bleeding edge versions, new nits to iron out. This addresses the 'check-python-tox' optional GitLab test, while 'check-python-minreqs' saw no regressions, since it's frozen on an older version of pylint.

Fixes:
qemu/machine/machine.py:345:52: E0606: Possibly using variable 'sock' before assignment (possibly-used-before-assignment) qemu/utils/qemu_ga_client.py:168:4: R1711: Useless return at end of function or method (useless-return)

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
author
#3 lore raw

PATCH 2/4 python: Do not use pylint 3.2.4 with python 3.8

In reply to John Snow

There is a bug in this version,
see: https://github.com/pylint-dev/pylint/issues/9751

---
 python/setup.cfg | 1 +
 1 file changed, 1 insertion(+)
python/setup.cfg +1 -0
index 48668609d3e..8ebd345d7ed 100644
@@ -41,6 +41,7 @@ devel =
     isort >= 5.1.2
     mypy >= 1.4.0
     pylint >= 2.17.3
+    pylint != 3.2.4; python_version<"3.9"
     tox >= 3.18.0
     urwid >= 2.1.2
     urwid-readline >= 0.13
Signature · 1 line
2.45.0
author
#5 lore raw

PATCH 3/4 iotests: Change imports for Python 3.13

In reply to John Snow

Python 3.13 isn't out yet, but it's in beta and Fedora is ramping up to make it the default system interpreter for Fedora 41.

They moved our cheese for where ContextManager lives; add a conditional to locate it while we support both pre-3.9 and 3.13+.

---
 tests/qemu-iotests/testenv.py    | 7 ++++++-
 tests/qemu-iotests/testrunner.py | 9 ++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
tests/qemu-iotests/testenv.py +6 -1
index 588f30a4f14..96d69e56963 100644
@@ -25,7 +25,12 @@
 import random
 import subprocess
 import glob
-from typing import List, Dict, Any, Optional, ContextManager
+from typing import List, Dict, Any, Optional
+
+if sys.version_info >= (3, 9):
+    from contextlib import AbstractContextManager as ContextManager
+else:
+    from typing import ContextManager
 
 DEF_GDB_OPTIONS = 'localhost:12345'
 
tests/qemu-iotests/testrunner.py +6 -3
index 7b322272e92..2e236c8fa39 100644
@@ -27,11 +27,14 @@
 import shutil
 import sys
 from multiprocessing import Pool
-from typing import List, Optional, Any, Sequence, Dict, \
-        ContextManager
-
+from typing import List, Optional, Any, Sequence, Dict
 from testenv import TestEnv
 
+if sys.version_info >= (3, 9):
+    from contextlib import AbstractContextManager as ContextManager
+else:
+    from typing import ContextManager
+
 
 def silent_unlink(path: Path) -> None:
     try:
Signature · 1 line
2.45.0
author
#6 lore raw

Re: [PATCH 3/4] iotests: Change imports for Python 3.13

Ping - happy to merge this series myself but didn't wanna change iotests without at least an ack from the lord of that castle.

Quoted 57 lines · John Snow

Python 3.13 isn't out yet, but it's in beta and Fedora is ramping up to make it the default system interpreter for Fedora 41.

They moved our cheese for where ContextManager lives; add a conditional to locate it while we support both pre-3.9 and 3.13+.

---
 tests/qemu-iotests/testenv.py    | 7 ++++++-
 tests/qemu-iotests/testrunner.py | 9 ++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
tests/qemu-iotests/testenv.py +6 -1
index 588f30a4f14..96d69e56963 100644
@@ -25,7 +25,12 @@
 import random
 import subprocess
 import glob
-from typing import List, Dict, Any, Optional, ContextManager
+from typing import List, Dict, Any, Optional
+
+if sys.version_info >= (3, 9):
+    from contextlib import AbstractContextManager as ContextManager
+else:
+    from typing import ContextManager
 
 DEF_GDB_OPTIONS = 'localhost:12345'
 
tests/qemu-iotests/testrunner.py +6 -4
index 7b322272e92..2e236c8fa39 100644
@@ -27,11 +27,14 @@
 import shutil
 import sys
 from multiprocessing import Pool
-from typing import List, Optional, Any, Sequence, Dict, \
-        ContextManager
-
+from typing import List, Optional, Any, Sequence, Dict
 from testenv import TestEnv
 
+if sys.version_info >= (3, 9):
+    from contextlib import AbstractContextManager as ContextManager
+else:
+    from typing import ContextManager
+
 
 def silent_unlink(path: Path) -> None:
     try:
--

2.45.0

#7 lore raw

Re: [PATCH 3/4] iotests: Change imports for Python 3.13

In reply to John Snow
Quoted 18 lines · John Snow

Python 3.13 isn't out yet, but it's in beta and Fedora is ramping up to make it the default system interpreter for Fedora 41.

They moved our cheese for where ContextManager lives; add a conditional to locate it while we support both pre-3.9 and 3.13+.

---
 tests/qemu-iotests/testenv.py    | 7 ++++++-
 tests/qemu-iotests/testrunner.py | 9 ++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
tests/qemu-iotests/testenv.py +0 -0
index 588f30a4f14..96d69e56963 100644

tests/qemu-iotests/testenv.py line 33

Quoted 10 lines
tests/qemu-iotests/testenv.py +6 -1
@@ -25,7 +25,12 @@
 import random
 import subprocess
 import glob
-from typing import List, Dict, Any, Optional, ContextManager
+from typing import List, Dict, Any, Optional
+
+if sys.version_info >= (3, 9):
+    from contextlib import AbstractContextManager as ContextManager
+else:
+    from typing import ContextManager

It can be cleaner to add a compat module hiding the details so the entire project
can have a single instance of this. Other code will just use:

from compat import ContextManager

Quoted 29 lines
tests/qemu-iotests/testenv.py +0 -0
 DEF_GDB_OPTIONS = 'localhost:12345'
 
tests/qemu-iotests/testrunner.py +6 -4
index 7b322272e92..2e236c8fa39 100644
@@ -27,11 +27,14 @@
 import shutil
 import sys
 from multiprocessing import Pool
-from typing import List, Optional, Any, Sequence, Dict, \
-        ContextManager
-
+from typing import List, Optional, Any, Sequence, Dict
 from testenv import TestEnv
 
+if sys.version_info >= (3, 9):
+    from contextlib import AbstractContextManager as ContextManager
+else:
+    from typing import ContextManager
+
 
 def silent_unlink(path: Path) -> None:
     try:
--

2.45.0

author
#8 lore raw

Re: [PATCH 3/4] iotests: Change imports for Python 3.13

Quoted 35 lines · Nir Soffer
Quoted 7 lines · John Snow

Python 3.13 isn't out yet, but it's in beta and Fedora is ramping up to make it the default system interpreter for Fedora 41.

They moved our cheese for where ContextManager lives; add a conditional to locate it while we support both pre-3.9 and 3.13+.

Review

Quoted 7 lines
---
 tests/qemu-iotests/testenv.py    | 7 ++++++-
 tests/qemu-iotests/testrunner.py | 9 ++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/tests/qemu-iotests/testenv.py

Quoted 4 lines

index 588f30a4f14..96d69e56963 100644

tests/qemu-iotests/testenv.py line 33

Quoted 10 lines
tests/qemu-iotests/testenv.py +6 -1
@@ -25,7 +25,12 @@
 import random
 import subprocess
 import glob
-from typing import List, Dict, Any, Optional, ContextManager
+from typing import List, Dict, Any, Optional
+
+if sys.version_info >= (3, 9):
+    from contextlib import AbstractContextManager as ContextManager
+else:
+    from typing import ContextManager

It can be cleaner to add a compat module hiding the details so the entire project
can have a single instance of this. Other code will just use:

Quoted 2 lines

from compat import ContextManager

If there were more than two uses, I'd consider it. As it stands, a compat.py module with just one import conditional in it doesn't seem worth the hassle. Are there more cases of compatibility goop inside iotests that need to be factored out to make it worth it?

--js

#9 lore raw

Re: [PATCH 3/4] iotests: Change imports for Python 3.13

Quoted 40 lines · John Snow
Quoted 34 lines · On Tue, Jul 2, 2024 at 7:52 AM Nir Soffer <[email protected]…
Quoted 18 lines · On Thu, Jun 27, 2024 at 2:23 AM John Snow <[email protected]…

Python 3.13 isn't out yet, but it's in beta and Fedora is ramping up to make it the default system interpreter for Fedora 41.

They moved our cheese for where ContextManager lives; add a conditional to locate it while we support both pre-3.9 and 3.13+.

Signed-off-by John Snow <[email protected] <mailto:[email protected]>>
---
 tests/qemu-iotests/testenv.py    | 7 ++++++-
 tests/qemu-iotests/testrunner.py | 9 ++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
tests/qemu-iotests/testenv.py +0 -0
index 588f30a4f14..96d69e56963 100644

tests/qemu-iotests/testenv.py line 33

Quoted 10 lines
tests/qemu-iotests/testenv.py +6 -1
@@ -25,7 +25,12 @@
 import random
 import subprocess
 import glob
-from typing import List, Dict, Any, Optional, ContextManager
+from typing import List, Dict, Any, Optional
+
+if sys.version_info >= (3, 9):
+    from contextlib import AbstractContextManager as ContextManager
+else:
+    from typing import ContextManager

It can be cleaner to add a compat module hiding the details so the entire project
can have a single instance of this. Other code will just use:

Quoted 3 lines
Quoted 1 line

from compat import ContextManager

If there were more than two uses, I'd consider it. As it stands, a compat.py module with just one import conditional in it doesn't seem worth the hassle. Are there more cases of compatibility goop inside iotests that need to be factored out to make it worth it?

I don’t about other. For me even one instance is ugly enough :-)

author
#10 lore raw

Re: [PATCH 3/4] iotests: Change imports for Python 3.13

Quoted 45 lines · Nir Soffer

On 2 Jul 2024, at 17:44, John Snow <[email protected]> wrote:

Quoted 35 lines · Nir Soffer
Quoted 7 lines · John Snow

Python 3.13 isn't out yet, but it's in beta and Fedora is ramping up to make it the default system interpreter for Fedora 41.

They moved our cheese for where ContextManager lives; add a conditional to locate it while we support both pre-3.9 and 3.13+.

Review

Quoted 7 lines
---
 tests/qemu-iotests/testenv.py    | 7 ++++++-
 tests/qemu-iotests/testrunner.py | 9 ++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/tests/qemu-iotests/testenv.py

Quoted 4 lines

index 588f30a4f14..96d69e56963 100644

tests/qemu-iotests/testenv.py line 33

Quoted 10 lines
tests/qemu-iotests/testenv.py +6 -1
@@ -25,7 +25,12 @@
 import random
 import subprocess
 import glob
-from typing import List, Dict, Any, Optional, ContextManager
+from typing import List, Dict, Any, Optional
+
+if sys.version_info >= (3, 9):
+    from contextlib import AbstractContextManager as ContextManager
+else:
+    from typing import ContextManager

It can be cleaner to add a compat module hiding the details so the entire project
can have a single instance of this. Other code will just use:

Quoted 2 lines

from compat import ContextManager

Quoted 8 lines

If there were more than two uses, I'd consider it. As it stands, a compat.py module with just one import conditional in it doesn't seem worth the hassle. Are there more cases of compatibility goop inside iotests that need to be factored out to make it worth it?

I don’t about other. For me even one instance is ugly enough :-)

I was going to add it to qemu/utils, but then I remembered the testenv/testrunner script here needs to operate without external dependencies because part of the function of these modules is to *locate* those dependencies.

Ehh. I'm going to say that repeating the import scaffolding in just two places is fine enough for now and really not worth adding a compat.py for *just* this. Let's just get the tests green.

--js

author
#11 lore raw

PATCH 4/4 python: enable testing for 3.13

In reply to John Snow

Python 3.13 is in beta and Fedora 41 is preparing to make it the default system interpreter; enable testing for it.

(In the event problems develop prior to release, it should only impact the check-python-tox job, which is not run by default and is allowed to fail.)

---
 python/setup.cfg                       | 3 ++-
 tests/docker/dockerfiles/python.docker | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
python/setup.cfg +2 -1
index 8ebd345d7ed..3b4e2cc5501 100644
@@ -19,6 +19,7 @@ classifiers =
     Programming Language :: Python :: 3.10
     Programming Language :: Python :: 3.11
     Programming Language :: Python :: 3.12
+    Programming Language :: Python :: 3.13
     Typing :: Typed
 
 [options]
@@ -184,7 +185,7 @@ multi_line_output=3
 # of python available on your system to run this test.
 
 [tox:tox]
-envlist = py38, py39, py310, py311, py312
+envlist = py38, py39, py310, py311, py312, py313
 skip_missing_interpreters = true
 
 [testenv]
tests/docker/dockerfiles/python.docker +1 -0
index a3c1321190c..8f0af9ef25f 100644
@@ -14,6 +14,7 @@ ENV PACKAGES \
     python3.10 \
     python3.11 \
     python3.12 \
+    python3.13 \
     python3.8 \
     python3.9
 
Signature · 1 line
2.45.0
Reviewed-by Tested-by on v1 4/4
#12 lore raw

Re: [PATCH 4/4] python: enable testing for 3.13

Quoted 8 lines · John Snow

Python 3.13 is in beta and Fedora 41 is preparing to make it the default system interpreter; enable testing for it.

(In the event problems develop prior to release, it should only impact the check-python-tox job, which is not run by default and is allowed to fail.)

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
author
#13 lore raw
In reply to John Snow
Quoted 21 lines · John Snow

Fix some regressions in check-python-tox that have crept in since Pylint 3.x, and add Python 3.13 support to the pipeline.

GitLab pipeline (before I fixed the missing DCO, but let's be honest, it can't possibly be worth re-running so many tests for just that):
https://gitlab.com/jsnow/qemu/-/pipelines/1349737188

John Snow (4):
python: linter changes for pylint 3.x
python: Do not use pylint 3.2.4 with python 3.8
iotests: Change imports for Python 3.13
python: enable testing for 3.13

 python/qemu/machine/machine.py         | 1 +
 python/qemu/utils/qemu_ga_client.py    | 2 +-
 python/setup.cfg                       | 4 +++-
 tests/docker/dockerfiles/python.docker | 1 +
 tests/qemu-iotests/testenv.py          | 7 ++++++-
 tests/qemu-iotests/testrunner.py       | 9 ++++++---
 6 files changed, 18 insertions(+), 6 deletions(-)
Quoted 3 lines

--
2.45.0

Staging under my Python branch, since I need to get tests green to roll forward with some more substantial changes.

--js

Quoted 1 line