* [PATCH 1/3] scripts/container: Turn runtimes class variable into a tuple
2026-01-22 23:27 [PATCH 0/3] scripts/container: Minor fixups suggested by ruff Nathan Chancellor
@ 2026-01-22 23:27 ` Nathan Chancellor
2026-01-23 20:34 ` Guillaume Tucker
2026-01-22 23:27 ` [PATCH 2/3] scripts/container: Use list comprehension in get_names() Nathan Chancellor
` (4 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Nathan Chancellor @ 2026-01-22 23:27 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Guillaume Tucker; +Cc: linux-kbuild
'ruff check --select RUF scripts/container' warns:
RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
--> scripts/container:108:16
|
106 | """List of all supported runtimes"""
107 |
108 | runtimes = [PodmanRuntime, DockerRuntime]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109 |
110 | @classmethod
|
runtimes is never modified so move from a list to a tuple, clearing up
the warning.
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
scripts/container | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/container b/scripts/container
index b05333d8530b..dae475c6d262 100755
--- a/scripts/container
+++ b/scripts/container
@@ -105,7 +105,7 @@ class PodmanRuntime(CommonRuntime):
class Runtimes:
"""List of all supported runtimes"""
- runtimes = [PodmanRuntime, DockerRuntime]
+ runtimes = (PodmanRuntime, DockerRuntime)
@classmethod
def get_names(cls):
--
2.52.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 1/3] scripts/container: Turn runtimes class variable into a tuple
2026-01-22 23:27 ` [PATCH 1/3] scripts/container: Turn runtimes class variable into a tuple Nathan Chancellor
@ 2026-01-23 20:34 ` Guillaume Tucker
0 siblings, 0 replies; 13+ messages in thread
From: Guillaume Tucker @ 2026-01-23 20:34 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild
On 23/01/2026 12:27 am, Nathan Chancellor wrote:
> - runtimes = [PodmanRuntime, DockerRuntime]
> + runtimes = (PodmanRuntime, DockerRuntime)
My 2¢ - A subtle difference between a non-mutable list and a tuple,
is that a list is a series of values with arbitrary length whereas a
tuple is a single variable with a fixed number of values meant to be
used together. Say, coordinates make sense as a tuple but not as a
list. Search results from a database make sense to be stored in a
list but not as a tuple. In this case, there could be any number of
runtimes so it's semantically a list. At least that's why I used a
list, now there may be good reasons for using a tuple too.
Cheers,
Guillaume
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/3] scripts/container: Use list comprehension in get_names()
2026-01-22 23:27 [PATCH 0/3] scripts/container: Minor fixups suggested by ruff Nathan Chancellor
2026-01-22 23:27 ` [PATCH 1/3] scripts/container: Turn runtimes class variable into a tuple Nathan Chancellor
@ 2026-01-22 23:27 ` Nathan Chancellor
2026-01-23 20:38 ` Guillaume Tucker
2026-01-22 23:27 ` [PATCH 3/3] scripts/container: Use iterable unpacking for _get_opts() Nathan Chancellor
` (3 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Nathan Chancellor @ 2026-01-22 23:27 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Guillaume Tucker; +Cc: linux-kbuild
'ruff check --select C4 scripts/container' warns:
C400 Unnecessary generator (rewrite as a list comprehension)
--> scripts/container:113:16
|
111 | def get_names(cls):
112 | """Get a list of all the runtime names"""
113 | return list(runtime.name for runtime in cls.runtimes)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114 |
115 | @classmethod
|
help: Rewrite as a list comprehension
Do as it suggests.
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
scripts/container | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/container b/scripts/container
index dae475c6d262..5afaad762492 100755
--- a/scripts/container
+++ b/scripts/container
@@ -110,7 +110,7 @@ class Runtimes:
@classmethod
def get_names(cls):
"""Get a list of all the runtime names"""
- return list(runtime.name for runtime in cls.runtimes)
+ return [runtime.name for runtime in cls.runtimes]
@classmethod
def get(cls, name):
--
2.52.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 3/3] scripts/container: Use iterable unpacking for _get_opts()
2026-01-22 23:27 [PATCH 0/3] scripts/container: Minor fixups suggested by ruff Nathan Chancellor
2026-01-22 23:27 ` [PATCH 1/3] scripts/container: Turn runtimes class variable into a tuple Nathan Chancellor
2026-01-22 23:27 ` [PATCH 2/3] scripts/container: Use list comprehension in get_names() Nathan Chancellor
@ 2026-01-22 23:27 ` Nathan Chancellor
2026-01-23 20:45 ` Guillaume Tucker
2026-01-23 15:14 ` [PATCH 0/3] scripts/container: Minor fixups suggested by ruff Miguel Ojeda
` (2 subsequent siblings)
5 siblings, 1 reply; 13+ messages in thread
From: Nathan Chancellor @ 2026-01-22 23:27 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Guillaume Tucker; +Cc: linux-kbuild
'ruff check --select RUF scripts/container' warns:
RUF005 Consider iterable unpacking instead of concatenation
--> scripts/container:89:16
|
88 | def _get_opts(self, container_name):
89 | return super()._get_opts(container_name) + [
| ________________^
90 | | '--user', f'{self._uid}:{self._gid}'
91 | | ]
| |_________^
|
help: Replace with iterable unpacking
RUF005 Consider iterable unpacking instead of concatenation
--> scripts/container:100:16
|
99 | def _get_opts(self, container_name):
100 | return super()._get_opts(container_name) + [
| ________________^
101 | | '--userns', f'keep-id:uid={self._uid},gid={self._gid}',
102 | | ]
| |_________^
|
help: Replace with iterable unpacking
Iterable unpacking is more efficient, so switch to it as it suggests
(even if it is unlikely to matter given how small these lists are).
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
scripts/container | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/scripts/container b/scripts/container
index 5afaad762492..09a14f7e29f3 100755
--- a/scripts/container
+++ b/scripts/container
@@ -86,7 +86,8 @@ class DockerRuntime(CommonRuntime):
name = 'docker'
def _get_opts(self, container_name):
- return super()._get_opts(container_name) + [
+ return [
+ *super()._get_opts(container_name),
'--user', f'{self._uid}:{self._gid}'
]
@@ -97,7 +98,8 @@ class PodmanRuntime(CommonRuntime):
name = 'podman'
def _get_opts(self, container_name):
- return super()._get_opts(container_name) + [
+ return [
+ *super()._get_opts(container_name),
'--userns', f'keep-id:uid={self._uid},gid={self._gid}',
]
--
2.52.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 3/3] scripts/container: Use iterable unpacking for _get_opts()
2026-01-22 23:27 ` [PATCH 3/3] scripts/container: Use iterable unpacking for _get_opts() Nathan Chancellor
@ 2026-01-23 20:45 ` Guillaume Tucker
0 siblings, 0 replies; 13+ messages in thread
From: Guillaume Tucker @ 2026-01-23 20:45 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild
On 23/01/2026 12:27 am, Nathan Chancellor wrote:
> - return super()._get_opts(container_name) + [
> + return [
> + *super()._get_opts(container_name),
> '--user', f'{self._uid}:{self._gid}'
> ]
My last 2¢ - Yes it's more efficient to build the list in one go but
I find it easier to read and maintain with the + [...options...]
syntax. I guess it's hard to tell a linter that sometimes, runtime
performance isn't so important.
These are all minor things but they come with interesting language
implications so I thought it was worth a few comments...
Cheers,
Guillaume
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/3] scripts/container: Minor fixups suggested by ruff
2026-01-22 23:27 [PATCH 0/3] scripts/container: Minor fixups suggested by ruff Nathan Chancellor
` (2 preceding siblings ...)
2026-01-22 23:27 ` [PATCH 3/3] scripts/container: Use iterable unpacking for _get_opts() Nathan Chancellor
@ 2026-01-23 15:14 ` Miguel Ojeda
2026-01-23 21:01 ` Nathan Chancellor
2026-01-23 20:26 ` Guillaume Tucker
2026-02-04 8:54 ` Masahiro Yamada
5 siblings, 1 reply; 13+ messages in thread
From: Miguel Ojeda @ 2026-01-23 15:14 UTC (permalink / raw)
To: Nathan Chancellor; +Cc: Nicolas Schier, Guillaume Tucker, linux-kbuild
On Fri, Jan 23, 2026 at 12:27 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> This series fixes a few warnings that I see when running
>
> $ ruff check --select C4,RUF scripts/container
>
> which were the few warnings from my personal ruff.toml that seemed most
> interesting.
I haven't had time to look into the new container support yet, but
having kernel Python scripts Ruff-clean sounds good in general, and I
wonder -- should we consider having a `.ruff.toml` eventually?
At least we have a small `.pylintrc` already, which is quite recent by the way.
I think I recall you also using Black and/or Flake8, for
ClangBuiltLinux-related bits perhaps?
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 0/3] scripts/container: Minor fixups suggested by ruff
2026-01-23 15:14 ` [PATCH 0/3] scripts/container: Minor fixups suggested by ruff Miguel Ojeda
@ 2026-01-23 21:01 ` Nathan Chancellor
2026-01-23 23:55 ` Miguel Ojeda
0 siblings, 1 reply; 13+ messages in thread
From: Nathan Chancellor @ 2026-01-23 21:01 UTC (permalink / raw)
To: Miguel Ojeda; +Cc: Nicolas Schier, Guillaume Tucker, linux-kbuild
On Fri, Jan 23, 2026 at 04:14:16PM +0100, Miguel Ojeda wrote:
> On Fri, Jan 23, 2026 at 12:27 AM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > This series fixes a few warnings that I see when running
> >
> > $ ruff check --select C4,RUF scripts/container
> >
> > which were the few warnings from my personal ruff.toml that seemed most
> > interesting.
>
> I haven't had time to look into the new container support yet, but
> having kernel Python scripts Ruff-clean sounds good in general, and I
> wonder -- should we consider having a `.ruff.toml` eventually?
I think that we should. Even something as simple as the one in the Ruff
docs would keep things consistent:
https://docs.astral.sh/ruff/linter/#rule-selection
I guess the one problem there is consistency amongst developers (since
one's linting workflow is fairly personal) and having a wide range of
Python code across the tree but having a .ruff.toml for people to run if
they want it is harmless.
> At least we have a small `.pylintrc` already, which is quite recent by the way.
Ah, good to know!
> I think I recall you also using Black and/or Flake8, for
> ClangBuiltLinux-related bits perhaps?
We use Ruff and pylint for linting, yapf for formatting. Ruff can
replace flake8 outright with the right configuration in my experience.
Cheers,
Nathan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/3] scripts/container: Minor fixups suggested by ruff
2026-01-23 21:01 ` Nathan Chancellor
@ 2026-01-23 23:55 ` Miguel Ojeda
0 siblings, 0 replies; 13+ messages in thread
From: Miguel Ojeda @ 2026-01-23 23:55 UTC (permalink / raw)
To: Nathan Chancellor; +Cc: Nicolas Schier, Guillaume Tucker, linux-kbuild
On Fri, Jan 23, 2026 at 10:01 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> I think that we should. Even something as simple as the one in the Ruff
> docs would keep things consistent:
>
> https://docs.astral.sh/ruff/linter/#rule-selection
>
> I guess the one problem there is consistency amongst developers (since
> one's linting workflow is fairly personal) and having a wide range of
> Python code across the tree but having a .ruff.toml for people to run if
> they want it is harmless.
Yeah, I think as long as it is optional (and the rules reasonable --
not sure how opinionated the defaults are, but we can tweak things as
needed), then it is a win with little downside.
It is similar to the clang-format situation -- some developers take
advantage of it, others don't.
Over time, the idea would be to try to define the set of rules that
most people is happy with, and thus to get more and more files to
conform.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/3] scripts/container: Minor fixups suggested by ruff
2026-01-22 23:27 [PATCH 0/3] scripts/container: Minor fixups suggested by ruff Nathan Chancellor
` (3 preceding siblings ...)
2026-01-23 15:14 ` [PATCH 0/3] scripts/container: Minor fixups suggested by ruff Miguel Ojeda
@ 2026-01-23 20:26 ` Guillaume Tucker
2026-01-23 23:46 ` Nathan Chancellor
2026-02-04 8:54 ` Masahiro Yamada
5 siblings, 1 reply; 13+ messages in thread
From: Guillaume Tucker @ 2026-01-23 20:26 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier; +Cc: linux-kbuild
Hi Nathan,
On 23/01/2026 12:27 am, Nathan Chancellor wrote:
> Hi all,
>
> This series fixes a few warnings that I see when running
>
> $ ruff check --select C4,RUF scripts/container
>
> which were the few warnings from my personal ruff.toml that seemed most
> interesting.
>
> I will apply these on top of the initial scripts/container change.
>
> ---
> Nathan Chancellor (3):
> scripts/container: Turn runtimes class variable into a tuple
> scripts/container: Use list comprehension in get_names()
> scripts/container: Use iterable unpacking for _get_opts()
>
> scripts/container | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
> ---
> base-commit: 6eac13c876805f61bbb588eaff5ada0b6dc603e8
> change-id: 20260122-scripts-container-ruff-fixes-4d38fc92771a
LGTM - some of these things are arguably more a matter of individual
taste than absolute best practices but it's good to have a
well-defined code quality standard. I typically use Pylint,
Pycodestyle and Mypy, not Ruff or Black. So for the whole series:
Reviewed-by: Guillaume Tucker <gtucker@gtucker.io>
Cheers,
Guillaume
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 0/3] scripts/container: Minor fixups suggested by ruff
2026-01-23 20:26 ` Guillaume Tucker
@ 2026-01-23 23:46 ` Nathan Chancellor
0 siblings, 0 replies; 13+ messages in thread
From: Nathan Chancellor @ 2026-01-23 23:46 UTC (permalink / raw)
To: Guillaume Tucker; +Cc: Nicolas Schier, linux-kbuild
On Fri, Jan 23, 2026 at 09:26:20PM +0100, Guillaume Tucker wrote:
> Hi Nathan,
>
> On 23/01/2026 12:27 am, Nathan Chancellor wrote:
> > Hi all,
> >
> > This series fixes a few warnings that I see when running
> >
> > $ ruff check --select C4,RUF scripts/container
> >
> > which were the few warnings from my personal ruff.toml that seemed most
> > interesting.
> >
> > I will apply these on top of the initial scripts/container change.
> >
> > ---
> > Nathan Chancellor (3):
> > scripts/container: Turn runtimes class variable into a tuple
> > scripts/container: Use list comprehension in get_names()
> > scripts/container: Use iterable unpacking for _get_opts()
> >
> > scripts/container | 10 ++++++----
> > 1 file changed, 6 insertions(+), 4 deletions(-)
> > ---
> > base-commit: 6eac13c876805f61bbb588eaff5ada0b6dc603e8
> > change-id: 20260122-scripts-container-ruff-fixes-4d38fc92771a
>
> LGTM - some of these things are arguably more a matter of individual
> taste than absolute best practices but it's good to have a
> well-defined code quality standard. I typically use Pylint,
> Pycodestyle and Mypy, not Ruff or Black. So for the whole series:
>
> Reviewed-by: Guillaume Tucker <gtucker@gtucker.io>
Thanks a lot for taking a look and providing the comments. I am going to
hold off on this series for a little bit to ponder on providing a
.ruff.toml file first to ensure we have a common understanding around
Python linting in the kernel, especially given a lot of these lints can
be opinionated as you mentioned.
Cheers,
Nathan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/3] scripts/container: Minor fixups suggested by ruff
2026-01-22 23:27 [PATCH 0/3] scripts/container: Minor fixups suggested by ruff Nathan Chancellor
` (4 preceding siblings ...)
2026-01-23 20:26 ` Guillaume Tucker
@ 2026-02-04 8:54 ` Masahiro Yamada
5 siblings, 0 replies; 13+ messages in thread
From: Masahiro Yamada @ 2026-02-04 8:54 UTC (permalink / raw)
To: Nathan Chancellor; +Cc: Nicolas Schier, Guillaume Tucker, linux-kbuild
On Fri, Jan 23, 2026 at 8:27 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> Hi all,
>
> This series fixes a few warnings that I see when running
>
> $ ruff check --select C4,RUF scripts/container
>
> which were the few warnings from my personal ruff.toml that seemed most
> interesting.
>
> I will apply these on top of the initial scripts/container change.
>
> ---
> Nathan Chancellor (3):
> scripts/container: Turn runtimes class variable into a tuple
> scripts/container: Use list comprehension in get_names()
> scripts/container: Use iterable unpacking for _get_opts()
>
> scripts/container | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
scripts/container is written in a generic way.
In my understanding, this runs an arbitrary
command in a container, and that's it.
Nothing is related to Kbuild.
$ scripts/container -i debian:trixie echo hello
hello
If this script is really useful,
why don't you keep this outside the kernel code
so that non-kernel developers can use it?
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 13+ messages in thread