Skip to content

Commit

Permalink
deprecate scripts depending on extras (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering authored Jan 27, 2024
1 parent e2a3b85 commit 14a5250
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,20 @@ def validate(
continue

extras = script.get("extras", [])
if extras:
result["warnings"].append(
f'The script "{name}" depends on an extra. Scripts'
" depending on extras are deprecated and support for them"
" will be removed in a future version of"
" poetry/poetry-core. See"
" https://packaging.python.org/en/latest/specifications/entry-points/#data-model"
" for details."
)
for extra in extras:
if extra not in config_extras:
result["errors"].append(
f'Script "{name}" requires extra "{extra}" which is not'
" defined."
f'The script "{name}" requires extra "{extra}"'
" which is not defined."
)

# Checking types of all readme files (must match)
Expand Down
12 changes: 11 additions & 1 deletion src/poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def convert_entry_points(self) -> dict[str, list[str]]:
f"Use of callable in script specification ({name}) is"
" deprecated. Use reference instead.",
DeprecationWarning,
stacklevel=2,
stacklevel=1,
)
specification = {
"reference": specification["callable"],
Expand All @@ -322,6 +322,16 @@ def convert_entry_points(self) -> dict[str, list[str]]:
continue

extras = specification.get("extras", [])
if extras:
warnings.warn(
f'The script "{name}" depends on an extra. Scripts depending on'
" extras are deprecated and support for them will be removed in a"
" future version of poetry/poetry-core. See"
" https://packaging.python.org/en/latest/specifications/entry-points/#data-model"
" for details.",
DeprecationWarning,
stacklevel=1,
)
extras = f"[{', '.join(extras)}]" if extras else ""
reference = specification.get("reference")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ time = ["pendulum"]
[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
extra-script = {reference = "my_package.extra:main", extras = ["time"], type = "console"}

[tool.poetry.urls]
"Issue Tracker" = "https://github.com/python-poetry/poetry/issues"
3 changes: 2 additions & 1 deletion tests/masonry/builders/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ def test_entrypoint_scripts_legacy_warns(fixture: str) -> None:
),
],
)
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
@pytest.mark.filterwarnings("ignore:.* callable .* deprecated:DeprecationWarning")
@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
def test_builder_convert_entry_points(
fixture: str, result: dict[str, list[str]]
) -> None:
Expand Down
3 changes: 2 additions & 1 deletion tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def test_complete(no_vcs: bool) -> None:
module_path = temporary_dir

builder = Builder(Factory().create_poetry(module_path))
builder.build(fmt="all")
with pytest.warns(DeprecationWarning, match=".* script .* extra"):
builder.build(fmt="all")

whl = module_path / "dist" / "my_package-1.2.3-py3-none-any.whl"

Expand Down
2 changes: 2 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def test_convert_dependencies() -> None:
assert result == (main, extras)


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
def test_make_setup() -> None:
poetry = Factory().create_poetry(project("complete"))

Expand Down Expand Up @@ -298,6 +299,7 @@ def test_sdist_reproducibility() -> None:
assert len(hashes) == 1


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
def test_setup_py_context() -> None:
poetry = Factory().create_poetry(project("complete"))

Expand Down
2 changes: 2 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_wheel_module() -> None:
assert "module1.py" in z.namelist()


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
def test_wheel_package() -> None:
module_path = fixtures_dir / "complete"
WheelBuilder.make(Factory().create_poetry(module_path))
Expand Down Expand Up @@ -208,6 +209,7 @@ def test_wheel_build_script_creates_package() -> None:
shutil.rmtree(module_path / "my_package")


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
def test_dist_info_file_permissions() -> None:
module_path = fixtures_dir / "complete"
WheelBuilder.make(Factory().create_poetry(module_path))
Expand Down
7 changes: 7 additions & 0 deletions tests/masonry/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from typing import TYPE_CHECKING
from typing import Iterator

import pytest

from poetry.core import __version__
from poetry.core.masonry import api
from poetry.core.utils.helpers import temporary_directory
Expand Down Expand Up @@ -44,6 +46,7 @@ def test_get_requires_for_build_sdist() -> None:
assert api.get_requires_for_build_sdist() == expected


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
def test_build_wheel() -> None:
with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "complete")):
filename = api.build_wheel(tmp_dir)
Expand Down Expand Up @@ -132,6 +135,7 @@ def test_build_sdist_with_bad_path_dep_succeeds(caplog: LogCaptureFixture) -> No
assert "does not exist" in record.message


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
def test_prepare_metadata_for_build_wheel() -> None:
entry_points = """\
[console_scripts]
Expand Down Expand Up @@ -224,6 +228,7 @@ def test_prepare_metadata_for_build_wheel_with_bad_path_dep_succeeds(
assert "does not exist" in record.message


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
def test_build_editable_wheel() -> None:
pkg_dir = Path(fixtures) / "complete"

Expand All @@ -244,6 +249,7 @@ def test_build_editable_wheel() -> None:
assert pkg_dir.as_posix() == z.read("my_package.pth").decode().strip()


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
def test_build_wheel_with_metadata_directory() -> None:
pkg_dir = Path(fixtures) / "complete"

Expand Down Expand Up @@ -271,6 +277,7 @@ def test_build_wheel_with_metadata_directory() -> None:
assert f"{metadata_directory}/CUSTOM" in namelist


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
def test_build_editable_wheel_with_metadata_directory() -> None:
pkg_dir = Path(fixtures) / "complete"

Expand Down
2 changes: 2 additions & 0 deletions tests/masonry/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_builder_raises_error_in_non_package_mode(tmp_path: Path, format: str) -
assert str(err.value) == "Building a package is not possible in non-package mode."


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
@pytest.mark.parametrize("format", ["sdist", "wheel", "all"])
def test_builder_creates_places_built_files_in_specified_directory(
tmp_path: Path, format: str
Expand All @@ -72,6 +73,7 @@ def test_builder_creates_places_built_files_in_specified_directory(
assert all(archive.exists() for archive in build_artifacts)


@pytest.mark.filterwarnings("ignore:.* script .* extra:DeprecationWarning")
@pytest.mark.parametrize("format", ["sdist", "wheel", "all"])
def test_builder_creates_packages_in_dist_directory_if_no_output_is_specified(
format: str,
Expand Down
11 changes: 9 additions & 2 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ def test_validate_strict_fails_strict_and_non_strict() -> None:
'"some-extras" in main dependencies.'
),
(
'Script "a_script_with_unknown_extra" requires extra "foo" which is not'
" defined."
'The script "a_script_with_unknown_extra" requires extra "foo" which is'
" not defined."
),
(
"Declared README files must be of same type: found text/markdown,"
Expand All @@ -325,6 +325,13 @@ def test_validate_strict_fails_strict_and_non_strict() -> None:
'The "pathlib2" dependency specifies the "allows-prereleases" property,'
' which is deprecated. Use "allow-prereleases" instead.'
),
(
'The script "a_script_with_unknown_extra" depends on an extra. Scripts'
" depending on extras are deprecated and support for them will be"
" removed in a future version of poetry/poetry-core. See"
" https://packaging.python.org/en/latest/specifications/entry-points/#data-model"
" for details."
),
],
}

Expand Down

0 comments on commit 14a5250

Please sign in to comment.