Test suite fails with error from Setuptools: distutils.errors.DistutilsClassError
bignose-debian opened this issue · comments
The TestCommand (implemented in setup.py) subclasses the Distutils Command class directly. This is no longer correct: it should subclass the Setuptools implementation.
The Distutils library is deprecated upstream, and all implementations should instead use their replacements from Setuptools:
As Distutils is deprecated, any usage of functions or objects from distutils is similarly discouraged, and Setuptools aims to replace or deprecate all such uses. This section describes the recommended replacements.
On current Python versions, the use of distutils.core.Command
causes the test suite to fail:
$ python3 ./setup.py test
./setup.py:5: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
from distutils.core import Command
/usr/lib/python3/dist-packages/_distutils_hack/__init__.py:18: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.
warnings.warn(
/usr/lib/python3/dist-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
Traceback (most recent call last):
File "/<<PKGBUILDDIR>>/./setup.py", line 89, in <module>
setup(
[…]
File "/usr/lib/python3/dist-packages/setuptools/_distutils/dist.py", line 540, in _parse_command_opts
raise DistutilsClassError(
distutils.errors.DistutilsClassError: command class <class '__main__.TestCommand'> must subclass Command
For this package, the necessary replacement is: Import setuptools.Command
and subclass from that.
This patch (from the Debian package) addresses this issue:
Description: Prioritise the Setuptools implementation of Command.
.
Setuptools is replacing distutils. The Setuptools implementation of
the Command class needs to be used if it is available.
Author: Ben Finney <bignose@debian.org>
Last-Update: 2022-11-01
--- old/setup.py
+++ new/setup.py
@@ -2,12 +2,11 @@
import os
import subprocess
import sys
-from distutils.core import Command
from glob import glob
try:
- from setuptools import setup, Extension
+ from setuptools import setup, Command, Extension
except ImportError:
- from distutils.core import setup
+ from distutils.core import Command, setup
from distutils.extension import Extension
pysha3 is no longer supported. Please use SHA-3 from Python's hashlib module.