Skip to content

Remove distutils #56527

@driazati

Description

@driazati

Distutils is deprecated via PEP 632 in Python 3.10+ and will be removed in 3.12. There's no reason for us to keep using it, so we should get rid of all usages so it doesn't bite us later when 3.10 rolls around.

Usages:

$ ag --ignore third_party distutils
caffe2/CMakeLists.txt
1707:      from distutils import sysconfig
1719:      from distutils import sysconfig

cmake/Dependencies.cmake
938:    # distutils.sysconfig, if it's installed, is more accurate than sysconfig,
940:    pycmd_no_exit(_py_inc _exitcode "from distutils import sysconfig; print(sysconfig.get_python_inc())")
943:      message(STATUS "Setting Python's include dir to ${_py_inc} from distutils.sysconfig")

scripts/build_android.sh
64:  CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$($PYTHON -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')")

scripts/build_mobile.sh
18:CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')")

scripts/get_python_cmake_flags.py
18:from distutils import sysconfig

scripts/build_ios.sh
16:  CMAKE_ARGS+=("-DCMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')")

test/test_spectral_ops.py
16:from distutils.version import LooseVersion

tools/setup_helpers/cmake.py
10:import distutils.sysconfig
11:from distutils.version import LooseVersion
233:            'CMAKE_PREFIX_PATH': distutils.sysconfig.get_python_lib()
319:                      PYTHON_INCLUDE_DIR=distutils.sysconfig.get_python_inc(),

tools/build_pytorch_libs.py
10:    from distutils._msvccompiler import _get_vc_env

tools/generate_torch_version.py
5:from distutils.util import strtobool

torch/package/_stdlib.py
79:    "distutils",
298:    "distutils",
516:    "distutils",
732:    "distutils",

torch/testing/_internal/common_cuda.py
9:from distutils.version import LooseVersion

torch/testing/_internal/common_methods_invocations.py
37:from distutils.version import LooseVersion

torch/utils/tensorboard/__init__.py
2:from distutils.version import LooseVersion

torch/utils/cpp_extension.py
338:    Fallbacks to the standard distutils backend if Ninja is not available.
368:                   '{}. Falling back to using the slow distutils backend.')
479:            # of distutils.UnixCCompiler). See the following link.
480:            # https://github.com/python/cpython/blob/f03a8f8d5001963ad5b5b28dbd95497e9cc15596/Lib/distutils/ccompiler.py#L564-L567
484:            # we update our python version (which is when distutils can be
697:        # https://github.com/python/cpython/blob/dc0284ee8f7a270b6005467f26d8e5773d76e959/Lib/distutils/ccompiler.py#L511
737:        if IS_WINDOWS and 'VSCMD_ARG_TGT_ARCH' in os.environ and 'DISTUTILS_USE_SDK' not in os.environ:
738:            msg = ('It seems that the VC environment is activated but DISTUTILS_USE_SDK is not set.'
740:                   'Please set `DISTUTILS_USE_SDK=1` and try again.')
1638:        from distutils.util import get_platform
1639:        from distutils._msvccompiler import _get_vc_env

README.md
316:set DISTUTILS_USE_SDK=1

mypy.ini
190:[mypy-distutils.*]

setup.py
24:#     the C/C++ compiler to use (NB: the CXX flag has no effect for distutils
25:#     compiles, because distutils always uses CC to compile, even for C++
200:from distutils import core
201:from distutils.core import Distribution
202:from distutils.errors import DistutilsArgError
205:import distutils.command.clean
206:import distutils.command.sdist
207:import distutils.sysconfig
270:rel_site_packages = distutils.sysconfig.get_python_lib(prefix='')
272:full_site_packages = distutils.sysconfig.get_python_lib()
276:        distutils.sysconfig.get_config_var("prefix"),
277:        distutils.sysconfig.get_config_var("VERSION"))
283:            distutils.sysconfig.get_config_var("VERSION"))
286:        distutils.sysconfig.get_config_var("LIBDIR"),
287:        distutils.sysconfig.get_config_var("INSTSONAME"))
288:cmake_python_include_dir = distutils.sysconfig.get_python_inc()
494:        system_c_flags = str(distutils.sysconfig.get_config_var('CFLAGS'))
496:            os.environ['CC'] = str(distutils.sysconfig.get_config_var('CC'))
562:        distutils.command.build_ext.build_ext.build_extensions(self)
565:        outputs = distutils.command.build_ext.build_ext.get_outputs(self)
647:class clean(distutils.command.clean.clean):
671:class sdist(distutils.command.sdist.sdist):
870:    except DistutilsArgError as msg:

cc @malfet @seemethere @walterddr @pytorch/pytorch-dev-infra

Metadata

Metadata

Assignees

Labels

better-engineeringRelatively self-contained tasks for better engineering contributorsenhancementNot as big of a feature, but technically not a bug. Should be easy to fixmodule: buildBuild system issuestriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions