diff mbox series

kunit: tool: Assert version requirement

Message ID 20210616094033.18246-1-sj38.park@gmail.com
State Superseded
Headers show
Series kunit: tool: Assert version requirement | expand

Commit Message

SeongJae Park June 16, 2021, 9:40 a.m. UTC
From: SeongJae Park <sjpark@amazon.de>

Commit 87c9c1631788 ("kunit: tool: add support for QEMU") on the 'next'
tree adds 'from __future__ import annotations' in 'kunit_kernel.py'.
Because it is supported on only >=3.7 Python, people using older Python
will get below error:

    Traceback (most recent call last):
      File "./tools/testing/kunit/kunit.py", line 20, in <module>
        import kunit_kernel
      File "/home/sjpark/linux/tools/testing/kunit/kunit_kernel.py", line 9
        from __future__ import annotations
        ^
    SyntaxError: future feature annotations is not defined

This commit adds a version assertion in 'kunit.py', so that people get
more explicit error message like below:

   Traceback (most recent call last):
      File "./tools/testing/kunit/kunit.py", line 15, in <module>
        assert sys.version_info >= (3, 7)
    AssertionError

Signed-off-by: SeongJae Park <sjpark@amazon.de>
---
 tools/testing/kunit/kunit.py | 2 ++
 1 file changed, 2 insertions(+)

Comments

Daniel Latypov June 16, 2021, 9:14 p.m. UTC | #1
On Wed, Jun 16, 2021 at 2:40 AM SeongJae Park <sj38.park@gmail.com> wrote:
>
> From: SeongJae Park <sjpark@amazon.de>
>
> Commit 87c9c1631788 ("kunit: tool: add support for QEMU") on the 'next'
> tree adds 'from __future__ import annotations' in 'kunit_kernel.py'.
> Because it is supported on only >=3.7 Python, people using older Python
> will get below error:

Ah, we had been fine with just using 3.6 before this (and could have
dropped down to 3.5 with a few lines changed).

But 3.7 came out initially in 2018*, so I assume we're probably fine
to rely on that in kunit tool.
*https://www.python.org/downloads/release/python-370/

>
>     Traceback (most recent call last):
>       File "./tools/testing/kunit/kunit.py", line 20, in <module>
>         import kunit_kernel
>       File "/home/sjpark/linux/tools/testing/kunit/kunit_kernel.py", line 9
>         from __future__ import annotations
>         ^
>     SyntaxError: future feature annotations is not defined
>
> This commit adds a version assertion in 'kunit.py', so that people get
> more explicit error message like below:
>
>    Traceback (most recent call last):
>       File "./tools/testing/kunit/kunit.py", line 15, in <module>
>         assert sys.version_info >= (3, 7)
>     AssertionError
>
> Signed-off-by: SeongJae Park <sjpark@amazon.de>

Acked-by: Daniel Latypov <dlatypov@google.com>

> ---
>  tools/testing/kunit/kunit.py | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
> index be8d8d4a4e08..748d88178506 100755
> --- a/tools/testing/kunit/kunit.py
> +++ b/tools/testing/kunit/kunit.py
> @@ -12,6 +12,8 @@ import sys
>  import os
>  import time
>
> +assert sys.version_info >= (3, 7)

Do we perhaps want
  assert sys.version_info >= (3, 7), "Python version is too old"

Then the error message would be
  Traceback (most recent call last):
    File "./tools/testing/kunit/kunit.py", line 15, in <module>
      assert sys.version_info >= (3, 7), "Python version is too old"
  AssertionError: Python version is too old

I assume kernel devs know some Python, but not necessarily that
sys.version_info == "my python version"

> +
>  from collections import namedtuple
>  from enum import Enum, auto
>
> --
> 2.17.1
>
> --
> You received this message because you are subscribed to the Google Groups "KUnit Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20210616094033.18246-1-sj38.park%40gmail.com.
diff mbox series

Patch

diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index be8d8d4a4e08..748d88178506 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -12,6 +12,8 @@  import sys
 import os
 import time
 
+assert sys.version_info >= (3, 7)
+
 from collections import namedtuple
 from enum import Enum, auto