Change request #4223

Replace distutils by setuptools

Added by Knödlseder Jürgen over 1 year ago. Updated over 1 year ago.

Status:ClosedStart date:03/14/2023
Priority:HighDue date:
Assigned To:Knödlseder Jürgen% Done:

100%

Category:-
Target version:2.1.0
Duration:

Description

In Python 3.12, distutils will be removed (see https://peps.python.org/pep-0632/).

This should in principle be easy, since

Code already exists in setuptools to transparently switch setup.py files using distutils onto their equivalents, and so most working build scripts are already known to work with setuptools. Such scripts may need to update their import statements. Consult the setuptools documentation for specific migration advice.


Recurrence

No recurrence.


Related issues

Related to GammaLib - Bug #4222: gammalib 2.0 crashes when the test suite is called Closed 03/13/2023

History

#1 Updated by Knödlseder Jürgen over 1 year ago

Note that this change request also applies to ctools.

#2 Updated by Knödlseder Jürgen over 1 year ago

  • Related to Bug #4222: gammalib 2.0 crashes when the test suite is called added

#3 Updated by Knödlseder Jürgen over 1 year ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 10

Replacing distutils in setup.py is straight forward:

from setuptools import setup, Extension
import sysconfig

Interestingly, the resulting installation differs from the one before, with things now installed into an egg file:
$ ls /usr/local/gamma/lib/python2.7/site-packages/
easy-install.pth
gammalib
gammalib-2.1.0.dev0-py2.7-macosx-10.14-intel.egg
site.py
site.pyc
Note that the gammalib folder is created by the Makefile.am and is not related to the setup.py change. See #4222 for the side-effects of the new installation. I need now to make sure that all the test stuff is also installed into the Python egg.

#4 Updated by Knödlseder Jürgen over 1 year ago

Here the new egg creation step during make:

creating build/bdist.macosx-10.14-intel/egg/EGG-INFO
copying gammalib.egg-info/PKG-INFO -> build/bdist.macosx-10.14-intel/egg/EGG-INFO
copying gammalib.egg-info/SOURCES.txt -> build/bdist.macosx-10.14-intel/egg/EGG-INFO
copying gammalib.egg-info/dependency_links.txt -> build/bdist.macosx-10.14-intel/egg/EGG-INFO
copying gammalib.egg-info/top_level.txt -> build/bdist.macosx-10.14-intel/egg/EGG-INFO
writing build/bdist.macosx-10.14-intel/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/gammalib-2.1.0.dev0-py2.7-macosx-10.14-intel.egg' and adding 'build/bdist.macosx-10.14-intel/egg' to it
removing 'build/bdist.macosx-10.14-intel/egg' (and everything under it)
Creating /usr/local/gamma/lib/python2.7/site-packages/site.py
Processing gammalib-2.1.0.dev0-py2.7-macosx-10.14-intel.egg
Copying gammalib-2.1.0.dev0-py2.7-macosx-10.14-intel.egg to /usr/local/gamma/lib/python2.7/site-packages
Adding gammalib 2.1.0.dev0 to easy-install.pth file

It seems to be the cleanest to handle everything in tests also in setup.py so that there is no more interference with the actions in the makefiles.

#5 Updated by Knödlseder Jürgen over 1 year ago

  • % Done changed from 10 to 20

There is an issue with using the tests in an egg file, and since egg files are anyways deprecated, I remove the additional code from setup.py and added some options to the installation that prevent the building of an egg file:

$(PYTHON) setup.py install --prefix=$(DESTDIR)$(prefix) --single-version-externally-managed --root=/

I merged the code into the integration branch and submitted for checking on the CI system.

#6 Updated by Knödlseder Jürgen over 1 year ago

On Linux systems I get the error

/usr/bin/python setup.py build_ext
Traceback (most recent call last):
  File "setup.py", line 22, in <module>
    import sysconfig
ImportError: No module named sysconfig
This is because the sysconfig was only introduced in Python version 3.2. I therefore added the code
import sys
if sys.version_info < (3, 2):
    from distutils import sysconfig
else:
    import sysconfig
at the beginning of setup.py.

#7 Updated by Knödlseder Jürgen over 1 year ago

  • % Done changed from 20 to 30

I figured out that setuptools is actually third party, and not necessary installed with Python. I also figured out that the sysconfig module is only available since Python 3.2. Hence some code was added to fallback to distutils in case that setuptools and sysconfig was not available.

#8 Updated by Knödlseder Jürgen over 1 year ago

  • Status changed from In Progress to Feedback
  • % Done changed from 30 to 90

Both GammaLib and ctools went through the validation of the code in the integration branch. I merged the code into devel. Still need to check all Python versions.

#9 Updated by Knödlseder Jürgen over 1 year ago

I installed Python version 3.10 and 3.11 on the CI system and GammaLib passed all different Python versions.

#10 Updated by Knödlseder Jürgen over 1 year ago

  • Status changed from Feedback to Closed
  • % Done changed from 90 to 100

Also the ctools Python tests passed, so I close the issue now.

Also available in: Atom PDF