Skip to content

Commit

Permalink
Remove deprecated fallback for 'distutils.commands.build.build.sub_co…
Browse files Browse the repository at this point in the history
…mmands +='
  • Loading branch information
abravalheri committed Apr 22, 2024
1 parent c32e190 commit d32b394
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 53 deletions.
18 changes: 0 additions & 18 deletions setuptools/command/build.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
from typing import Dict, List, Protocol
from distutils.command.build import build as _build

from ..warnings import SetuptoolsDeprecationWarning

_ORIGINAL_SUBCOMMANDS = {"build_py", "build_clib", "build_ext", "build_scripts"}


class build(_build):
# copy to avoid sharing the object with parent class
sub_commands = _build.sub_commands[:]

def get_sub_commands(self):
subcommands = {cmd[0] for cmd in _build.sub_commands}
if subcommands - _ORIGINAL_SUBCOMMANDS:
SetuptoolsDeprecationWarning.emit(
"Direct usage of `distutils` commands",
"""
It seems that you are using `distutils.command.build` to add
new subcommands. Using `distutils` directly is considered deprecated,
please use `setuptools.command.build`.
""",
due_date=(2023, 12, 13), # Warning introduced in 13 Jun 2022.
see_url="https://peps.python.org/pep-0632/",
)
self.sub_commands = _build.sub_commands
return super().get_sub_commands()


class SubCommand(Protocol):
"""In order to support editable installations (see :pep:`660`) all
Expand Down
36 changes: 1 addition & 35 deletions setuptools/tests/test_build.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from contextlib import contextmanager
from setuptools import Command, SetuptoolsDeprecationWarning
from setuptools import Command
from setuptools.dist import Distribution
from setuptools.command.build import build
from distutils.command.build import build as distutils_build

import pytest


def test_distribution_gives_setuptools_build_obj(tmpdir_cwd):
Expand All @@ -24,15 +20,6 @@ def test_distribution_gives_setuptools_build_obj(tmpdir_cwd):
assert isinstance(dist.get_command_obj("build"), build)


@contextmanager
def _restore_sub_commands():
orig = distutils_build.sub_commands[:]
try:
yield
finally:
distutils_build.sub_commands = orig


class Subcommand(Command):
"""Dummy command to be used in tests"""

Expand All @@ -44,24 +31,3 @@ def finalize_options(self):

def run(self):
raise NotImplementedError("just to check if the command runs")


@_restore_sub_commands()
def test_subcommand_in_distutils(tmpdir_cwd):
"""
Ensure that sub commands registered in ``distutils`` run,
after instructing the users to migrate to ``setuptools``.
"""
dist = Distribution(
dict(
packages=[],
cmdclass={'subcommand': Subcommand},
)
)
distutils_build.sub_commands.append(('subcommand', None))

warning_msg = "please use .setuptools.command.build."
with pytest.warns(SetuptoolsDeprecationWarning, match=warning_msg):
# For backward compatibility, the subcommand should run anyway:
with pytest.raises(NotImplementedError, match="the command runs"):
dist.run_command("build")

0 comments on commit d32b394

Please sign in to comment.