Skip to content

Recent changes in disutils/command/__init__.py change the outcome of setuptools.monkey.patch_all #351

@abravalheri

Description

@abravalheri

I am not sure if this new behaviour is welcome, but I am reporting it as an outcome of the investigation in pypa/setuptools#4902.


In pypa/setuptools#4902 I hypothesized that eagerly importing the command modules in command/__init__.py affected the end result of setuptools.monkey.patch_all:

  • Previous to this PR the command modules were imported late, so by the time they were executed distutils.core.Command was already monkeypatched to setuptools.Command.
  • Now, the modules are executed before the patch.

The following experiment seems to corroborate this conclusion:

> docker run --rm -it python:3.10-bookworm /bin/bash
python -m pip install 'setuptools==77.0.1'
python
>>> import setuptools
>>> from distutils.command.sdist import sdist
>>> sdist.__mro__
(<class 'distutils.command.sdist.sdist'>, <class 'setuptools.Command'>, <class 'distutils.cmd.Command'>, <class 'object'>)


python -m pip install 'setuptools @ https://github.com/pypa/setuptools/archive/refs/tags/v77.0.2.zip'
# tag not published to PyPI.
python
>>> import setuptools
>>> from distutils.command.sdist import sdist
>>> sdist.__mro__
(<class 'distutils.command.sdist.sdist'>, <class 'distutils.cmd.Command'>, <class 'object'>)

I don't know if there are the deeper unforeseen consequences of this change (other than problems similar to pypa/setuptools#4902).

Originally posted by @abravalheri in #345 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions