Closed jakelishman closed 11 months ago
We've marked distutils support as deprecated (see NEWS); however, we haven't done any major release since then.
We could try to import from setuptools first, and fall back to importing from distutils if that doesn't work? That way at least we don't add setuptools as a runtime dependency for existing users on python < 3.12.
Yeah, I saw the deprecation - if the preferred solution is just to wait til the next major release to support Python 3.12 then that's a fine answer to my query.
Setuptools doesn't re-expose setuptools.distutils
publicly - the setuptools
Python wheel puts in a shim to the import system via its _distutils_hack
package that causes import distutils
to pull in the private setuptools._distutils
if there's no other distutils
in the import path.
Could it be acceptable to add the dependency on setuptools; python_version>=3.12
to avoid burdening prior Python versions with the extra requirement?
AFAIK we just import Command from distutils, so I was proposing just doing:
try:
from setuptools.command import Command
except ModuleNotFoundError:
from distutils.command import Command
and then indeed adding a setuptools; python_version>=3.12
dependency.
Ah yeah, sorry I misunderstood slightly. There's also distutils.errors.DisutilsOptionError
, but that's easily redirectable to setuptools.errors.OptionError
by similar means (which in actuality is just a re-export of distutils.errors.DistutilsOptionError
).
At the moment,
import testtools
fails because of the eager import ofdistutils
viatesttools.distutilscmd
, which provides the deprecatedTestCommand
, sincedistutils
is removed from the Python 3.12 standard library.setuptools
still packagesdistutils
, so a temporary workaround could be to addsetuptools
as a runtime dependency untilTestCommand
can be removed, or potentially the import ofTestCommand
in the root could be conditional on Python version?Happy to provide a patch in either direction, if it would help.