diff mbox series

[ovs-dev] python: use setuptools instead of distutils

Message ID 19f5d1ea288f33486eb751d5c0e341d20a516a18.1652292862.git.tredaelli@redhat.com
State Changes Requested
Headers show
Series [ovs-dev] python: use setuptools instead of distutils | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test fail github build: failed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Timothy Redaelli May 11, 2022, 6:14 p.m. UTC
On Python 3.12, distutils will be removed and it's currently (3.10+)
deprecated (see PEP 632).

Since the suggested and simplest replacement is setuptools, this commit
replaces distutils to use setuptools instead.

Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
---
 python/setup.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Mike Pattrick June 3, 2022, 4:23 p.m. UTC | #1
On Wed, May 11, 2022 at 2:14 PM Timothy Redaelli <tredaelli@redhat.com> wrote:
>
> On Python 3.12, distutils will be removed and it's currently (3.10+)
> deprecated (see PEP 632).
>
> Since the suggested and simplest replacement is setuptools, this commit
> replaces distutils to use setuptools instead.
>
> Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
> ---
>  python/setup.py | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/python/setup.py b/python/setup.py
> index cfe01763f..7c7418bd9 100644
> --- a/python/setup.py
> +++ b/python/setup.py
> @@ -12,9 +12,8 @@
>
>  import sys
>
> -from distutils.command.build_ext import build_ext
> -from distutils.errors import CCompilerError, DistutilsExecError, \
> -    DistutilsPlatformError
> +from setuptools.command.build_ext import build_ext
> +from setuptools.errors import CCompilerError, ExecError, PlatformError


I tried applying this patch on RHEL 8.5 with Python 3.6.8 and
setuptools 39.2.0, and got the following error:

Processing /home/test/ovs_mod/python
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-v08_3iao-build/setup.py", line 16, in <module>
        from setuptools.errors import CCompilerError, ExecError, PlatformError
    ModuleNotFoundError: No module named 'setuptools.errors'

You could use this sort of motif to improve backwards compatibility:

try:
    from A import B
except ImportError:
    from C import D as B


Cheers,
M

>
>  import setuptools
>
> @@ -37,7 +36,7 @@ except IOError:
>            file=sys.stderr)
>      sys.exit(-1)
>
> -ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
> +ext_errors = (CCompilerError, ExecError, PlatformError)
>  if sys.platform == 'win32':
>      ext_errors += (IOError, ValueError)
>
> @@ -53,7 +52,7 @@ class try_build_ext(build_ext):
>      def run(self):
>          try:
>              build_ext.run(self)
> -        except DistutilsPlatformError:
> +        except PlatformError:
>              raise BuildFailed()
>
>      def build_extension(self, ext):
> --
> 2.36.1
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
diff mbox series

Patch

diff --git a/python/setup.py b/python/setup.py
index cfe01763f..7c7418bd9 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -12,9 +12,8 @@ 
 
 import sys
 
-from distutils.command.build_ext import build_ext
-from distutils.errors import CCompilerError, DistutilsExecError, \
-    DistutilsPlatformError
+from setuptools.command.build_ext import build_ext
+from setuptools.errors import CCompilerError, ExecError, PlatformError
 
 import setuptools
 
@@ -37,7 +36,7 @@  except IOError:
           file=sys.stderr)
     sys.exit(-1)
 
-ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
+ext_errors = (CCompilerError, ExecError, PlatformError)
 if sys.platform == 'win32':
     ext_errors += (IOError, ValueError)
 
@@ -53,7 +52,7 @@  class try_build_ext(build_ext):
     def run(self):
         try:
             build_ext.run(self)
-        except DistutilsPlatformError:
+        except PlatformError:
             raise BuildFailed()
 
     def build_extension(self, ext):