|
| 1 | +PEP: 632 |
| 2 | +Title: Deprecate distutils module |
| 3 | +Author: Steve Dower <steve.dower@python.org> |
| 4 | +Status: Draft |
| 5 | +Type: Standards Track |
| 6 | +Content-Type: text/x-rst |
| 7 | +Created: 03-Sep-2020 |
| 8 | +Post-History: |
| 9 | + |
| 10 | + |
| 11 | +Abstract |
| 12 | +======== |
| 13 | + |
| 14 | +The distutils module [1]_ has for a long time recommended using the |
| 15 | +setuptools package [2]_ instead. Setuptools has recently integrated a |
| 16 | +complete copy of distutils and is no longer dependent on the standard |
| 17 | +library [3]_. Pip has silently replaced distutils with setuptools when |
| 18 | +building packages for a long time already. It is time to remove it |
| 19 | +from the (public part of the) standard library. |
| 20 | + |
| 21 | + |
| 22 | +Motivation |
| 23 | +========== |
| 24 | + |
| 25 | +distutils [1]_ is a largely undocumented and unmaintained collection |
| 26 | +of utilities for packaging and distributing Python packages, including |
| 27 | +compilation of native extension modules. It defines a configuration |
| 28 | +format that describes a Python distribution and provides the tools to |
| 29 | +convert a directory of source code into a source distribution, and |
| 30 | +some forms of binary distribution. Because of its place in the |
| 31 | +standard library, many updates can only be released with a major |
| 32 | +release, and users cannot rely on particular fixes being available. |
| 33 | + |
| 34 | +setuptools [2]_ is a better documented and well maintained enhancement |
| 35 | +based on distutils. While it provides very similar functionality, it |
| 36 | +is much better able to support users on earlier Python releases, and |
| 37 | +can respond to bug reports more quickly. A number of platform-specific |
| 38 | +enhancements already exist in setuptools that have not been added to |
| 39 | +distutils, and there is been a long-standing recommendation in the |
| 40 | +distutils documentation to prefer setuptools. |
| 41 | + |
| 42 | +Historically, setuptools has extended distutils using subclassing and |
| 43 | +monkeypatching, but has now taken a copy of the underlying code. [3]_ |
| 44 | +As a result, the second last major dependency on distutils is gone and |
| 45 | +there is no need to keep it in the standard library. |
| 46 | + |
| 47 | +The final dependency on distutils is CPython itself, which uses it to |
| 48 | +build the native extension modules in the standard library (except on |
| 49 | +Windows). Because this is a CPython build-time dependency, it is |
| 50 | +possible to continue to use distutils for this specific case without |
| 51 | +it being part of the standard library. |
| 52 | + |
| 53 | +Deprecation and removal will make it obvious that issues should be |
| 54 | +fixed in the setuptools project, and will reduce a source of bug |
| 55 | +reports and test maintenance that is unnecessary. It will also help |
| 56 | +promote the development of alternative build backends, which can now |
| 57 | +be supported more easily thanks to PEP 517. |
| 58 | + |
| 59 | + |
| 60 | +Specification |
| 61 | +============= |
| 62 | + |
| 63 | +In Python 3.10 and 3.11, distutils will be formally marked as |
| 64 | +deprecated. All known issues will be closed at this time. |
| 65 | +``import distutils`` will raise a deprecation warning. |
| 66 | + |
| 67 | +During Python 3.10 and 3.11, uses of distutils within the standard |
| 68 | +library may change to use alternative APIs. |
| 69 | + |
| 70 | +In Python 3.12, distutils will no longer be installed by ``make |
| 71 | +install`` or any of the first-party distribution. Third-party |
| 72 | +redistributors should no longer include distutils in their bundles or |
| 73 | +repositories. |
| 74 | + |
| 75 | +This PEP makes no specification on migrating the parts of the CPython |
| 76 | +build process that currently use distutils. Depending on |
| 77 | +contributions, this migration may occur at any time. |
| 78 | + |
| 79 | +After Python 3.12 is started and when the CPython build process no |
| 80 | +longer depends on distutils being in the standard library, the entire |
| 81 | +``Lib/distutils`` directory and ``Lib/test/test_distutils.py`` file |
| 82 | +will be removed from the repository. |
| 83 | + |
| 84 | +Other references to distutils will be cleaned up. As of Python 3.9's |
| 85 | +initial release, the following modules have references in code or |
| 86 | +comments: |
| 87 | + |
| 88 | +* Lib/ctypes/util.py |
| 89 | +* Lib/site.py |
| 90 | +* Lib/sysconfig.py |
| 91 | +* Lib/_aix_support.py |
| 92 | +* Lib/_bootsubprocess.py |
| 93 | +* Lib/_osx_support.py |
| 94 | +* Modules/_decimal/tests/formathelper.py |
| 95 | + |
| 96 | +As the distutils code is already included in setuptools, there is no |
| 97 | +need to republish it in any other form. Those who require access to |
| 98 | +the functionality should use setuptools or an alternative build |
| 99 | +backend. |
| 100 | + |
| 101 | +Backwards Compatibility |
| 102 | +======================= |
| 103 | + |
| 104 | +Code that imports distutils will no longer work from Python 3.12. |
| 105 | + |
| 106 | +The suggested migration path is to use the equivalent (though not |
| 107 | +identical) imports from setuptools. |
| 108 | + |
| 109 | +Compatibility shims already exist in setuptools and pip to |
| 110 | +transparently migrate old code, however, these are controlled by |
| 111 | +external projects and are in no way bound by this PEP. Consult their |
| 112 | +latest documentation for migration advice. |
| 113 | + |
| 114 | +Some projects use alternate sets of shims over distutils, notably, |
| 115 | +numpy.distutils. [4]_ Where known, these projects have been informed. |
| 116 | + |
| 117 | +Many use custom commands or more narrowly scoped patches, mostly |
| 118 | +constrained to ``setup.py`` files. As these packages are already |
| 119 | +subject to setuptools being injected by pip, we expect minimal |
| 120 | +disruption as a result of distutils being removed. |
| 121 | + |
| 122 | + |
| 123 | +Reference Implementation |
| 124 | +======================== |
| 125 | + |
| 126 | +setuptools version 48 includes the complete copy of distutils, and as |
| 127 | +such is no longer dependent on the standard library's copy. Most |
| 128 | +implementation issues they have faced are due to the continuing |
| 129 | +existence of distutils in the standard library, and so removal will |
| 130 | +improve the stability of their implementation. |
| 131 | + |
| 132 | +There is not yet a reference implementation for the removal of |
| 133 | +distutils from the standard library, nor is there an implementation |
| 134 | +for CPython's native module builds without relying on the standard |
| 135 | +library copy of distutils. |
| 136 | + |
| 137 | + |
| 138 | +References |
| 139 | +========== |
| 140 | + |
| 141 | +.. [1] distutils - Building and installing Python modules |
| 142 | + (https://docs.python.org/3.9/library/distutils.html) |
| 143 | +
|
| 144 | +.. [2] setuptools - PyPI |
| 145 | + (https://pypi.org/project/setuptools/) |
| 146 | +
|
| 147 | +.. [3] setuptools Issue #417 - Adopt distutils |
| 148 | + (https://github.com/pypa/setuptools/issues/417) |
| 149 | +
|
| 150 | +.. [4] Packaging (numpy.distutils) |
| 151 | + (https://numpy.org/doc/stable/reference/distutils.html) |
| 152 | +
|
| 153 | +
|
| 154 | +Copyright |
| 155 | +========= |
| 156 | + |
| 157 | +This document is placed in the public domain or under the |
| 158 | +CC0-1.0-Universal license, whichever is more permissive. |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | +.. |
| 163 | + Local Variables: |
| 164 | + mode: indented-text |
| 165 | + indent-tabs-mode: nil |
| 166 | + sentence-end-double-space: t |
| 167 | + fill-column: 70 |
| 168 | + coding: utf-8 |
| 169 | + End: |
0 commit comments