Message ID | 7b3ecf211f60e0d6f7a4d146b62f9c28eff003f5.1694450145.git.javi.merino@cloud.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | python: Use setuptools instead of the deprecated distutils | expand |
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. The distutils.sysconfig is available as sysconfig module in > stdlib since Python 3.2, so use that directly. > > Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> This breaks Py2, doesn't it? > --- > m4/python_devel.m4 | 28 ++++++++++++++-------------- > tools/libs/stat/Makefile | 4 ++-- > 2 files changed, 16 insertions(+), 16 deletions(-) > > diff --git a/m4/python_devel.m4 b/m4/python_devel.m4 > index bbf1e0354b..bb60857b03 100644 > --- a/m4/python_devel.m4 > +++ b/m4/python_devel.m4 > @@ -5,21 +5,21 @@ ac_previous_libs=$LIBS > AC_PATH_PROG([pyconfig], [$PYTHON-config], [no]) > AS_IF([test x"$pyconfig" = x"no"], [ > dnl For those that don't have python-config > - CPPFLAGS="$CFLAGS `$PYTHON -c 'import distutils.sysconfig; \ > - print("-I" + distutils.sysconfig.get_config_var("INCLUDEPY"))'`" > - CPPFLAGS="$CPPFLAGS `$PYTHON -c 'import distutils.sysconfig; \ > - print(distutils.sysconfig.get_config_var("CFLAGS"))'`" > - LDFLAGS="$LDFLAGS `$PYTHON -c 'import distutils.sysconfig; \ > - print("-L" + distutils.sysconfig.get_python_lib(plat_specific=1,\ > + CPPFLAGS="$CFLAGS `$PYTHON -c 'import sysconfig; \ > + print("-I" + sysconfig.get_config_var("INCLUDEPY"))'`" > + CPPFLAGS="$CPPFLAGS `$PYTHON -c 'import sysconfig; \ > + print(sysconfig.get_config_var("CFLAGS"))'`" > + LDFLAGS="$LDFLAGS `$PYTHON -c 'import sysconfig; \ > + print("-L" + sysconfig.get_python_lib(plat_specific=1,\ > standard_lib=1) + "/config")'`" > - LDFLAGS="$LDFLAGS `$PYTHON -c 'import distutils.sysconfig; \ > - print(distutils.sysconfig.get_config_var("LINKFORSHARED"))'`" > - LDFLAGS="$LDFLAGS `$PYTHON -c 'import distutils.sysconfig; \ > - print(distutils.sysconfig.get_config_var("LDFLAGS"))'`" > - LIBS="$LIBS `$PYTHON -c 'import distutils.sysconfig; \ > - print(distutils.sysconfig.get_config_var("LIBS"))'`" > - LIBS="$LIBS `$PYTHON -c 'import distutils.sysconfig; \ > - print(distutils.sysconfig.get_config_var("SYSLIBS"))'`" > + LDFLAGS="$LDFLAGS `$PYTHON -c 'import sysconfig; \ > + print(sysconfig.get_config_var("LINKFORSHARED"))'`" > + LDFLAGS="$LDFLAGS `$PYTHON -c 'import sysconfig; \ > + print(sysconfig.get_config_var("LDFLAGS"))'`" > + LIBS="$LIBS `$PYTHON -c 'import sysconfig; \ > + print(sysconfig.get_config_var("LIBS"))'`" > + LIBS="$LIBS `$PYTHON -c 'import sysconfig; \ > + print(sysconfig.get_config_var("SYSLIBS"))'`" I know the code was terrible to start with, but it's absurd to fork multiple processes just to append different fields into the same variable. Why not have a config.py in this directory which takes CPPFLAGS/LDFLAGS/LIBS as an input prints everything it needs. Then you can repeat the import trick to prefer sysconfig and fall back to distutils if sysconfig isn't available. ~Andrew
On Tue, Sep 12, 2023 at 11:38:04AM +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. The distutils.sysconfig is available as sysconfig module in > > stdlib since Python 3.2, so use that directly. > > > > Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> > > This breaks Py2, doesn't it? I was thinking that too, but "sysconfig" module seems to be in Python 2.7 too. > > --- > > m4/python_devel.m4 | 28 ++++++++++++++-------------- > > tools/libs/stat/Makefile | 4 ++-- > > 2 files changed, 16 insertions(+), 16 deletions(-) > > > > diff --git a/m4/python_devel.m4 b/m4/python_devel.m4 > > index bbf1e0354b..bb60857b03 100644 > > --- a/m4/python_devel.m4 > > +++ b/m4/python_devel.m4 > > @@ -5,21 +5,21 @@ ac_previous_libs=$LIBS > > AC_PATH_PROG([pyconfig], [$PYTHON-config], [no]) > > AS_IF([test x"$pyconfig" = x"no"], [ > > dnl For those that don't have python-config > > - CPPFLAGS="$CFLAGS `$PYTHON -c 'import distutils.sysconfig; \ > > - print("-I" + distutils.sysconfig.get_config_var("INCLUDEPY"))'`" > > - CPPFLAGS="$CPPFLAGS `$PYTHON -c 'import distutils.sysconfig; \ > > - print(distutils.sysconfig.get_config_var("CFLAGS"))'`" > > - LDFLAGS="$LDFLAGS `$PYTHON -c 'import distutils.sysconfig; \ > > - print("-L" + distutils.sysconfig.get_python_lib(plat_specific=1,\ > > + CPPFLAGS="$CFLAGS `$PYTHON -c 'import sysconfig; \ > > + print("-I" + sysconfig.get_config_var("INCLUDEPY"))'`" > > + CPPFLAGS="$CPPFLAGS `$PYTHON -c 'import sysconfig; \ > > + print(sysconfig.get_config_var("CFLAGS"))'`" > > + LDFLAGS="$LDFLAGS `$PYTHON -c 'import sysconfig; \ > > + print("-L" + sysconfig.get_python_lib(plat_specific=1,\ > > standard_lib=1) + "/config")'`" > > - LDFLAGS="$LDFLAGS `$PYTHON -c 'import distutils.sysconfig; \ > > - print(distutils.sysconfig.get_config_var("LINKFORSHARED"))'`" > > - LDFLAGS="$LDFLAGS `$PYTHON -c 'import distutils.sysconfig; \ > > - print(distutils.sysconfig.get_config_var("LDFLAGS"))'`" > > - LIBS="$LIBS `$PYTHON -c 'import distutils.sysconfig; \ > > - print(distutils.sysconfig.get_config_var("LIBS"))'`" > > - LIBS="$LIBS `$PYTHON -c 'import distutils.sysconfig; \ > > - print(distutils.sysconfig.get_config_var("SYSLIBS"))'`" > > + LDFLAGS="$LDFLAGS `$PYTHON -c 'import sysconfig; \ > > + print(sysconfig.get_config_var("LINKFORSHARED"))'`" > > + LDFLAGS="$LDFLAGS `$PYTHON -c 'import sysconfig; \ > > + print(sysconfig.get_config_var("LDFLAGS"))'`" > > + LIBS="$LIBS `$PYTHON -c 'import sysconfig; \ > > + print(sysconfig.get_config_var("LIBS"))'`" > > + LIBS="$LIBS `$PYTHON -c 'import sysconfig; \ > > + print(sysconfig.get_config_var("SYSLIBS"))'`" > > I know the code was terrible to start with, but it's absurd to fork > multiple processes just to append different fields into the same variable. > > Why not have a config.py in this directory which takes > CPPFLAGS/LDFLAGS/LIBS as an input prints everything it needs. Then you > can repeat the import trick to prefer sysconfig and fall back to > distutils if sysconfig isn't available. > > ~Andrew
On 12/09/2023 12:50 pm, Marek Marczykowski-Górecki wrote: > On Tue, Sep 12, 2023 at 11:38:04AM +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. The distutils.sysconfig is available as sysconfig module in >>> stdlib since Python 3.2, so use that directly. >>> >>> Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> >> This breaks Py2, doesn't it? > I was thinking that too, but "sysconfig" module seems to be in Python > 2.7 too. Oh, so it is. Lovely that the documentation says this... It seems to have appeared in Py2.7 and 3.2 together. https://docs.python.org/2.7/library/sysconfig.html I notice that README currently says Py2.6. We can definitely bump that to 2.7, and take this patch as-is. ~Andrew
On Tue, Sep 12, 2023 at 01:17:21PM +0100, Andrew Cooper wrote: > On 12/09/2023 12:50 pm, Marek Marczykowski-Górecki wrote: > > On Tue, Sep 12, 2023 at 11:38:04AM +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. The distutils.sysconfig is available as sysconfig module in > >>> stdlib since Python 3.2, so use that directly. > >>> > >>> Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> > >> This breaks Py2, doesn't it? > > I was thinking that too, but "sysconfig" module seems to be in Python > > 2.7 too. Yes, I forgot to say it. I tested this with python2 as well as python3. I did: PYTHON=$(which python) ./configure make -C tools/pygrub clean && make -C tools/pygrub make -C tools/python clean && make -C tools/python with python being: $ python --version Python 2.7.18.6 I did the same test with just `./configure` and python3 being: $ python3 --version Python 3.12.0rc2 > Oh, so it is. Lovely that the documentation says this... > > It seems to have appeared in Py2.7 and 3.2 together. > https://docs.python.org/2.7/library/sysconfig.html > > I notice that README currently says Py2.6. We can definitely bump that > to 2.7, and take this patch as-is. Marek had a patch that bumped the minimum version to 3.2[0] but I dropped it from the series as we were going to keep the support for python2. [0] https://lore.kernel.org/xen-devel/20230316171634.320626-4-marmarek@invisiblethingslab.com/ I will bump the minimum version of python to 2.7 in the README. Cheers, Javi
diff --git a/m4/python_devel.m4 b/m4/python_devel.m4 index bbf1e0354b..bb60857b03 100644 --- a/m4/python_devel.m4 +++ b/m4/python_devel.m4 @@ -5,21 +5,21 @@ ac_previous_libs=$LIBS AC_PATH_PROG([pyconfig], [$PYTHON-config], [no]) AS_IF([test x"$pyconfig" = x"no"], [ dnl For those that don't have python-config - CPPFLAGS="$CFLAGS `$PYTHON -c 'import distutils.sysconfig; \ - print("-I" + distutils.sysconfig.get_config_var("INCLUDEPY"))'`" - CPPFLAGS="$CPPFLAGS `$PYTHON -c 'import distutils.sysconfig; \ - print(distutils.sysconfig.get_config_var("CFLAGS"))'`" - LDFLAGS="$LDFLAGS `$PYTHON -c 'import distutils.sysconfig; \ - print("-L" + distutils.sysconfig.get_python_lib(plat_specific=1,\ + CPPFLAGS="$CFLAGS `$PYTHON -c 'import sysconfig; \ + print("-I" + sysconfig.get_config_var("INCLUDEPY"))'`" + CPPFLAGS="$CPPFLAGS `$PYTHON -c 'import sysconfig; \ + print(sysconfig.get_config_var("CFLAGS"))'`" + LDFLAGS="$LDFLAGS `$PYTHON -c 'import sysconfig; \ + print("-L" + sysconfig.get_python_lib(plat_specific=1,\ standard_lib=1) + "/config")'`" - LDFLAGS="$LDFLAGS `$PYTHON -c 'import distutils.sysconfig; \ - print(distutils.sysconfig.get_config_var("LINKFORSHARED"))'`" - LDFLAGS="$LDFLAGS `$PYTHON -c 'import distutils.sysconfig; \ - print(distutils.sysconfig.get_config_var("LDFLAGS"))'`" - LIBS="$LIBS `$PYTHON -c 'import distutils.sysconfig; \ - print(distutils.sysconfig.get_config_var("LIBS"))'`" - LIBS="$LIBS `$PYTHON -c 'import distutils.sysconfig; \ - print(distutils.sysconfig.get_config_var("SYSLIBS"))'`" + LDFLAGS="$LDFLAGS `$PYTHON -c 'import sysconfig; \ + print(sysconfig.get_config_var("LINKFORSHARED"))'`" + LDFLAGS="$LDFLAGS `$PYTHON -c 'import sysconfig; \ + print(sysconfig.get_config_var("LDFLAGS"))'`" + LIBS="$LIBS `$PYTHON -c 'import sysconfig; \ + print(sysconfig.get_config_var("LIBS"))'`" + LIBS="$LIBS `$PYTHON -c 'import sysconfig; \ + print(sysconfig.get_config_var("SYSLIBS"))'`" ], [ dnl If python-config is found use it CPPFLAGS="$CFLAGS `$PYTHON-config --cflags`" diff --git a/tools/libs/stat/Makefile b/tools/libs/stat/Makefile index ee5c42bf7b..a968eaff48 100644 --- a/tools/libs/stat/Makefile +++ b/tools/libs/stat/Makefile @@ -73,8 +73,8 @@ $(PYLIB): $(PYSRC) python-bindings: $(PYLIB) $(PYMOD) pythonlibdir = $(shell $(PYTHON) -c \ - 'import distutils.sysconfig as cfg; \ - print(cfg.get_python_lib(False, False, prefix="$(prefix)"))') + 'import sysconfig; \ + print(sysconfig.get_python_lib("platlib", vars={"platbase": "$(prefix)"}))') .PHONY: install-python-bindings install-python-bindings: $(PYLIB) $(PYMOD)