From 547c9e2bb0c7af87ba961f9282ae35f0ff2cc867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Fri, 4 Oct 2024 11:47:56 +0200 Subject: [PATCH] remove code that has been deprecated for a while --- src/poetry/core/masonry/builder.py | 49 ------------ src/poetry/core/packages/dependency.py | 37 --------- src/poetry/core/packages/package.py | 30 ------- src/poetry/core/packages/project_package.py | 11 --- src/poetry/core/packages/utils/link.py | 51 ------------ tests/masonry/test_builder.py | 88 --------------------- tests/packages/test_dependency.py | 21 +---- tests/packages/utils/test_utils_link.py | 24 ------ 8 files changed, 2 insertions(+), 309 deletions(-) delete mode 100644 src/poetry/core/masonry/builder.py delete mode 100644 tests/masonry/test_builder.py diff --git a/src/poetry/core/masonry/builder.py b/src/poetry/core/masonry/builder.py deleted file mode 100644 index ed9e78f6e..000000000 --- a/src/poetry/core/masonry/builder.py +++ /dev/null @@ -1,49 +0,0 @@ -from __future__ import annotations - -import warnings - -from typing import TYPE_CHECKING - - -if TYPE_CHECKING: - from pathlib import Path - - from poetry.core.poetry import Poetry - - -warnings.warn( - "poetry.core.masonry.builder is deprecated. Its functionality has been moved" - "from poetry-core to poetry (poetry.console.commands.build).", - DeprecationWarning, - stacklevel=2, -) - - -class Builder: - def __init__(self, poetry: Poetry) -> None: - from poetry.core.masonry.builders.sdist import SdistBuilder - from poetry.core.masonry.builders.wheel import WheelBuilder - - self._poetry = poetry - - self._formats = { - "sdist": SdistBuilder, - "wheel": WheelBuilder, - } - - def build( - self, - fmt: str, - executable: str | Path | None = None, - *, - target_dir: Path | None = None, - ) -> None: - if fmt in self._formats: - builders = [self._formats[fmt]] - elif fmt == "all": - builders = list(self._formats.values()) - else: - raise ValueError(f"Invalid format: {fmt}") - - for builder in builders: - builder(self._poetry, executable=executable).build(target_dir) diff --git a/src/poetry/core/packages/dependency.py b/src/poetry/core/packages/dependency.py index 9c40a7ae0..bbf8d5290 100644 --- a/src/poetry/core/packages/dependency.py +++ b/src/poetry/core/packages/dependency.py @@ -2,7 +2,6 @@ import os import re -import warnings from contextlib import suppress from pathlib import Path @@ -81,8 +80,6 @@ def __init__( self._python_versions = "*" self._python_constraint = parse_constraint("*") - self._transitive_python_versions: str | None = None - self._transitive_python_constraint: VersionConstraint | None = None self._transitive_marker: BaseMarker | None = None self._in_extras: Sequence[NormalizedName] = [] @@ -137,28 +134,6 @@ def python_versions(self, value: str) -> None: ) ) - @property - def transitive_python_versions(self) -> str: - warnings.warn( - "'transitive_python_versions' is deprecated and will be removed.", - DeprecationWarning, - stacklevel=2, - ) - if self._transitive_python_versions is None: - return self._python_versions - - return self._transitive_python_versions - - @transitive_python_versions.setter - def transitive_python_versions(self, value: str) -> None: - warnings.warn( - "'transitive_python_versions' is deprecated and will be removed.", - DeprecationWarning, - stacklevel=2, - ) - self._transitive_python_versions = value - self._transitive_python_constraint = parse_constraint(value) - @property def marker(self) -> BaseMarker: return self._marker @@ -216,18 +191,6 @@ def transitive_marker(self, value: BaseMarker) -> None: def python_constraint(self) -> VersionConstraint: return self._python_constraint - @property - def transitive_python_constraint(self) -> VersionConstraint: - warnings.warn( - "'transitive_python_constraint' is deprecated and will be removed.", - DeprecationWarning, - stacklevel=2, - ) - if self._transitive_python_constraint is None: - return self._python_constraint - - return self._transitive_python_constraint - @property def extras(self) -> frozenset[NormalizedName]: # extras activated in a dependency is the same as features diff --git a/src/poetry/core/packages/package.py b/src/poetry/core/packages/package.py index a795bc01e..312a9d09f 100644 --- a/src/poetry/core/packages/package.py +++ b/src/poetry/core/packages/package.py @@ -1,7 +1,6 @@ from __future__ import annotations import re -import warnings from typing import TYPE_CHECKING from typing import ClassVar @@ -60,7 +59,6 @@ def __init__( self, name: str, version: str | Version, - pretty_version: str | None = None, source_type: str | None = None, source_url: str | None = None, source_reference: str | None = None, @@ -75,14 +73,6 @@ def __init__( """ from poetry.core.version.markers import AnyMarker - if pretty_version is not None: - warnings.warn( - "The `pretty_version` parameter is deprecated and will be removed" - " in a future release.", - DeprecationWarning, - stacklevel=2, - ) - super().__init__( name, source_type=source_type, @@ -116,8 +106,6 @@ def __init__( self._dependency_groups: Mapping[str, DependencyGroup] = {} - # Category is heading towards deprecation. - self._category = "main" self.files: Sequence[Mapping[str, str]] = [] self.optional = False @@ -376,24 +364,6 @@ def urls(self) -> dict[str, str]: return urls - @property - def category(self) -> str: - warnings.warn( - "`category` is deprecated and will be removed in a future release.", - DeprecationWarning, - stacklevel=2, - ) - return self._category - - @category.setter - def category(self, category: str) -> None: - warnings.warn( - "Setting `category` is deprecated and will be removed in a future release.", - DeprecationWarning, - stacklevel=2, - ) - self._category = category - @property def yanked(self) -> bool: return isinstance(self._yanked, str) or bool(self._yanked) diff --git a/src/poetry/core/packages/project_package.py b/src/poetry/core/packages/project_package.py index ff3465ff4..4b5cf107e 100644 --- a/src/poetry/core/packages/project_package.py +++ b/src/poetry/core/packages/project_package.py @@ -1,7 +1,5 @@ from __future__ import annotations -import warnings - from typing import TYPE_CHECKING from typing import Any from typing import Mapping @@ -24,16 +22,7 @@ def __init__( self, name: str, version: str | Version, - pretty_version: str | None = None, ) -> None: - if pretty_version is not None: - warnings.warn( - "The `pretty_version` parameter is deprecated and will be removed" - " in a future release.", - DeprecationWarning, - stacklevel=2, - ) - super().__init__(name, version) # Attributes must be immutable for clone() to be safe! diff --git a/src/poetry/core/packages/utils/link.py b/src/poetry/core/packages/utils/link.py index 00b39b6a2..5458bfc23 100644 --- a/src/poetry/core/packages/utils/link.py +++ b/src/poetry/core/packages/utils/link.py @@ -3,7 +3,6 @@ import posixpath import re import urllib.parse as urlparse -import warnings from functools import cached_property from typing import TYPE_CHECKING @@ -187,32 +186,6 @@ def metadata_hashes(self) -> Mapping[str, str]: return {match.group(1): match.group(2)} return {} - @property - def metadata_hash(self) -> str | None: - warnings.warn( - "metadata_hash is deprecated. Use metadata_hashes instead.", - DeprecationWarning, - stacklevel=2, - ) - if self.has_metadata and isinstance(self._metadata, str): - match = self._hash_re.search(self._metadata) - if match: - return match.group(2) - return None - - @property - def metadata_hash_name(self) -> str | None: - warnings.warn( - "metadata_hash_name is deprecated. Use metadata_hashes instead.", - DeprecationWarning, - stacklevel=2, - ) - if self.has_metadata and isinstance(self._metadata, str): - match = self._hash_re.search(self._metadata) - if match: - return match.group(1) - return None - @cached_property def hashes(self) -> Mapping[str, str]: if self._hashes: @@ -222,30 +195,6 @@ def hashes(self) -> Mapping[str, str]: return {match.group(1): match.group(2)} return {} - @property - def hash(self) -> str | None: - warnings.warn( - "hash is deprecated. Use hashes instead.", - DeprecationWarning, - stacklevel=2, - ) - match = self._hash_re.search(self.url) - if match: - return match.group(2) - return None - - @property - def hash_name(self) -> str | None: - warnings.warn( - "hash_name is deprecated. Use hashes instead.", - DeprecationWarning, - stacklevel=2, - ) - match = self._hash_re.search(self.url) - if match: - return match.group(1) - return None - @cached_property def show_url(self) -> str: return posixpath.basename(self.url.split("#", 1)[0].split("?", 1)[0]) diff --git a/tests/masonry/test_builder.py b/tests/masonry/test_builder.py deleted file mode 100644 index 42cd5f495..000000000 --- a/tests/masonry/test_builder.py +++ /dev/null @@ -1,88 +0,0 @@ -from __future__ import annotations - -import shutil -import warnings - -from contextlib import contextmanager -from pathlib import Path -from typing import TYPE_CHECKING -from typing import Iterator - -import pytest - -from poetry.core.factory import Factory - - -with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - from poetry.core.masonry.builder import Builder - - -if TYPE_CHECKING: - from poetry.core.poetry import Poetry - - -def get_project(name: str) -> Path: - project_directory = Path(__file__).parent / "builders" / "fixtures" / name - assert project_directory.is_dir() - return project_directory - - -@contextmanager -def get_project_context(name: str) -> Iterator[Path]: - project_directory = get_project(name) - try: - yield project_directory - finally: - shutil.rmtree(project_directory / "dist") - - -def get_poetry(name: str) -> Poetry: - return Factory().create_poetry(get_project(name)) - - -def get_package_glob(poetry: Poetry) -> str: - return f"{poetry.package.name.replace('-', '_')}-{poetry.package.version}*" - - -def test_builder_factory_raises_error_when_format_is_not_valid() -> None: - with pytest.raises(ValueError, match=r"Invalid format.*"): - Builder(get_poetry("complete")).build("not_valid") - - -@pytest.mark.parametrize("format", ["sdist", "wheel", "all"]) -def test_builder_raises_error_in_non_package_mode(tmp_path: Path, format: str) -> None: - poetry = Factory().create_poetry( - Path(__file__).parent.parent / "fixtures" / "non_package_mode" - ) - with pytest.raises(RuntimeError) as err: - Builder(poetry).build(format, target_dir=tmp_path) - - 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 -) -> None: - poetry = get_poetry("complete") - Builder(poetry).build(format, target_dir=tmp_path) - build_artifacts = tuple(tmp_path.glob(get_package_glob(poetry))) - assert len(build_artifacts) > 0 - 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, -) -> None: - with get_project_context("complete") as project: - poetry = Factory().create_poetry(project) - Builder(poetry).build(format, target_dir=None) - package_directory = project / "dist" - build_artifacts = tuple(package_directory.glob(get_package_glob(poetry))) - assert package_directory.is_dir() - assert len(build_artifacts) > 0 - assert all(archive.exists() for archive in build_artifacts) diff --git a/tests/packages/test_dependency.py b/tests/packages/test_dependency.py index 8b10a8df9..de35e280a 100644 --- a/tests/packages/test_dependency.py +++ b/tests/packages/test_dependency.py @@ -1,9 +1,5 @@ from __future__ import annotations -from contextlib import AbstractContextManager -from contextlib import nullcontext -from typing import Any - import pytest from packaging.utils import canonicalize_name @@ -304,8 +300,6 @@ def test_with_constraint() -> None: 'python_version >= "3.7" and python_version < "4.0"' ) dependency.python_versions = "^3.6" - with pytest.warns(DeprecationWarning): - dependency.transitive_python_versions = "^3.7" new = dependency.with_constraint("^1.2.6") @@ -318,10 +312,6 @@ def test_with_constraint() -> None: assert new.marker == dependency.marker assert new.transitive_marker == dependency.transitive_marker assert new.python_constraint == dependency.python_constraint - with pytest.warns(DeprecationWarning): - assert ( - new.transitive_python_constraint == dependency.transitive_python_constraint - ) @pytest.mark.parametrize( @@ -399,7 +389,6 @@ def test_eq(dependency1: Dependency, dependency2: Dependency, expected: bool) -> [ ("constraint", "2.0"), ("python_versions", "<3.8"), - ("transitive_python_versions", "<3.8"), ("marker", "sys_platform == 'linux'"), ("transitive_marker", "sys_platform == 'linux'"), ], @@ -407,15 +396,9 @@ def test_eq(dependency1: Dependency, dependency2: Dependency, expected: bool) -> def test_mutable_attributes_not_in_hash(attr_name: str, value: str) -> None: dependency = Dependency("foo", "^1.2.3") ref_hash = hash(dependency) + ref_value = getattr(dependency, attr_name) - if attr_name == "transitive_python_versions": - context: AbstractContextManager[Any] = pytest.warns(DeprecationWarning) - else: - context = nullcontext() + setattr(dependency, attr_name, value) - with context: - ref_value = getattr(dependency, attr_name) - with context: - setattr(dependency, attr_name, value) assert value != ref_value assert hash(dependency) == ref_hash diff --git a/tests/packages/utils/test_utils_link.py b/tests/packages/utils/test_utils_link.py index 8abe9c0b9..5dd51637f 100644 --- a/tests/packages/utils/test_utils_link.py +++ b/tests/packages/utils/test_utils_link.py @@ -43,29 +43,17 @@ def make_url( def test_package_link_hash(file_checksum: str) -> None: link = make_url(ext="whl", file_checksum=file_checksum) assert link.hashes == {"sha256": file_checksum} - with pytest.warns(DeprecationWarning): - assert link.hash_name == "sha256" - with pytest.warns(DeprecationWarning): - assert link.hash == file_checksum assert link.show_url == "demo-1.0.0.whl" # this is legacy PEP 503, no metadata hash is present assert not link.has_metadata assert not link.metadata_url assert not link.metadata_hashes - with pytest.warns(DeprecationWarning): - assert not link.metadata_hash - with pytest.warns(DeprecationWarning): - assert not link.metadata_hash_name def test_package_link_hashes(file_checksum: str) -> None: link = make_url(ext="whl", hashes={"sha256": file_checksum, "other": "1234"}) assert link.hashes == {"sha256": file_checksum, "other": "1234"} - with pytest.warns(DeprecationWarning): - assert link.hash_name is None - with pytest.warns(DeprecationWarning): - assert link.hash is None assert link.show_url == "demo-1.0.0.whl" @@ -97,18 +85,10 @@ def test_package_link_pep658( assert link.has_metadata assert link.metadata_url == f"{link.url_without_fragment}.metadata" assert link.metadata_hashes == {"sha256": metadata_checksum} - with pytest.warns(DeprecationWarning): - assert link.metadata_hash == metadata_checksum - with pytest.warns(DeprecationWarning): - assert link.metadata_hash_name == "sha256" else: assert not link.has_metadata assert not link.metadata_url assert not link.metadata_hashes - with pytest.warns(DeprecationWarning): - assert not link.metadata_hash - with pytest.warns(DeprecationWarning): - assert not link.metadata_hash_name def test_package_link_pep658_no_default_metadata() -> None: @@ -152,10 +132,6 @@ def test_package_link_pep691() -> None: assert link.has_metadata assert link.metadata_url == f"{link.url_without_fragment}.metadata" assert link.metadata_hashes == {"sha256": "abcd", "sha512": "1234"} - with pytest.warns(DeprecationWarning): - assert link.metadata_hash is None - with pytest.warns(DeprecationWarning): - assert link.metadata_hash_name is None def test_package_link_pep592_default_not_yanked() -> None: