build: use setuptools.command.build when available

Setuptools 62.4.0 adds setuptools.command.build to transparently replace
the old distutils equivalent; hence, use it when available to fully
switch away from distutils.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
This commit is contained in:
Pino Toscano 2024-03-24 10:19:28 +01:00 committed by Cole Robinson
parent 4f4e73d017
commit 231a3dbc87

View File

@ -20,16 +20,17 @@ import subprocess
import setuptools
import setuptools.command.install
import setuptools.command.install_egg_info
# distutils will be deprecated in python 3.12 in favor of setuptools,
# but as of this writing there's standard no setuptools way to extend the
# 'build' commands which are the only standard commands we trigger.
# https://github.com/pypa/setuptools/issues/2591
#
# Newer setuptools will transparently support 'import distutils' though.
# That can be overridden with SETUPTOOLS_USE_DISTUTILS env variable
import distutils.command.build # pylint: disable=wrong-import-order,deprecated-module,import-error
try:
# Use the setuptools build command with setuptools >= 62.4.0
import setuptools.command.build
BUILD_COMMAND_CLASS = setuptools.command.build.build
except ImportError:
# Use distutils with an older setuptools version
#
# Newer setuptools will transparently support 'import distutils' though.
# That can be overridden with SETUPTOOLS_USE_DISTUTILS env variable
import distutils.command.build # pylint: disable=wrong-import-order,deprecated-module,import-error
BUILD_COMMAND_CLASS = distutils.command.build.build
SYSPREFIX = sysconfig.get_config_var("prefix")
@ -131,7 +132,7 @@ class my_build_i18n(setuptools.Command):
self.distribution.data_files.append((target, files_merged))
class my_build(distutils.command.build.build):
class my_build(BUILD_COMMAND_CLASS):
def _make_bin_wrappers(self):
template = """#!/usr/bin/env python3