Skip to content

Commit

Permalink
Ensured all methods in setuptools.modified raise a consistant `dist…
Browse files Browse the repository at this point in the history
…utils.error.DistutilsError` type
  • Loading branch information
Avasam committed Sep 18, 2024
1 parent 3106af0 commit 439ec5a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
1 change: 1 addition & 0 deletions newsfragments/4567.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensured all methods in ``setuptools.modified`` raise a consistant ``distutils.errors.DistutilsError`` type -- by :user:`Avasam`
9 changes: 1 addition & 8 deletions setuptools/command/build_clib.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
from ..dist import Distribution
from ..modified import newer_pairwise_group

import distutils.command.build_clib as orig
from distutils import log
from distutils.errors import DistutilsSetupError

try:
from distutils._modified import ( # pyright: ignore[reportMissingImports]
newer_pairwise_group,
)
except ImportError:
# fallback for SETUPTOOLS_USE_DISTUTILS=stdlib
from .._distutils._modified import newer_pairwise_group


class build_clib(orig.build_clib):
"""
Expand Down
22 changes: 16 additions & 6 deletions setuptools/modified.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
from ._distutils._modified import (
newer,
newer_group,
newer_pairwise,
newer_pairwise_group,
)
try:
# Ensure a DistutilsError raised by these methods is the same as distutils.errors.DistutilsError
from distutils._modified import (
newer,
newer_group,
newer_pairwise,
newer_pairwise_group,
)
except ImportError:
# fallback for SETUPTOOLS_USE_DISTUTILS=stdlib, because _modified never existed in stdlib
from ._distutils._modified import (
newer,
newer_group,
newer_pairwise,
newer_pairwise_group,
)

__all__ = ['newer', 'newer_pairwise', 'newer_group', 'newer_pairwise_group']
38 changes: 34 additions & 4 deletions setuptools/tests/test_distutils_adoption.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def test_distutils_has_origin():
"""


@pytest.mark.usefixtures("tmpdir_cwd")
@pytest.mark.parametrize(
"distutils_version, imported_module",
[
Expand All @@ -125,9 +126,7 @@ def test_distutils_has_origin():
("local", "archive_util"),
],
)
def test_modules_are_not_duplicated_on_import(
distutils_version, imported_module, tmpdir_cwd, venv
):
def test_modules_are_not_duplicated_on_import(distutils_version, imported_module, venv):
env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version)
script = ENSURE_IMPORTS_ARE_NOT_DUPLICATED.format(imported_module=imported_module)
cmd = ['python', '-c', script]
Expand All @@ -145,15 +144,46 @@ def test_modules_are_not_duplicated_on_import(
"""


@pytest.mark.usefixtures("tmpdir_cwd")
@pytest.mark.parametrize(
"distutils_version",
[
"local",
pytest.param("stdlib", marks=skip_without_stdlib_distutils),
],
)
def test_log_module_is_not_duplicated_on_import(distutils_version, tmpdir_cwd, venv):
def test_log_module_is_not_duplicated_on_import(distutils_version, venv):
env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version)
cmd = ['python', '-c', ENSURE_LOG_IMPORT_IS_NOT_DUPLICATED]
output = venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS).strip()
assert output == "success"


ENSURE_CONSISTENT_ERROR_FROM_MODIFIED_PY = r"""
from setuptools.modified import newer
from distutils.errors import DistutilsError
# Can't use pytest.raises in this context
try:
newer("", "")
except DistutilsError:
pass
else:
raise AssertionError("Expected to raise")
"""


@pytest.mark.usefixtures("tmpdir_cwd")
@pytest.mark.parametrize(
"distutils_version",
[
"local",
pytest.param("stdlib", marks=skip_without_stdlib_distutils),
],
)
def test_consistent_error_from_modified_py(distutils_version, venv):
env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version)
cmd = ['python', '-c', ENSURE_CONSISTENT_ERROR_FROM_MODIFIED_PY]
output = venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS).strip()
assert output == "success"

0 comments on commit 439ec5a

Please sign in to comment.