From ab2f5a249de859bd1b1fb3d015f8d2b5ef6bd034 Mon Sep 17 00:00:00 2001 From: Bartosz Sokorski Date: Tue, 24 Sep 2024 00:25:05 +0200 Subject: [PATCH] Rename exceptions to have Error suffix --- pyproject.toml | 1 - src/poetry/console/commands/group_command.py | 4 +- src/poetry/console/exceptions.py | 2 +- src/poetry/exceptions.py | 2 +- src/poetry/factory.py | 4 +- src/poetry/inspection/lazy_wheel.py | 32 ++++++------ src/poetry/mixology/failure.py | 50 +++++++++---------- src/poetry/mixology/incompatibility.py | 50 +++++++++---------- src/poetry/mixology/incompatibility_cause.py | 14 +++--- src/poetry/mixology/version_solver.py | 17 ++++--- src/poetry/puzzle/exceptions.py | 8 +-- src/poetry/puzzle/provider.py | 16 +++--- src/poetry/puzzle/solver.py | 8 +-- src/poetry/repositories/exceptions.py | 2 +- src/poetry/repositories/http_repository.py | 10 ++-- src/poetry/repositories/legacy_repository.py | 10 ++-- src/poetry/repositories/pypi_repository.py | 8 +-- src/poetry/repositories/repository.py | 4 +- src/poetry/repositories/repository_pool.py | 6 +-- .../repositories/single_page_repository.py | 4 +- src/poetry/utils/authenticator.py | 4 +- src/poetry/utils/cache.py | 4 +- src/poetry/utils/env/__init__.py | 8 +-- src/poetry/utils/env/env_manager.py | 8 +-- src/poetry/utils/env/exceptions.py | 4 +- src/poetry/utils/env/python_manager.py | 4 +- src/poetry/utils/helpers.py | 4 +- src/poetry/utils/pip.py | 6 +-- src/poetry/utils/wheel.py | 4 +- tests/console/commands/test_install.py | 4 +- tests/helpers.py | 4 +- tests/inspection/test_lazy_wheel.py | 14 +++--- tests/installation/test_executor.py | 2 +- tests/mixology/helpers.py | 4 +- tests/mixology/test_incompatibility.py | 4 +- tests/puzzle/test_provider.py | 4 +- tests/repositories/test_http_repository.py | 10 ++-- tests/repositories/test_legacy_repository.py | 6 +-- tests/repositories/test_repository_pool.py | 6 +-- .../test_single_page_repository.py | 4 +- tests/test_factory.py | 4 +- tests/utils/env/test_env_manager.py | 12 ++--- tests/utils/test_helpers.py | 4 +- 43 files changed, 191 insertions(+), 189 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f9fe2d313e3..30cbc165f93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -126,7 +126,6 @@ extend-select = [ ignore = [ "B904", # use 'raise ... from err' "B905", # use explicit 'strict=' parameter with 'zip()' - "N818", # Exception name should be named with an Error suffix ] extend-safe-fixes = [ "TCH", # move import from and to TYPE_CHECKING blocks diff --git a/src/poetry/console/commands/group_command.py b/src/poetry/console/commands/group_command.py index c080dc1e5e1..750666f69ae 100644 --- a/src/poetry/console/commands/group_command.py +++ b/src/poetry/console/commands/group_command.py @@ -7,7 +7,7 @@ from poetry.core.packages.dependency_group import MAIN_GROUP from poetry.console.commands.command import Command -from poetry.console.exceptions import GroupNotFound +from poetry.console.exceptions import GroupNotFoundError if TYPE_CHECKING: @@ -128,4 +128,4 @@ def _validate_group_options(self, group_options: dict[str, set[str]]) -> None: for opt in sorted(invalid_options[group]) ) message_parts.append(f"{group} (via {opts})") - raise GroupNotFound(f"Group(s) not found: {', '.join(message_parts)}") + raise GroupNotFoundError(f"Group(s) not found: {', '.join(message_parts)}") diff --git a/src/poetry/console/exceptions.py b/src/poetry/console/exceptions.py index 2cc359ddb75..d45c38dd3df 100644 --- a/src/poetry/console/exceptions.py +++ b/src/poetry/console/exceptions.py @@ -7,5 +7,5 @@ class PoetryConsoleError(CleoError): pass -class GroupNotFound(PoetryConsoleError): +class GroupNotFoundError(PoetryConsoleError): pass diff --git a/src/poetry/exceptions.py b/src/poetry/exceptions.py index 68154f8d87d..170d1028edf 100644 --- a/src/poetry/exceptions.py +++ b/src/poetry/exceptions.py @@ -1,5 +1,5 @@ from __future__ import annotations -class PoetryException(Exception): +class PoetryError(Exception): pass diff --git a/src/poetry/factory.py b/src/poetry/factory.py index 052e9cd8105..7561bdfe208 100644 --- a/src/poetry/factory.py +++ b/src/poetry/factory.py @@ -14,7 +14,7 @@ from poetry.core.packages.dependency_group import MAIN_GROUP from poetry.config.config import Config -from poetry.exceptions import PoetryException +from poetry.exceptions import PoetryError from poetry.json import validate_object from poetry.packages.locker import Locker from poetry.plugins.plugin import Plugin @@ -155,7 +155,7 @@ def create_pool( ) if not pool.repositories: - raise PoetryException( + raise PoetryError( "At least one source must not be configured as 'explicit'." ) diff --git a/src/poetry/inspection/lazy_wheel.py b/src/poetry/inspection/lazy_wheel.py index 61cd5ce019e..8722a04ef5c 100644 --- a/src/poetry/inspection/lazy_wheel.py +++ b/src/poetry/inspection/lazy_wheel.py @@ -45,20 +45,20 @@ class LazyWheelUnsupportedError(Exception): """Raised when a lazy wheel is unsupported.""" -class HTTPRangeRequestUnsupported(LazyWheelUnsupportedError): +class HTTPRangeRequestUnsupportedError(LazyWheelUnsupportedError): """Raised when the remote server appears unable to support byte ranges.""" -class HTTPRangeRequestNotRespected(LazyWheelUnsupportedError): +class HTTPRangeRequestNotRespectedError(LazyWheelUnsupportedError): """Raised when the remote server tells us that it supports byte ranges but does not respect a respective request.""" -class UnsupportedWheel(LazyWheelUnsupportedError): +class UnsupportedWheelError(LazyWheelUnsupportedError): """Unsupported wheel.""" -class InvalidWheel(LazyWheelUnsupportedError): +class InvalidWheelError(LazyWheelUnsupportedError): """Invalid (e.g. corrupt) wheel.""" def __init__(self, location: str, name: str) -> None: @@ -77,8 +77,8 @@ def metadata_from_wheel_url( This uses HTTP range requests to only fetch the portion of the wheel containing metadata, just enough for the object to be constructed. - :raises HTTPRangeRequestUnsupported: if range requests are unsupported for ``url``. - :raises InvalidWheel: if the zip file contents could not be parsed. + :raises HTTPRangeRequestUnsupportedError: if range requests are unsupported for ``url``. + :raises InvalidWheelError: if the zip file contents could not be parsed. """ try: # After context manager exit, wheel.name will point to a deleted file path. @@ -89,11 +89,11 @@ def metadata_from_wheel_url( metadata, _ = parse_email(metadata_bytes) return metadata - except (BadZipFile, UnsupportedWheel): + except (BadZipFile, UnsupportedWheelError): # We assume that these errors have occurred because the wheel contents # themselves are invalid, not because we've messed up our bookkeeping # and produced an invalid file. - raise InvalidWheel(url, name) + raise InvalidWheelError(url, name) except Exception as e: if isinstance(e, LazyWheelUnsupportedError): # this is expected when the code handles issues with lazy wheel metadata retrieval correctly @@ -288,7 +288,7 @@ class LazyFileOverHTTP(ReadOnlyIOWrapper): This uses HTTP range requests to lazily fetch the file's content into a temporary file. If such requests are not supported by the server, raises - ``HTTPRangeRequestUnsupported`` in the ``__enter__`` method.""" + ``HTTPRangeRequestUnsupportedError`` in the ``__enter__`` method.""" def __init__( self, @@ -401,7 +401,7 @@ def _reset_content(self) -> None: def _content_length_from_head(self) -> int: """Performs a HEAD request to extract the Content-Length. - :raises HTTPRangeRequestUnsupported: if the response fails to indicate support + :raises HTTPRangeRequestUnsupportedError: if the response fails to indicate support for "bytes" ranges.""" self._request_count += 1 head = self._session.head( @@ -411,7 +411,7 @@ def _content_length_from_head(self) -> int: assert head.status_code == codes.ok accepted_range = head.headers.get("Accept-Ranges", None) if accepted_range != "bytes": - raise HTTPRangeRequestUnsupported( + raise HTTPRangeRequestUnsupportedError( f"server does not support byte ranges: header was '{accepted_range}'" ) return int(head.headers["Content-Length"]) @@ -431,7 +431,7 @@ def _stream_response(self, start: int, end: int) -> Response: response = self._session.get(self._url, headers=headers, stream=True) response.raise_for_status() if int(response.headers["Content-Length"]) != (end - start + 1): - raise HTTPRangeRequestNotRespected( + raise HTTPRangeRequestNotRespectedError( f"server did not respect byte range request: " f"requested {end - start + 1} bytes, got " f"{response.headers['Content-Length']} bytes" @@ -584,7 +584,9 @@ def _parse_full_length_from_content_range(arg: str) -> int: """ m = re.match(r"bytes [^/]+/([0-9]+)", arg) if m is None: - raise HTTPRangeRequestUnsupported(f"could not parse Content-Range: '{arg}'") + raise HTTPRangeRequestUnsupportedError( + f"could not parse Content-Range: '{arg}'" + ) return int(m.group(1)) def _try_initial_chunk_request( @@ -614,7 +616,7 @@ def _try_initial_chunk_request( if accept_ranges == "bytes" and content_length <= initial_chunk_size: return content_length, tail - raise HTTPRangeRequestUnsupported( + raise HTTPRangeRequestUnsupportedError( f"did not receive partial content: got code {code}" ) @@ -716,7 +718,7 @@ def _prefetch_metadata(self, name: str) -> str: end = info.header_offset break if start is None: - raise UnsupportedWheel( + raise UnsupportedWheelError( f"no {self._metadata_regex!r} found for {name} in {self.name}" ) # If it is the last entry of the zip, then give us everything diff --git a/src/poetry/mixology/failure.py b/src/poetry/mixology/failure.py index 84a7fb0642d..230cbdbd85d 100644 --- a/src/poetry/mixology/failure.py +++ b/src/poetry/mixology/failure.py @@ -4,15 +4,15 @@ from poetry.core.constraints.version import parse_constraint -from poetry.mixology.incompatibility_cause import ConflictCause -from poetry.mixology.incompatibility_cause import PythonCause +from poetry.mixology.incompatibility_cause import ConflictCauseError +from poetry.mixology.incompatibility_cause import PythonCauseError if TYPE_CHECKING: from poetry.mixology.incompatibility import Incompatibility -class SolveFailure(Exception): +class SolveFailureError(Exception): def __init__(self, incompatibility: Incompatibility) -> None: self._incompatibility = incompatibility @@ -38,7 +38,7 @@ def write(self) -> str: version_solutions = [] required_python_version_notification = False for incompatibility in self._root.external_incompatibilities: - if isinstance(incompatibility.cause, PythonCause): + if isinstance(incompatibility.cause, PythonCauseError): root_constraint = parse_constraint( incompatibility.cause.root_python_version ) @@ -73,7 +73,7 @@ def write(self) -> str: if required_python_version_notification: buffer.append("") - if isinstance(self._root.cause, ConflictCause): + if isinstance(self._root.cause, ConflictCauseError): self._visit(self._root) else: self._write(self._root, f"Because {self._root}, version solving failed.") @@ -150,10 +150,10 @@ def _visit( incompatibility_string = str(incompatibility) cause = incompatibility.cause - assert isinstance(cause, ConflictCause) + assert isinstance(cause, ConflictCauseError) - if isinstance(cause.conflict.cause, ConflictCause) and isinstance( - cause.other.cause, ConflictCause + if isinstance(cause.conflict.cause, ConflictCauseError) and isinstance( + cause.other.cause, ConflictCauseError ): conflict_line = self._line_numbers.get(cause.conflict) other_line = self._line_numbers.get(cause.other) @@ -211,17 +211,17 @@ def _visit( f" {incompatibility_string}", numbered=numbered, ) - elif isinstance(cause.conflict.cause, ConflictCause) or isinstance( - cause.other.cause, ConflictCause + elif isinstance(cause.conflict.cause, ConflictCauseError) or isinstance( + cause.other.cause, ConflictCauseError ): derived = ( cause.conflict - if isinstance(cause.conflict.cause, ConflictCause) + if isinstance(cause.conflict.cause, ConflictCauseError) else cause.other ) ext = ( cause.other - if isinstance(cause.conflict.cause, ConflictCause) + if isinstance(cause.conflict.cause, ConflictCauseError) else cause.conflict ) @@ -235,8 +235,8 @@ def _visit( ) elif self._is_collapsible(derived): derived_cause = derived.cause - assert isinstance(derived_cause, ConflictCause) - if isinstance(derived_cause.conflict.cause, ConflictCause): + assert isinstance(derived_cause, ConflictCauseError) + if isinstance(derived_cause.conflict.cause, ConflictCauseError): collapsed_derived = derived_cause.conflict collapsed_ext = derived_cause.other else: @@ -271,29 +271,29 @@ def _is_collapsible(self, incompatibility: Incompatibility) -> bool: return False cause = incompatibility.cause - assert isinstance(cause, ConflictCause) - if isinstance(cause.conflict.cause, ConflictCause) and isinstance( - cause.other.cause, ConflictCause + assert isinstance(cause, ConflictCauseError) + if isinstance(cause.conflict.cause, ConflictCauseError) and isinstance( + cause.other.cause, ConflictCauseError ): return False - if not isinstance(cause.conflict.cause, ConflictCause) and not isinstance( - cause.other.cause, ConflictCause + if not isinstance(cause.conflict.cause, ConflictCauseError) and not isinstance( + cause.other.cause, ConflictCauseError ): return False complex = ( cause.conflict - if isinstance(cause.conflict.cause, ConflictCause) + if isinstance(cause.conflict.cause, ConflictCauseError) else cause.other ) return complex not in self._line_numbers - def _is_single_line(self, cause: ConflictCause) -> bool: - return not isinstance(cause.conflict.cause, ConflictCause) and not isinstance( - cause.other.cause, ConflictCause - ) + def _is_single_line(self, cause: ConflictCauseError) -> bool: + return not isinstance( + cause.conflict.cause, ConflictCauseError + ) and not isinstance(cause.other.cause, ConflictCauseError) def _count_derivations(self, incompatibility: Incompatibility) -> None: if incompatibility in self._derivations: @@ -301,6 +301,6 @@ def _count_derivations(self, incompatibility: Incompatibility) -> None: else: self._derivations[incompatibility] = 1 cause = incompatibility.cause - if isinstance(cause, ConflictCause): + if isinstance(cause, ConflictCauseError): self._count_derivations(cause.conflict) self._count_derivations(cause.other) diff --git a/src/poetry/mixology/incompatibility.py b/src/poetry/mixology/incompatibility.py index 9a2cc96294c..32ceec37863 100644 --- a/src/poetry/mixology/incompatibility.py +++ b/src/poetry/mixology/incompatibility.py @@ -2,30 +2,30 @@ from typing import TYPE_CHECKING -from poetry.mixology.incompatibility_cause import ConflictCause -from poetry.mixology.incompatibility_cause import DependencyCause -from poetry.mixology.incompatibility_cause import NoVersionsCause -from poetry.mixology.incompatibility_cause import PlatformCause -from poetry.mixology.incompatibility_cause import PythonCause -from poetry.mixology.incompatibility_cause import RootCause +from poetry.mixology.incompatibility_cause import ConflictCauseError +from poetry.mixology.incompatibility_cause import DependencyCauseError +from poetry.mixology.incompatibility_cause import NoVersionsCauseError +from poetry.mixology.incompatibility_cause import PlatformCauseError +from poetry.mixology.incompatibility_cause import PythonCauseError +from poetry.mixology.incompatibility_cause import RootCauseError if TYPE_CHECKING: from collections.abc import Callable from collections.abc import Iterator - from poetry.mixology.incompatibility_cause import IncompatibilityCause + from poetry.mixology.incompatibility_cause import IncompatibilityCauseError from poetry.mixology.term import Term class Incompatibility: - def __init__(self, terms: list[Term], cause: IncompatibilityCause) -> None: + def __init__(self, terms: list[Term], cause: IncompatibilityCauseError) -> None: # Remove the root package from generated incompatibilities, since it will # always be satisfied. This makes error reporting clearer, and may also # make solving more efficient. if ( len(terms) != 1 - and isinstance(cause, ConflictCause) + and isinstance(cause, ConflictCauseError) and any(term.is_positive() and term.dependency.is_root for term in terms) ): terms = [ @@ -81,7 +81,7 @@ def terms(self) -> list[Term]: return self._terms @property - def cause(self) -> IncompatibilityCause: + def cause(self) -> IncompatibilityCauseError: return self._cause @property @@ -92,8 +92,8 @@ def external_incompatibilities( Returns all external incompatibilities in this incompatibility's derivation graph. """ - if isinstance(self._cause, ConflictCause): - cause: ConflictCause = self._cause + if isinstance(self._cause, ConflictCauseError): + cause: ConflictCauseError = self._cause yield from cause.conflict.external_incompatibilities yield from cause.other.external_incompatibilities @@ -106,7 +106,7 @@ def is_failure(self) -> bool: ) def __str__(self) -> str: - if isinstance(self._cause, DependencyCause): + if isinstance(self._cause, DependencyCauseError): assert len(self._terms) == 2 depender = self._terms[0] @@ -118,7 +118,7 @@ def __str__(self) -> str: f"{self._terse(depender, allow_every=True)} depends on" f" {self._terse(dependee)}" ) - elif isinstance(self._cause, PythonCause): + elif isinstance(self._cause, PythonCauseError): assert len(self._terms) == 1 assert self._terms[0].is_positive() @@ -126,7 +126,7 @@ def __str__(self) -> str: text += f"Python {self._cause.python_version}" return text - elif isinstance(self._cause, PlatformCause): + elif isinstance(self._cause, PlatformCauseError): assert len(self._terms) == 1 assert self._terms[0].is_positive() @@ -134,7 +134,7 @@ def __str__(self) -> str: text += f"platform {self._cause.platform}" return text - elif isinstance(self._cause, NoVersionsCause): + elif isinstance(self._cause, NoVersionsCauseError): assert len(self._terms) == 1 assert self._terms[0].is_positive() @@ -142,7 +142,7 @@ def __str__(self) -> str: f"no versions of {self._terms[0].dependency.name} match" f" {self._terms[0].constraint}" ) - elif isinstance(self._cause, RootCause): + elif isinstance(self._cause, RootCauseError): assert len(self._terms) == 1 assert not self._terms[0].is_positive() assert self._terms[0].dependency.is_root @@ -261,8 +261,8 @@ def _try_requires_both( ) buffer = [self._terse(this_positive, allow_every=True) + " "] - is_dependency = isinstance(self.cause, DependencyCause) and isinstance( - other.cause, DependencyCause + is_dependency = isinstance(self.cause, DependencyCauseError) and isinstance( + other.cause, DependencyCauseError ) if is_dependency: @@ -331,7 +331,7 @@ def _try_requires_through( prior_string = " or ".join([self._terse(term) for term in prior_positives]) buffer.append(f"if {prior_string} then ") else: - if isinstance(prior.cause, DependencyCause): + if isinstance(prior.cause, DependencyCauseError): verb = "depends on" else: verb = "requires" @@ -346,7 +346,7 @@ def _try_requires_through( buffer.append(" which ") - if isinstance(latter.cause, DependencyCause): + if isinstance(latter.cause, DependencyCauseError): buffer.append("depends on ") else: buffer.append("requires ") @@ -397,7 +397,7 @@ def _try_requires_forbidden( buffer.append(f"if {prior_string} then ") else: buffer.append(self._terse(positives[0], allow_every=True)) - if isinstance(prior.cause, DependencyCause): + if isinstance(prior.cause, DependencyCauseError): buffer.append(" depends on ") else: buffer.append(" requires ") @@ -406,10 +406,10 @@ def _try_requires_forbidden( if prior_line is not None: buffer.append(f"({prior_line}) ") - if isinstance(latter.cause, PythonCause): - cause: PythonCause = latter.cause + if isinstance(latter.cause, PythonCauseError): + cause: PythonCauseError = latter.cause buffer.append(f"which requires Python {cause.python_version}") - elif isinstance(latter.cause, NoVersionsCause): + elif isinstance(latter.cause, NoVersionsCauseError): buffer.append("which doesn't match any versions") else: buffer.append("which is forbidden") diff --git a/src/poetry/mixology/incompatibility_cause.py b/src/poetry/mixology/incompatibility_cause.py index 1536d1b22b2..aaabd570eda 100644 --- a/src/poetry/mixology/incompatibility_cause.py +++ b/src/poetry/mixology/incompatibility_cause.py @@ -7,25 +7,25 @@ from poetry.mixology.incompatibility import Incompatibility -class IncompatibilityCause(Exception): +class IncompatibilityCauseError(Exception): """ The reason and Incompatibility's terms are incompatible. """ -class RootCause(IncompatibilityCause): +class RootCauseError(IncompatibilityCauseError): pass -class NoVersionsCause(IncompatibilityCause): +class NoVersionsCauseError(IncompatibilityCauseError): pass -class DependencyCause(IncompatibilityCause): +class DependencyCauseError(IncompatibilityCauseError): pass -class ConflictCause(IncompatibilityCause): +class ConflictCauseError(IncompatibilityCauseError): """ The incompatibility was derived from two existing incompatibilities during conflict resolution. @@ -47,7 +47,7 @@ def __str__(self) -> str: return str(self._conflict) -class PythonCause(IncompatibilityCause): +class PythonCauseError(IncompatibilityCauseError): """ The incompatibility represents a package's python constraint (Python versions) being incompatible @@ -67,7 +67,7 @@ def root_python_version(self) -> str: return self._root_python_version -class PlatformCause(IncompatibilityCause): +class PlatformCauseError(IncompatibilityCauseError): """ The incompatibility represents a package's platform constraint (OS most likely) being incompatible with the current platform. diff --git a/src/poetry/mixology/version_solver.py b/src/poetry/mixology/version_solver.py index 5bb02d9418a..30b87087f60 100644 --- a/src/poetry/mixology/version_solver.py +++ b/src/poetry/mixology/version_solver.py @@ -10,11 +10,11 @@ from poetry.core.packages.dependency import Dependency -from poetry.mixology.failure import SolveFailure +from poetry.mixology.failure import SolveFailureError from poetry.mixology.incompatibility import Incompatibility -from poetry.mixology.incompatibility_cause import ConflictCause -from poetry.mixology.incompatibility_cause import NoVersionsCause -from poetry.mixology.incompatibility_cause import RootCause +from poetry.mixology.incompatibility_cause import ConflictCauseError +from poetry.mixology.incompatibility_cause import NoVersionsCauseError +from poetry.mixology.incompatibility_cause import RootCauseError from poetry.mixology.partial_solution import PartialSolution from poetry.mixology.result import SolverResult from poetry.mixology.set_relation import SetRelation @@ -165,7 +165,7 @@ def solve(self) -> SolverResult: root_dependency.is_root = True self._add_incompatibility( - Incompatibility([Term(root_dependency, False)], RootCause()) + Incompatibility([Term(root_dependency, False)], RootCauseError()) ) try: @@ -412,7 +412,8 @@ def _resolve_conflict(self, incompatibility: Incompatibility) -> Incompatibility new_terms.append(inverse) incompatibility = Incompatibility( - new_terms, ConflictCause(incompatibility, most_recent_satisfier.cause) + new_terms, + ConflictCauseError(incompatibility, most_recent_satisfier.cause), ) new_incompatibility = True @@ -424,7 +425,7 @@ def _resolve_conflict(self, incompatibility: Incompatibility) -> Incompatibility self._log(f'! which is caused by "{most_recent_satisfier.cause}"') self._log(f"! thus: {incompatibility}") - raise SolveFailure(incompatibility) + raise SolveFailureError(incompatibility) def _choose_package_version(self) -> str | None: """ @@ -503,7 +504,7 @@ def _get_min(dependency: Dependency) -> tuple[bool, int, int]: # If there are no versions that satisfy the constraint, # add an incompatibility that indicates that. self._add_incompatibility( - Incompatibility([Term(dependency, True)], NoVersionsCause()) + Incompatibility([Term(dependency, True)], NoVersionsCauseError()) ) complete_name = dependency.complete_name diff --git a/src/poetry/puzzle/exceptions.py b/src/poetry/puzzle/exceptions.py index 6bb7c0027bc..c33ab4f2f93 100644 --- a/src/poetry/puzzle/exceptions.py +++ b/src/poetry/puzzle/exceptions.py @@ -7,21 +7,21 @@ from poetry.core.packages.dependency import Dependency from poetry.core.packages.package import Package - from poetry.mixology.failure import SolveFailure + from poetry.mixology.failure import SolveFailureError class SolverProblemError(Exception): - def __init__(self, error: SolveFailure) -> None: + def __init__(self, error: SolveFailureError) -> None: self._error = error super().__init__(str(error)) @property - def error(self) -> SolveFailure: + def error(self) -> SolveFailureError: return self._error -class OverrideNeeded(Exception): +class OverrideNeededError(Exception): def __init__(self, *overrides: dict[Package, dict[str, Dependency]]) -> None: self._overrides = overrides diff --git a/src/poetry/puzzle/provider.py b/src/poetry/puzzle/provider.py index 754795b845c..590afc8c7b1 100644 --- a/src/poetry/puzzle/provider.py +++ b/src/poetry/puzzle/provider.py @@ -20,14 +20,14 @@ from poetry.core.version.markers import union as marker_union from poetry.mixology.incompatibility import Incompatibility -from poetry.mixology.incompatibility_cause import DependencyCause -from poetry.mixology.incompatibility_cause import PythonCause +from poetry.mixology.incompatibility_cause import DependencyCauseError +from poetry.mixology.incompatibility_cause import PythonCauseError from poetry.mixology.term import Term from poetry.packages import DependencyPackage from poetry.packages.direct_origin import DirectOrigin from poetry.packages.package_collection import PackageCollection -from poetry.puzzle.exceptions import OverrideNeeded -from poetry.repositories.exceptions import PackageNotFound +from poetry.puzzle.exceptions import OverrideNeededError +from poetry.repositories.exceptions import PackageNotFoundError from poetry.utils.helpers import get_file_hash @@ -446,7 +446,7 @@ def incompatibilities_for( return [ Incompatibility( [Term(package.to_dependency(), True)], - PythonCause( + PythonCauseError( package.python_versions, str(self._python_constraint) ), ) @@ -464,7 +464,7 @@ def incompatibilities_for( return [ Incompatibility( [Term(package.to_dependency(), True), Term(dep, False)], - DependencyCause(), + DependencyCauseError(), ) for dep in dependencies ] @@ -493,7 +493,7 @@ def complete_package( repository_name=dependency.source_name, ), ) - except PackageNotFound as e: + except PackageNotFoundError as e: try: dependency_package = next( DependencyPackage(dependency, pkg) @@ -650,7 +650,7 @@ def fmt_warning(d: Dependency) -> str: overrides.append(current_overrides) if overrides: - raise OverrideNeeded(*overrides) + raise OverrideNeededError(*overrides) # Modifying dependencies as needed clean_dependencies = [] diff --git a/src/poetry/puzzle/solver.py b/src/poetry/puzzle/solver.py index dcfb7e626e5..0b6742217d8 100644 --- a/src/poetry/puzzle/solver.py +++ b/src/poetry/puzzle/solver.py @@ -9,8 +9,8 @@ from typing import Tuple from poetry.mixology import resolve_version -from poetry.mixology.failure import SolveFailure -from poetry.puzzle.exceptions import OverrideNeeded +from poetry.mixology.failure import SolveFailureError +from poetry.puzzle.exceptions import OverrideNeededError from poetry.puzzle.exceptions import SolverProblemError from poetry.puzzle.provider import Indicator from poetry.puzzle.provider import Provider @@ -155,9 +155,9 @@ def _solve(self) -> tuple[list[Package], list[int]]: result = resolve_version(self._package, self._provider) packages = result.packages - except OverrideNeeded as e: + except OverrideNeededError as e: return self._solve_in_compatibility_mode(e.overrides) - except SolveFailure as e: + except SolveFailureError as e: raise SolverProblemError(e) combined_nodes = depth_first_search(PackageNode(self._package, packages)) diff --git a/src/poetry/repositories/exceptions.py b/src/poetry/repositories/exceptions.py index c742f268a42..1e5be368749 100644 --- a/src/poetry/repositories/exceptions.py +++ b/src/poetry/repositories/exceptions.py @@ -5,7 +5,7 @@ class RepositoryError(Exception): pass -class PackageNotFound(Exception): +class PackageNotFoundError(Exception): pass diff --git a/src/poetry/repositories/http_repository.py b/src/poetry/repositories/http_repository.py index 7d0249b897d..581bd7eebb7 100644 --- a/src/poetry/repositories/http_repository.py +++ b/src/poetry/repositories/http_repository.py @@ -24,12 +24,12 @@ from poetry.inspection.lazy_wheel import LazyWheelUnsupportedError from poetry.inspection.lazy_wheel import metadata_from_wheel_url from poetry.repositories.cached_repository import CachedRepository -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError from poetry.repositories.exceptions import RepositoryError from poetry.repositories.link_sources.html import HTMLPage from poetry.utils.authenticator import Authenticator from poetry.utils.constants import REQUESTS_TIMEOUT -from poetry.utils.helpers import HTTPRangeRequestSupported +from poetry.utils.helpers import HTTPRangeRequestSupportedError from poetry.utils.helpers import download_file from poetry.utils.helpers import get_highest_priority_hash_type from poetry.utils.patterns import wheel_file_re @@ -146,7 +146,7 @@ def _get_info_from_wheel(self, link: Link) -> PackageInfo: link, raise_accepts_ranges=raise_accepts_ranges ) as filepath: return PackageInfo.from_wheel(filepath) - except HTTPRangeRequestSupported: + except HTTPRangeRequestSupportedError: # The domain did not support range requests for the first URL(s) we tried, # but supports it for some URLs (especially the current URL), # so we abort the download, update _supports_range_requests to try @@ -336,7 +336,7 @@ def _get_info_from_links( def _links_to_data(self, links: list[Link], data: PackageInfo) -> dict[str, Any]: if not links: - raise PackageNotFound( + raise PackageNotFoundError( f'No valid distribution links found for package: "{data.name}" version:' f' "{data.version}"' ) @@ -429,5 +429,5 @@ def _get_response(self, endpoint: str) -> requests.Response | None: def _get_page(self, name: NormalizedName) -> LinkSource: response = self._get_response(f"/{name}/") if not response: - raise PackageNotFound(f"Package [{name}] not found.") + raise PackageNotFoundError(f"Package [{name}] not found.") return HTMLPage(response.url, response.text) diff --git a/src/poetry/repositories/legacy_repository.py b/src/poetry/repositories/legacy_repository.py index 8b1bcea8236..5cdcd7cc35f 100644 --- a/src/poetry/repositories/legacy_repository.py +++ b/src/poetry/repositories/legacy_repository.py @@ -10,7 +10,7 @@ from poetry.core.packages.package import Package from poetry.inspection.info import PackageInfo -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError from poetry.repositories.http_repository import HTTPRepository from poetry.repositories.link_sources.html import HTMLPage from poetry.repositories.link_sources.html import SimpleRepositoryRootPage @@ -68,7 +68,7 @@ def package( def find_links_for_package(self, package: Package) -> list[Link]: try: page = self.get_page(package.name) - except PackageNotFound: + except PackageNotFoundError: return [] return list(page.links_for_version(package.name, package.version)) @@ -81,7 +81,7 @@ def _find_packages( """ try: page = self.get_page(name) - except PackageNotFound: + except PackageNotFoundError: self._log(f"No packages found for {name}", level="debug") return [] @@ -127,7 +127,7 @@ def _get_release_info( def _get_page(self, name: NormalizedName) -> HTMLPage: if not (response := self._get_response(f"/{name}/")): - raise PackageNotFound(f"Package [{name}] not found.") + raise PackageNotFoundError(f"Package [{name}] not found.") return HTMLPage(response.url, response.text) @cached_property @@ -145,7 +145,7 @@ def search(self, query: str) -> list[Package]: results: list[Package] = [] for candidate in self.root_page.search(query): - with suppress(PackageNotFound): + with suppress(PackageNotFoundError): page = self.get_page(candidate) for package in page.packages: diff --git a/src/poetry/repositories/pypi_repository.py b/src/poetry/repositories/pypi_repository.py index 43d6c512324..eeabbcf2689 100644 --- a/src/poetry/repositories/pypi_repository.py +++ b/src/poetry/repositories/pypi_repository.py @@ -13,7 +13,7 @@ from poetry.core.packages.utils.link import Link from poetry.core.version.exceptions import InvalidVersion -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError from poetry.repositories.http_repository import HTTPRepository from poetry.repositories.link_sources.json import SimpleJsonPage from poetry.repositories.parsers.pypi_search_parser import SearchResultParser @@ -90,7 +90,7 @@ def _find_packages( """ try: json_page = self.get_page(name) - except PackageNotFound: + except PackageNotFoundError: self._log(f"No packages found for {name}", level="debug") return [] @@ -106,7 +106,7 @@ def _get_package_info(self, name: NormalizedName) -> dict[str, Any]: headers = {"Accept": "application/vnd.pypi.simple.v1+json"} info = self._get(f"simple/{name}/", headers=headers) if info is None: - raise PackageNotFound(f"Package [{name}] not found.") + raise PackageNotFoundError(f"Package [{name}] not found.") return info @@ -132,7 +132,7 @@ def _get_release_info( json_data = self._get(f"pypi/{name}/{version}/json") if json_data is None: - raise PackageNotFound(f"Package [{name}] not found.") + raise PackageNotFoundError(f"Package [{name}] not found.") info = json_data["info"] diff --git a/src/poetry/repositories/repository.py b/src/poetry/repositories/repository.py index 1f6aef2ff7c..1f15721f7bd 100644 --- a/src/poetry/repositories/repository.py +++ b/src/poetry/repositories/repository.py @@ -8,7 +8,7 @@ from poetry.core.constraints.version import Version from poetry.repositories.abstract_repository import AbstractRepository -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError if TYPE_CHECKING: @@ -105,4 +105,4 @@ def package( if canonicalized_name == package.name and package.version == version: return package - raise PackageNotFound(f"Package {name} ({version}) not found.") + raise PackageNotFoundError(f"Package {name} ({version}) not found.") diff --git a/src/poetry/repositories/repository_pool.py b/src/poetry/repositories/repository_pool.py index 6a68b503fe3..2adfdd872b2 100644 --- a/src/poetry/repositories/repository_pool.py +++ b/src/poetry/repositories/repository_pool.py @@ -10,7 +10,7 @@ from poetry.config.config import Config from poetry.repositories.abstract_repository import AbstractRepository -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError from poetry.repositories.repository import Repository from poetry.utils.cache import ArtifactCache @@ -179,9 +179,9 @@ def package( for repo in self.repositories: try: return repo.package(name, version, extras=extras) - except PackageNotFound: + except PackageNotFoundError: continue - raise PackageNotFound(f"Package {name} ({version}) not found.") + raise PackageNotFoundError(f"Package {name} ({version}) not found.") def find_packages(self, dependency: Dependency) -> list[Package]: repository_name = dependency.source_name diff --git a/src/poetry/repositories/single_page_repository.py b/src/poetry/repositories/single_page_repository.py index 446957f12db..dc318fd91f6 100644 --- a/src/poetry/repositories/single_page_repository.py +++ b/src/poetry/repositories/single_page_repository.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError from poetry.repositories.legacy_repository import LegacyRepository from poetry.repositories.link_sources.html import HTMLPage @@ -18,5 +18,5 @@ def _get_page(self, name: NormalizedName) -> HTMLPage: """ response = self._get_response("") if not response: - raise PackageNotFound(f"Package [{name}] not found.") + raise PackageNotFoundError(f"Package [{name}] not found.") return HTMLPage(response.url, response.text) diff --git a/src/poetry/utils/authenticator.py b/src/poetry/utils/authenticator.py index 2a5e663abf0..f19ee99b18e 100644 --- a/src/poetry/utils/authenticator.py +++ b/src/poetry/utils/authenticator.py @@ -22,7 +22,7 @@ from poetry.__version__ import __version__ from poetry.config.config import Config -from poetry.exceptions import PoetryException +from poetry.exceptions import PoetryError from poetry.utils.constants import REQUESTS_TIMEOUT from poetry.utils.constants import RETRY_AFTER_HEADER from poetry.utils.constants import STATUS_FORCELIST @@ -247,7 +247,7 @@ def request( continue # this should never really be hit under any sane circumstance - raise PoetryException("Failed HTTP {} request", method.upper()) + raise PoetryError("Failed HTTP {} request", method.upper()) def _get_backoff(self, response: requests.Response | None, attempt: int) -> float: if response is not None: diff --git a/src/poetry/utils/cache.py b/src/poetry/utils/cache.py index 1f0f18ed5e5..90dd1a46f52 100644 --- a/src/poetry/utils/cache.py +++ b/src/poetry/utils/cache.py @@ -19,7 +19,7 @@ from poetry.utils._compat import decode from poetry.utils._compat import encode from poetry.utils.helpers import get_highest_priority_hash_type -from poetry.utils.wheel import InvalidWheelName +from poetry.utils.wheel import InvalidWheelNameError from poetry.utils.wheel import Wheel @@ -316,7 +316,7 @@ def _get_cached_archive( try: wheel = Wheel(archive.name) - except InvalidWheelName: + except InvalidWheelNameError: continue if not wheel.is_supported_by_environment(env): diff --git a/src/poetry/utils/env/__init__.py b/src/poetry/utils/env/__init__.py index d15530a76ad..c3834f4fbaf 100644 --- a/src/poetry/utils/env/__init__.py +++ b/src/poetry/utils/env/__init__.py @@ -12,8 +12,8 @@ from poetry.utils.env.exceptions import EnvError from poetry.utils.env.exceptions import IncorrectEnvError from poetry.utils.env.exceptions import InvalidCurrentPythonVersionError -from poetry.utils.env.exceptions import NoCompatiblePythonVersionFound -from poetry.utils.env.exceptions import PythonVersionNotFound +from poetry.utils.env.exceptions import NoCompatiblePythonVersionFoundError +from poetry.utils.env.exceptions import PythonVersionNotFoundError from poetry.utils.env.generic_env import GenericEnv from poetry.utils.env.mock_env import MockEnv from poetry.utils.env.null_env import NullEnv @@ -102,8 +102,8 @@ def build_environment( "EnvCommandError", "IncorrectEnvError", "InvalidCurrentPythonVersionError", - "NoCompatiblePythonVersionFound", - "PythonVersionNotFound", + "NoCompatiblePythonVersionFoundError", + "PythonVersionNotFoundError", "Env", "EnvManager", "GenericEnv", diff --git a/src/poetry/utils/env/env_manager.py b/src/poetry/utils/env/env_manager.py index d33f963bb87..8d0835b0692 100644 --- a/src/poetry/utils/env/env_manager.py +++ b/src/poetry/utils/env/env_manager.py @@ -25,8 +25,8 @@ from poetry.utils.env.exceptions import EnvCommandError from poetry.utils.env.exceptions import IncorrectEnvError from poetry.utils.env.exceptions import InvalidCurrentPythonVersionError -from poetry.utils.env.exceptions import NoCompatiblePythonVersionFound -from poetry.utils.env.exceptions import PythonVersionNotFound +from poetry.utils.env.exceptions import NoCompatiblePythonVersionFoundError +from poetry.utils.env.exceptions import PythonVersionNotFoundError from poetry.utils.env.generic_env import GenericEnv from poetry.utils.env.python_manager import Python from poetry.utils.env.script_strings import GET_ENV_PATH_ONELINER @@ -125,7 +125,7 @@ def activate(self, python: str) -> Env: python_ = Python.get_by_name(python) if python_ is None: - raise PythonVersionNotFound(python) + raise PythonVersionNotFoundError(python) create = False # If we are required to create the virtual environment in the project directory, @@ -425,7 +425,7 @@ def create_venv( # and notify the user of the incompatibility. # Otherwise, we try to find a compatible Python version. if executable and not prefer_active_python: - raise NoCompatiblePythonVersionFound( + raise NoCompatiblePythonVersionFoundError( self._poetry.package.python_versions, python.patch_version.to_string(), ) diff --git a/src/poetry/utils/env/exceptions.py b/src/poetry/utils/env/exceptions.py index ece3b3924a0..78082d45932 100644 --- a/src/poetry/utils/env/exceptions.py +++ b/src/poetry/utils/env/exceptions.py @@ -33,12 +33,12 @@ def __init__(self, e: CalledProcessError) -> None: super().__init__("\n\n".join(message_parts)) -class PythonVersionNotFound(EnvError): +class PythonVersionNotFoundError(EnvError): def __init__(self, expected: str) -> None: super().__init__(f"Could not find the python executable {expected}") -class NoCompatiblePythonVersionFound(EnvError): +class NoCompatiblePythonVersionFoundError(EnvError): def __init__(self, expected: str, given: str | None = None) -> None: if given: message = ( diff --git a/src/poetry/utils/env/python_manager.py b/src/poetry/utils/env/python_manager.py index b0c52ccea30..ce1d8103978 100644 --- a/src/poetry/utils/env/python_manager.py +++ b/src/poetry/utils/env/python_manager.py @@ -14,7 +14,7 @@ from poetry.core.constraints.version import parse_constraint from poetry.utils._compat import decode -from poetry.utils.env.exceptions import NoCompatiblePythonVersionFound +from poetry.utils.env.exceptions import NoCompatiblePythonVersionFoundError from poetry.utils.env.script_strings import GET_PYTHON_VERSION_ONELINER @@ -162,6 +162,6 @@ def get_compatible_python(cls, poetry: Poetry, io: IO | None = None) -> Python: break if not python: - raise NoCompatiblePythonVersionFound(poetry.package.python_versions) + raise NoCompatiblePythonVersionFoundError(poetry.package.python_versions) return python diff --git a/src/poetry/utils/helpers.py b/src/poetry/utils/helpers.py index 07e0ce41687..22608f8c3eb 100644 --- a/src/poetry/utils/helpers.py +++ b/src/poetry/utils/helpers.py @@ -125,7 +125,7 @@ def merge_dicts(d1: dict[str, Any], d2: dict[str, Any]) -> None: d1[k] = d2[k] -class HTTPRangeRequestSupported(Exception): +class HTTPRangeRequestSupportedError(Exception): """Raised when server unexpectedly supports byte ranges.""" @@ -143,7 +143,7 @@ def download_file( downloader = Downloader(url, dest, session, max_retries=max_retries) if raise_accepts_ranges and downloader.accepts_ranges: - raise HTTPRangeRequestSupported(f"URL {url} supports range requests.") + raise HTTPRangeRequestSupportedError(f"URL {url} supports range requests.") set_indicator = False with Indicator.context() as update_context: diff --git a/src/poetry/utils/pip.py b/src/poetry/utils/pip.py index b74294795ed..458e897855e 100644 --- a/src/poetry/utils/pip.py +++ b/src/poetry/utils/pip.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING -from poetry.exceptions import PoetryException +from poetry.exceptions import PoetryError from poetry.utils.env import EnvCommandError @@ -45,7 +45,7 @@ def pip_install( if editable: if not path.is_dir(): - raise PoetryException( + raise PoetryError( "Cannot install non directory dependencies in editable mode" ) args.append("-e") @@ -55,4 +55,4 @@ def pip_install( try: return environment.run_pip(*args) except EnvCommandError as e: - raise PoetryException(f"Failed to install {path}") from e + raise PoetryError(f"Failed to install {path}") from e diff --git a/src/poetry/utils/wheel.py b/src/poetry/utils/wheel.py index f45c50b3b35..bb4a70b7907 100644 --- a/src/poetry/utils/wheel.py +++ b/src/poetry/utils/wheel.py @@ -16,7 +16,7 @@ logger = logging.getLogger(__name__) -class InvalidWheelName(Exception): +class InvalidWheelNameError(Exception): pass @@ -24,7 +24,7 @@ class Wheel: def __init__(self, filename: str) -> None: wheel_info = wheel_file_re.match(filename) if not wheel_info: - raise InvalidWheelName(f"{filename} is not a valid wheel filename.") + raise InvalidWheelNameError(f"{filename} is not a valid wheel filename.") self.filename = filename self.name = wheel_info.group("name").replace("_", "-") diff --git a/tests/console/commands/test_install.py b/tests/console/commands/test_install.py index 696bf493822..2cc5f7a29a5 100644 --- a/tests/console/commands/test_install.py +++ b/tests/console/commands/test_install.py @@ -10,7 +10,7 @@ from poetry.core.packages.dependency_group import MAIN_GROUP from poetry.console.commands.installer_command import InstallerCommand -from poetry.console.exceptions import GroupNotFound +from poetry.console.exceptions import GroupNotFoundError from tests.helpers import TestLocker @@ -324,7 +324,7 @@ def test_invalid_groups_with_without_only( tester.execute(cmd_args) assert tester.status_code == 1 else: - with pytest.raises(GroupNotFound, match=r"^Group\(s\) not found:") as e: + with pytest.raises(GroupNotFoundError, match=r"^Group\(s\) not found:") as e: tester.execute(cmd_args) assert tester.status_code is None for opt, groups in options.items(): diff --git a/tests/helpers.py b/tests/helpers.py index 431b52c5df9..491cec88a91 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -18,7 +18,7 @@ from poetry.installation.executor import Executor from poetry.packages import Locker from poetry.repositories import Repository -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError from poetry.utils._compat import metadata @@ -215,7 +215,7 @@ class TestRepository(Repository): def find_packages(self, dependency: Dependency) -> list[Package]: packages = super().find_packages(dependency) if len(packages) == 0: - raise PackageNotFound(f"Package [{dependency.name}] not found.") + raise PackageNotFoundError(f"Package [{dependency.name}] not found.") return packages diff --git a/tests/inspection/test_lazy_wheel.py b/tests/inspection/test_lazy_wheel.py index 1a71cf0b441..4c149a7a0e7 100644 --- a/tests/inspection/test_lazy_wheel.py +++ b/tests/inspection/test_lazy_wheel.py @@ -14,9 +14,9 @@ from requests import codes -from poetry.inspection.lazy_wheel import HTTPRangeRequestNotRespected -from poetry.inspection.lazy_wheel import HTTPRangeRequestUnsupported -from poetry.inspection.lazy_wheel import InvalidWheel +from poetry.inspection.lazy_wheel import HTTPRangeRequestNotRespectedError +from poetry.inspection.lazy_wheel import HTTPRangeRequestUnsupportedError +from poetry.inspection.lazy_wheel import InvalidWheelError from poetry.inspection.lazy_wheel import LazyWheelUnsupportedError from poetry.inspection.lazy_wheel import metadata_from_wheel_url from tests.helpers import http_setup_redirect @@ -377,7 +377,7 @@ def test_metadata_from_wheel_url_range_requests_not_supported_one_request( url = f"https://{domain}/poetry_core-1.5.0-py3-none-any.whl" - with pytest.raises(HTTPRangeRequestUnsupported): + with pytest.raises(HTTPRangeRequestUnsupportedError): metadata_from_wheel_url("poetry-core", url, requests.Session()) latest_requests = http.latest_requests() @@ -407,7 +407,7 @@ def test_metadata_from_wheel_url_range_requests_not_supported_two_requests( url = f"https://{domain}/poetry_core-1.5.0-py3-none-any.whl" - with pytest.raises(HTTPRangeRequestUnsupported): + with pytest.raises(HTTPRangeRequestUnsupportedError): metadata_from_wheel_url("poetry-core", url, requests.Session()) latest_requests = http.latest_requests() @@ -431,7 +431,7 @@ def test_metadata_from_wheel_url_range_requests_supported_but_not_respected( url = f"https://{domain}/poetry_core-1.5.0-py3-none-any.whl" - with pytest.raises(HTTPRangeRequestNotRespected): + with pytest.raises(HTTPRangeRequestNotRespectedError): metadata_from_wheel_url("poetry-core", url, requests.Session()) latest_requests = http.latest_requests() @@ -453,7 +453,7 @@ def test_metadata_from_wheel_url_invalid_wheel( url = f"https://{domain}/demo_missing_dist_info-0.1.0-py2.py3-none-any.whl" - with pytest.raises(InvalidWheel): + with pytest.raises(InvalidWheelError): metadata_from_wheel_url("demo-missing-dist-info", url, requests.Session()) latest_requests = http.latest_requests() diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index dc82247f675..00f7f179cd7 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -1342,7 +1342,7 @@ def test_build_system_requires_not_available( - Installing {package_name} ({package_version} {package_url}) - SolveFailure + SolveFailureError Because -root- depends on poetry-core (0.999) which doesn't match any versions,\ version solving failed. diff --git a/tests/mixology/helpers.py b/tests/mixology/helpers.py index c2c28e19853..c8dde3e5ae8 100644 --- a/tests/mixology/helpers.py +++ b/tests/mixology/helpers.py @@ -5,7 +5,7 @@ from poetry.core.packages.package import Package from poetry.factory import Factory -from poetry.mixology.failure import SolveFailure +from poetry.mixology.failure import SolveFailureError from poetry.mixology.version_solver import VersionSolver @@ -52,7 +52,7 @@ def check_solver_result( with provider.use_latest_for(use_latest or []): try: solution = solver.solve() - except SolveFailure as e: + except SolveFailureError as e: if error: assert str(e) == error diff --git a/tests/mixology/test_incompatibility.py b/tests/mixology/test_incompatibility.py index d3395f13796..f125abb6347 100644 --- a/tests/mixology/test_incompatibility.py +++ b/tests/mixology/test_incompatibility.py @@ -6,7 +6,7 @@ from poetry.core.packages.url_dependency import URLDependency from poetry.mixology.incompatibility import Incompatibility -from poetry.mixology.incompatibility_cause import DependencyCause +from poetry.mixology.incompatibility_cause import DependencyCauseError from poetry.mixology.term import Term @@ -45,6 +45,6 @@ def test_str_dependency_cause( dependency1: Dependency, dependency2: Dependency, expected: str ) -> None: incompatibility = Incompatibility( - [Term(dependency1, True), Term(dependency2, False)], DependencyCause() + [Term(dependency1, True), Term(dependency2, False)], DependencyCauseError() ) assert str(incompatibility) == expected diff --git a/tests/puzzle/test_provider.py b/tests/puzzle/test_provider.py index d79ecdba92d..e4fa5c855a0 100644 --- a/tests/puzzle/test_provider.py +++ b/tests/puzzle/test_provider.py @@ -24,7 +24,7 @@ from poetry.packages import DependencyPackage from poetry.puzzle.provider import IncompatibleConstraintsError from poetry.puzzle.provider import Provider -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError from poetry.repositories.repository import Repository from poetry.repositories.repository_pool import Priority from poetry.repositories.repository_pool import RepositoryPool @@ -852,7 +852,7 @@ def test_complete_package_raises_packagenotfound_if_locked_source_not_available( locked = provider.get_locked(dependency) assert locked is not None - with pytest.raises(PackageNotFound): + with pytest.raises(PackageNotFoundError): provider.complete_package(locked) diff --git a/tests/repositories/test_http_repository.py b/tests/repositories/test_http_repository.py index 64a5ba6b176..fa1c9cc417c 100644 --- a/tests/repositories/test_http_repository.py +++ b/tests/repositories/test_http_repository.py @@ -14,9 +14,9 @@ from poetry.core.packages.utils.link import Link from poetry.inspection.info import PackageInfoError -from poetry.inspection.lazy_wheel import HTTPRangeRequestUnsupported +from poetry.inspection.lazy_wheel import HTTPRangeRequestUnsupportedError from poetry.repositories.http_repository import HTTPRepository -from poetry.utils.helpers import HTTPRangeRequestSupported +from poetry.utils.helpers import HTTPRangeRequestSupportedError if TYPE_CHECKING: @@ -121,7 +121,7 @@ def test_get_info_from_wheel_state_sequence(mocker: MockerFixture) -> None: repo = MockRepository() # 1. range request and download - mock_metadata_from_wheel_url.side_effect = HTTPRangeRequestUnsupported + mock_metadata_from_wheel_url.side_effect = HTTPRangeRequestUnsupportedError with contextlib.suppress(PackageInfoError): repo._get_info_from_wheel(link) @@ -140,7 +140,7 @@ def test_get_info_from_wheel_state_sequence(mocker: MockerFixture) -> None: # 3. download and range request mock_metadata_from_wheel_url.side_effect = None - mock_download.side_effect = HTTPRangeRequestSupported + mock_download.side_effect = HTTPRangeRequestSupportedError with contextlib.suppress(PackageInfoError): repo._get_info_from_wheel(link) @@ -157,7 +157,7 @@ def test_get_info_from_wheel_state_sequence(mocker: MockerFixture) -> None: assert mock_download.call_count == 3 # 5. range request and download - mock_metadata_from_wheel_url.side_effect = HTTPRangeRequestUnsupported + mock_metadata_from_wheel_url.side_effect = HTTPRangeRequestUnsupportedError mock_download.side_effect = None with contextlib.suppress(PackageInfoError): diff --git a/tests/repositories/test_legacy_repository.py b/tests/repositories/test_legacy_repository.py index f4d955fbae6..3b122e19a53 100644 --- a/tests/repositories/test_legacy_repository.py +++ b/tests/repositories/test_legacy_repository.py @@ -14,7 +14,7 @@ from poetry.core.packages.utils.link import Link from poetry.factory import Factory -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError from poetry.repositories.exceptions import RepositoryError from poetry.repositories.legacy_repository import LegacyRepository @@ -124,7 +124,7 @@ def test_sdist_format_support(legacy_repository: LegacyRepository) -> None: def test_missing_version(legacy_repository: LegacyRepository) -> None: repo = legacy_repository - with pytest.raises(PackageNotFound): + with pytest.raises(PackageNotFoundError): repo._get_release_info( canonicalize_name("missing_version"), Version.parse("1.1.0") ) @@ -562,7 +562,7 @@ def test_get_40x_and_returns_none( ) -> None: repo = MockHttpRepository({"/foo/": status_code}, http) - with pytest.raises(PackageNotFound): + with pytest.raises(PackageNotFoundError): repo.get_page("foo") diff --git a/tests/repositories/test_repository_pool.py b/tests/repositories/test_repository_pool.py index 056b1b0ee50..9c4036146a0 100644 --- a/tests/repositories/test_repository_pool.py +++ b/tests/repositories/test_repository_pool.py @@ -6,7 +6,7 @@ from poetry.repositories import Repository from poetry.repositories import RepositoryPool -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError from poetry.repositories.legacy_repository import LegacyRepository from poetry.repositories.repository_pool import Priority from tests.helpers import get_dependency @@ -209,7 +209,7 @@ def test_pool_no_package_from_any_repository_raises_package_not_found() -> None: pool = RepositoryPool() pool.add_repository(Repository("repo")) - with pytest.raises(PackageNotFound): + with pytest.raises(PackageNotFoundError): pool.package("foo", Version.parse("1.0.0")) @@ -219,7 +219,7 @@ def test_pool_no_package_from_specified_repository_raises_package_not_found() -> repo2 = Repository("repo2", [package]) pool = RepositoryPool([repo1, repo2]) - with pytest.raises(PackageNotFound): + with pytest.raises(PackageNotFoundError): pool.package("foo", Version.parse("1.0.0"), repository_name="repo1") diff --git a/tests/repositories/test_single_page_repository.py b/tests/repositories/test_single_page_repository.py index 05789690874..61b8f48501b 100644 --- a/tests/repositories/test_single_page_repository.py +++ b/tests/repositories/test_single_page_repository.py @@ -7,7 +7,7 @@ from poetry.core.packages.dependency import Dependency -from poetry.repositories.exceptions import PackageNotFound +from poetry.repositories.exceptions import PackageNotFoundError from poetry.repositories.link_sources.html import HTMLPage from poetry.repositories.single_page_repository import SinglePageRepository @@ -30,7 +30,7 @@ def __init__(self, page: str) -> None: def _get_page(self, name: NormalizedName) -> HTMLPage: fixture = self.FIXTURES / self.url.rsplit("/", 1)[-1] if not fixture.exists(): - raise PackageNotFound(f"Package [{name}] not found.") + raise PackageNotFoundError(f"Package [{name}] not found.") with fixture.open(encoding="utf-8") as f: return HTMLPage(self._url, f.read()) diff --git a/tests/test_factory.py b/tests/test_factory.py index a05dd2fbb86..288154eaee5 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -14,7 +14,7 @@ from poetry.core.packages.package import Package from poetry.core.packages.vcs_dependency import VCSDependency -from poetry.exceptions import PoetryException +from poetry.exceptions import PoetryError from poetry.factory import Factory from poetry.plugins.plugin import Plugin from poetry.repositories.exceptions import InvalidSourceError @@ -350,7 +350,7 @@ def test_poetry_with_explicit_pypi_and_other( def test_poetry_with_pypi_explicit_only( project: str, fixture_dir: FixtureDirGetter, with_simple_keyring: None ) -> None: - with pytest.raises(PoetryException) as e: + with pytest.raises(PoetryError) as e: Factory().create_poetry(fixture_dir(project)) assert str(e.value) == "At least one source must not be configured as 'explicit'." diff --git a/tests/utils/env/test_env_manager.py b/tests/utils/env/test_env_manager.py index ef49d367797..fd673f8b167 100644 --- a/tests/utils/env/test_env_manager.py +++ b/tests/utils/env/test_env_manager.py @@ -19,8 +19,8 @@ from poetry.utils.env import EnvManager from poetry.utils.env import IncorrectEnvError from poetry.utils.env import InvalidCurrentPythonVersionError -from poetry.utils.env import NoCompatiblePythonVersionFound -from poetry.utils.env import PythonVersionNotFound +from poetry.utils.env import NoCompatiblePythonVersionFoundError +from poetry.utils.env import PythonVersionNotFoundError from poetry.utils.env.env_manager import EnvsFile from poetry.utils.helpers import remove_directory @@ -216,7 +216,7 @@ def test_activate_fails_when_python_cannot_be_found( mocker.patch("shutil.which", return_value=None) - with pytest.raises(PythonVersionNotFound) as e: + with pytest.raises(PythonVersionNotFoundError) as e: manager.activate("python3.7") expected_message = "Could not find the python executable python3.7" @@ -931,7 +931,7 @@ def test_create_venv_finds_no_python_executable( poetry.package.python_versions = "^999" - with pytest.raises(NoCompatiblePythonVersionFound) as e: + with pytest.raises(NoCompatiblePythonVersionFoundError) as e: manager.create_venv() expected_message = ( @@ -1000,7 +1000,7 @@ def test_create_venv_fails_if_no_compatible_python_version_could_be_found( "poetry.utils.env.EnvManager.build_venv", side_effect=lambda *args, **kwargs: "" ) - with pytest.raises(NoCompatiblePythonVersionFound) as e: + with pytest.raises(NoCompatiblePythonVersionFoundError) as e: manager.create_venv() expected_message = ( @@ -1026,7 +1026,7 @@ def test_create_venv_does_not_try_to_find_compatible_versions_with_executable( "poetry.utils.env.EnvManager.build_venv", side_effect=lambda *args, **kwargs: "" ) - with pytest.raises(NoCompatiblePythonVersionFound) as e: + with pytest.raises(NoCompatiblePythonVersionFoundError) as e: manager.create_venv(executable=Path("python3.8")) expected_message = ( diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index a2aa909e936..462cfb636df 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -12,7 +12,7 @@ from requests.exceptions import ChunkedEncodingError from poetry.utils.helpers import Downloader -from poetry.utils.helpers import HTTPRangeRequestSupported +from poetry.utils.helpers import HTTPRangeRequestSupportedError from poetry.utils.helpers import download_file from poetry.utils.helpers import get_file_hash from poetry.utils.helpers import get_highest_priority_hash_type @@ -261,7 +261,7 @@ def handle_request( dest = tmp_path / filename if accepts_ranges and raise_accepts_ranges: - with pytest.raises(HTTPRangeRequestSupported): + with pytest.raises(HTTPRangeRequestSupportedError): download_file(url, dest, raise_accepts_ranges=raise_accepts_ranges) assert not dest.exists() else: