OSGeo / grass

GRASS GIS - free and open-source geospatial processing engine
https://grass.osgeo.org
Other
852 stars 309 forks source link

[Bug] Python 3.12 distutils removal #2601

Closed neteler closed 2 years ago

neteler commented 2 years ago

Describe the bug

In Python 3.10 and 3.11, distutils will be formally marked as deprecated. Code that imports distutils will no longer work from Python 3.12.

The suggested migration path is to use the equivalent (though not identical) imports from setuptools (see [5]), or to migrate to an alternative build backend (see PEP 517).

For details, see https://peps.python.org/pep-0632/

Code scanning

GRASS GIS core:

python/grass/utils/download.py
123:                # However, distutils.copy_tree() may fail to create directories before

scripts/g.extension/testsuite/test_addons_download.py
20:from distutils.spawn import find_executable

scripts/g.extension/g.extension.py
169:    from distutils.dir_util import copy_tree

GRASS-addons:

src/imagery/i.ann.maskrcnn/maskrcnnlib/utils.py
27:from distutils.version import LooseVersion

src/imagery/i.ann.maskrcnn/maskrcnnlib/model.py
32:from distutils.version import LooseVersion

Why relevant?

GRASS GIS will no longer compile in future Fedora (and other distros): See e.g. here: https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/N6ITYHLRWIDNYNXGPYG2ZHF3ZLQWZN7L/

petrasovaa commented 2 years ago

The most pressing issue in g.extension.py should be solved in #2592.

Looks like we could replace from distutils.spawn import find_executable with from shutil import which.

Regarding the addon, there is no clear replacement in standard library, there are external packages like https://pypi.org/project/looseversion/, but maybe it could be solved by manual parsing/comparison of the versions.

ninsbl commented 2 years ago

https://github.com/OSGeo/grass/pull/1158 has now been updated accordingly...

Version-comparison in the addon could also be done "manually" with splitting the version string and extracting a major and minor integer, no?

ninsbl commented 2 years ago

Now, distutils is only imported for older Python versions: https://github.com/OSGeo/grass/search?q=distutils

So the issue can be considered fixed.