diff mbox series

[XEN,v2,2/5] tools: convert setup.py to use setuptools

Message ID 9bbf71efc710dc869baf0c5ba926630e81181620.1694450145.git.javi.merino@cloud.com (mailing list archive)
State New, archived
Headers show
Series python: Use setuptools instead of the deprecated distutils | expand

Commit Message

Javi Merino Sept. 11, 2023, 4:51 p.m. UTC
From: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>

Python distutils is deprecated and is going to be removed in Python
3.12. Migrate to setuptools.
Setuptools in Python 3.11 complains:
SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
Keep using setup.py anyway to build C extension.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 tools/pygrub/setup.py | 8 ++++++--
 tools/python/setup.py | 8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

Comments

Andrew Cooper Sept. 12, 2023, 10:22 a.m. UTC | #1
On 11/09/2023 5:51 pm, Javi Merino wrote:
> From: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
>
> Python distutils is deprecated and is going to be removed in Python
> 3.12. Migrate to setuptools.
> Setuptools in Python 3.11 complains:
> SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
> Keep using setup.py anyway to build C extension.
>
> Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>

Throughout the commit message, s/use/support/ seeing as we're not
removing distutils.

Next, this needs a SoB from you because you've changed the patch from
what Marek originally wrote.


> diff --git a/tools/pygrub/setup.py b/tools/pygrub/setup.py
> index 502aa4df2d..f9e8feb2e6 100644
> --- a/tools/pygrub/setup.py
> +++ b/tools/pygrub/setup.py
> @@ -1,5 +1,9 @@
> -from distutils.core import setup, Extension
> -from distutils.ccompiler import new_compiler
> +try:
> +    from setuptools import setup, Extension
> +except ImportError:
> +    # distutils was removed in Python 3.12.  If this import fails,
> +    # install setuptools.
> +    from distutils.core import setup, Extension

Finally, this feels a little unnecessary.  How about just:

# Prefer setuptools, fall back to distutils
try:
    from setuptools import setup, Extension
except ImportError:
    from distutils.core import setup, Extension

~Andrew
Javi Merino Sept. 18, 2023, 10:13 p.m. UTC | #2
On Tue, Sep 12, 2023 at 11:22:56AM +0100, Andrew Cooper wrote:
> On 11/09/2023 5:51 pm, Javi Merino wrote:
> > From: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
> >
> > Python distutils is deprecated and is going to be removed in Python
> > 3.12. Migrate to setuptools.
> > Setuptools in Python 3.11 complains:
> > SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
> > Keep using setup.py anyway to build C extension.
> >
> > Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
> 
> Throughout the commit message, s/use/support/ seeing as we're not
> removing distutils.

Ok.

> Next, this needs a SoB from you because you've changed the patch from
> what Marek originally wrote.

Done

> > diff --git a/tools/pygrub/setup.py b/tools/pygrub/setup.py
> > index 502aa4df2d..f9e8feb2e6 100644
> > --- a/tools/pygrub/setup.py
> > +++ b/tools/pygrub/setup.py
> > @@ -1,5 +1,9 @@
> > -from distutils.core import setup, Extension
> > -from distutils.ccompiler import new_compiler
> > +try:
> > +    from setuptools import setup, Extension
> > +except ImportError:
> > +    # distutils was removed in Python 3.12.  If this import fails,
> > +    # install setuptools.
> > +    from distutils.core import setup, Extension
> 
> Finally, this feels a little unnecessary.  How about just:
> 
> # Prefer setuptools, fall back to distutils
> try:
>     from setuptools import setup, Extension
> except ImportError:
>     from distutils.core import setup, Extension

Done
diff mbox series

Patch

diff --git a/tools/pygrub/setup.py b/tools/pygrub/setup.py
index 502aa4df2d..f9e8feb2e6 100644
--- a/tools/pygrub/setup.py
+++ b/tools/pygrub/setup.py
@@ -1,5 +1,9 @@ 
-from distutils.core import setup, Extension
-from distutils.ccompiler import new_compiler
+try:
+    from setuptools import setup, Extension
+except ImportError:
+    # distutils was removed in Python 3.12.  If this import fails,
+    # install setuptools.
+    from distutils.core import setup, Extension
 import os
 import sys
 
diff --git a/tools/python/setup.py b/tools/python/setup.py
index 721a3141d7..e8111bd098 100644
--- a/tools/python/setup.py
+++ b/tools/python/setup.py
@@ -1,5 +1,9 @@ 
-
-from distutils.core import setup, Extension
+try:
+    from setuptools import setup, Extension
+except ImportError:
+    # distutils was removed in Python 3.12.  If this import fails,
+    # install setuptools.
+    from distutils.core import setup, Extension
 import os, sys
 
 XEN_ROOT = "../.."