Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distutils is to be removed from the standard library in Python 3.12 #63

Closed
musicinmybrain opened this issue Oct 20, 2022 · 8 comments · Fixed by #69
Closed

Distutils is to be removed from the standard library in Python 3.12 #63

musicinmybrain opened this issue Oct 20, 2022 · 8 comments · Fixed by #69

Comments

@musicinmybrain
Copy link

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 Linux python-devel mailing list thread; regarding potential incompatibilities, see pypa/setuptools#3532.

@hroncok
Copy link

hroncok commented Oct 21, 2022

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.

@praiskup
Copy link
Owner

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?

@hroncok
Copy link

hroncok commented Oct 26, 2022

It seems like this project imports from distutils:

from distutils.core import Command
from distutils.errors import DistutilsOptionError

If build_manpages isn't a "core" part of this, maybe it needs to have extras dependendencies?

@hroncok
Copy link

hroncok commented Oct 26, 2022

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.

@musicinmybrain
Copy link
Author

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

from build_manpages.build_manpage import ManPageWriter, get_parser, MANPAGE_DATA_ATTRS

…which imports distutils:

from distutils.core import Command
from distutils.errors import DistutilsOptionError


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

from .build_manpages import build_manpages, get_build_py_cmd, get_install_cmd

…and that still unconditionally imports distutils

from distutils.core import Command
from distutils.errors import DistutilsOptionError

…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

@praiskup
Copy link
Owner

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?

@hroncok
Copy link

hroncok commented Oct 26, 2022

Hm, importing cli.py really implies importing init.py

Always.

@hroncok
Copy link

hroncok commented Oct 26, 2022

You can wrap the entire thing that uses the classes in the try-except block from my comment.

praiskup added a commit that referenced this issue Oct 27, 2022
Let's separate the Manpage generating logic (the new 'argparse_manpage'
module) from the part which helps the user to override the setuptools
commands (continues to be named 'build_manpages').

Fixes: #63
praiskup added a commit that referenced this issue Oct 27, 2022
praiskup added a commit that referenced this issue Oct 27, 2022
Let's separate the Manpage generating logic (the new 'argparse_manpage'
module) from the part which helps the user to override the setuptools
commands (continues to be named 'build_manpages').

Fixes: #63
praiskup added a commit that referenced this issue Oct 27, 2022
praiskup added a commit that referenced this issue Oct 30, 2022
praiskup added a commit that referenced this issue Oct 31, 2022
musicinmybrain added a commit to musicinmybrain/pipx that referenced this issue Mar 3, 2023
To use the build_manpages tool on Python 3.12+, argparse-manpage needs
setuptools; depend on argparse-manpage[setuptools] to ensure this keeps
working.

See: praiskup/argparse-manpage#63
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants