Closed musicinmybrain closed 2 years ago
The easiest short-term workaround is to runtime-require setuptools on Python 3.12+.
I.e. add to setup.py:
setup(
...,
install_requires(['setuptools>=60;python_version>="3.12"']),
...,
)
EDIT: Added >=60
to ensure setuptools actually provide the distutils module.
It is not a hard runtime dependency IMO. The /bin/argparse-manpage
script doesn't rely on distutils at all. Distutils are only needed for the setup.py
command overrides (supported by this project). So should our users specify the setuptools as the builddep for their projects?
It seems like this project imports from distutils:
If build_manpages isn't a "core" part of this, maybe it needs to have extras dependendencies?
In that case, you would do something like this in setup.py:
https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#optional-dependencies
setup(
...,
extras_require={
"build-manpages": ['setuptools;python_version>="3.12"'],
},
)
And in build_manpages.py:
try:
from distutils.core import Command
from distutils.errors import DistutilsOptionError
except ImportError:
raise ImportError(
'To use the build_manpages tool on Python 3.12+, '
'you need to install argparse-manpage[build-manpages].'
)
And in the README, you recommend adding argparse-manpage[build-manpages]
to pyproject.toml's [build-system]
requires / tox / nox dependencies or other requirements.
I think you’ll find that even the CLI tool requires distutils
, perhaps accidentally, and that regardless of intent, distutils
currently still functions as a hard dependency in practice.
In v3
, as released on PyPI, build_manpages/cli.py
imports from build_manpages.build_manpage
…
…which imports distutils
:
In the unreleased main
, this does’t seem to be the case, but distutils
still gets imported, because importing build_manpages/cli.py
means build_manpages/__init__.py
gets imported, and that imports build_manpages/build_manpages.py
…
…and that still unconditionally imports distutils
…
…so one still sees:
PYTHON=python3.11 PYTHONPATH=$PWD PYTHONWARNINGS=d ./argparse-manpage
!! running argparse-manpage from git, this is not supported PYTHON=python3.11!!
/home/ben/src/argparse-manpage/build_manpages/build_manpages.py:8: 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
Thank you for the detailed analysis.
I plan a release soon, so let's keep v3 aside now.
In the unreleased main, this does’t seem to be the case, but distutils still gets imported, because importing build_manpages/cli.py means build_manpages/init.py gets imported, and that imports build_manpages/build_manpages.py…
Hm, importing cli.py really implies importing init.py, and thus distutils? I'd like to do something like #69, but having even the dep on setuptools in the script seems bad. Is there a way around it?
Hm, importing cli.py really implies importing init.py
Always.
You can wrap the entire thing that uses the classes in the try-except block from my comment.
In accordance with PEP 0632,
distutils
will be removed from the Python 3.12 standard library.In order to retain compatibility with Python 3.12, it may be sufficient to add a runtime dependency on
setuptools
. See the relevant Fedora Linuxpython-devel
mailing list thread; regarding potential incompatibilities, see https://github.com/pypa/setuptools/issues/3532.