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

Javi Merino posted 5 patches 1 year, 1 month ago
[XEN PATCH v2 2/5] tools: convert setup.py to use setuptools
Posted by Javi Merino 1 year, 1 month ago
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(-)

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 = "../.."
-- 
2.41.0


Re: [XEN PATCH v2 2/5] tools: convert setup.py to use setuptools
Posted by Andrew Cooper 1 year, 1 month ago
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

Re: [XEN PATCH v2 2/5] tools: convert setup.py to use setuptools
Posted by Javi Merino 1 year ago
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