Skip to content

Commit

Permalink
Remove deprecated code after warnings have been issued for a long per…
Browse files Browse the repository at this point in the history
…iod (#4322)
  • Loading branch information
abravalheri authored May 7, 2024
2 parents 6dc694e + a32e2aa commit 34328fa
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 77 deletions.
3 changes: 3 additions & 0 deletions newsfragments/4322.removal.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remove ``setuptools.convert_path`` after long deprecation period.
This function was never defined by ``setuptools`` itself, but rather a
side-effect of an import for internal usage.
3 changes: 3 additions & 0 deletions newsfragments/4322.removal.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remove fallback for customisations of ``distutils``' ``build.sub_command`` after long
deprecated period.
Users are advised to import ``build`` directly from ``setuptools.command.build``.
17 changes: 0 additions & 17 deletions setuptools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import _distutils_hack.override # noqa: F401
import distutils.core
from distutils.errors import DistutilsOptionError
from distutils.util import convert_path as _convert_path

from . import logging, monkey
from . import version as _version_module
Expand Down Expand Up @@ -247,22 +246,6 @@ def findall(dir=os.curdir):
return list(files)


@functools.wraps(_convert_path)
def convert_path(pathname):
SetuptoolsDeprecationWarning.emit(
"Access to implementation detail",
"""
The function `convert_path` is not provided by setuptools itself,
and therefore not part of the public API.
Its direct usage by 3rd-party packages is considered improper and the function
may be removed in the future.
""",
due_date=(2023, 12, 13), # initial deprecation 2022-03-25, see #3201
)
return _convert_path(pathname)


class sic(str):
"""Treat this string as-is (https://en.wikipedia.org/wiki/Sic)"""

Expand Down
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")
5 changes: 0 additions & 5 deletions setuptools/tests/test_setuptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,3 @@ def test_its_own_wheel_does_not_contain_tests(setuptools_wheel):

for member in contents:
assert '/tests/' not in member


def test_convert_path_deprecated():
with pytest.warns(setuptools.SetuptoolsDeprecationWarning):
setuptools.convert_path('setuptools/tests')
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ deps =
# Ideally all the dependencies should be set as "extras"
setenv =
PYTHONWARNDEFAULTENCODING = 1
SETUPTOOLS_ENFORCE_DEPRECATION = {env:SETUPTOOLS_ENFORCE_DEPRECATION:0}
# ^-- Temporarily disable enforcement so CI don't fail on due dates
SETUPTOOLS_ENFORCE_DEPRECATION = {env:SETUPTOOLS_ENFORCE_DEPRECATION:1}
commands =
pytest {posargs}
usedevelop = True
Expand Down

0 comments on commit 34328fa

Please sign in to comment.