From ad3678ef8dfd46d89eb849bec9ad92832e4a3ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Sun, 19 Dec 2021 20:22:35 +0100 Subject: [PATCH] Fix linting and styling issues --- src/poetry/console/commands/plugin/add.py | 7 ---- .../commands/plugin/plugin_command_mixin.py | 16 ++------ src/poetry/console/commands/plugin/remove.py | 37 ++++++------------- src/poetry/console/commands/plugin/show.py | 3 +- src/poetry/factory.py | 5 +-- src/poetry/packages/locker.py | 3 +- src/poetry/puzzle/provider.py | 2 - tests/installation/test_installer.py | 22 ++++++----- 8 files changed, 33 insertions(+), 62 deletions(-) diff --git a/src/poetry/console/commands/plugin/add.py b/src/poetry/console/commands/plugin/add.py index 6acc68bd107..c8a09772cd7 100644 --- a/src/poetry/console/commands/plugin/add.py +++ b/src/poetry/console/commands/plugin/add.py @@ -1,7 +1,5 @@ import os -from typing import TYPE_CHECKING - from cleo.helpers import argument from cleo.helpers import option @@ -9,11 +7,6 @@ from poetry.console.commands.plugin.plugin_command_mixin import PluginCommandMixin -if TYPE_CHECKING: - from poetry.console.application import Application # noqa - from poetry.console.commands.update import UpdateCommand # noqa - - class PluginAddCommand(InitCommand, PluginCommandMixin): name = "plugin add" diff --git a/src/poetry/console/commands/plugin/plugin_command_mixin.py b/src/poetry/console/commands/plugin/plugin_command_mixin.py index e2ebcc12e11..47407c69e73 100644 --- a/src/poetry/console/commands/plugin/plugin_command_mixin.py +++ b/src/poetry/console/commands/plugin/plugin_command_mixin.py @@ -3,8 +3,6 @@ from typing import TYPE_CHECKING from typing import List -import tomlkit - from poetry.packages.locker import BaseLocker from poetry.utils.helpers import canonicalize_name @@ -53,14 +51,10 @@ def create_env_package( entry_points.add(entry_point.distro.name) - found = False - for dependency in root_package.requires: - if canonicalize_name(entry_point.distro.name) == dependency.name: - found = True - - break - - if found: + if any( + canonicalize_name(entry_point.distro.name) == dependency.name + for dependency in root_package.requires + ): continue version = entry_point.distro.version @@ -90,8 +84,6 @@ def update( io: "IO", whitelist: List[str], ) -> int: - import os - from pathlib import Path from poetry.factory import Factory diff --git a/src/poetry/console/commands/plugin/remove.py b/src/poetry/console/commands/plugin/remove.py index 5795a5d5162..a58237225f2 100644 --- a/src/poetry/console/commands/plugin/remove.py +++ b/src/poetry/console/commands/plugin/remove.py @@ -1,17 +1,10 @@ import os -from typing import TYPE_CHECKING - from cleo.helpers import argument from cleo.helpers import option from poetry.console.commands.command import Command - -from .plugin_command_mixin import PluginCommandMixin - - -if TYPE_CHECKING: - from poetry.console.application import Application # noqa +from poetry.console.commands.plugin.plugin_command_mixin import PluginCommandMixin class PluginRemoveCommand(Command, PluginCommandMixin): @@ -60,18 +53,13 @@ def handle(self) -> int: removed_plugins = [] for plugin in plugins: plugin = canonicalize_name(plugin) - is_plugin = False - installed = False - for entrypoint in entrypoints: - if canonicalize_name(entrypoint.distro.name) == plugin: - is_plugin = True - break - - for i, dependency in enumerate(root_package.requires): - if dependency.name == plugin: - installed = True - - break + is_plugin = any( + canonicalize_name(entrypoint.distro.name) == plugin + for entrypoint in entrypoints + ) + installed = any( + dependency.name == plugin for dependency in root_package.requires + ) if not installed: self.line_error(f"Plugin {plugin} is not installed.") @@ -92,15 +80,14 @@ def handle(self) -> int: if not removed_plugins: return 1 - _root_package = root_package - root_package = root_package.with_dependency_groups([], only=True) - for dependency in _root_package.requires: + bare_root_package = root_package.with_dependency_groups([], only=True) + for dependency in root_package.requires: if dependency.name not in removed_plugins: - root_package.add_dependency(dependency) + bare_root_package.add_dependency(dependency) return_code = self.update( system_env, - root_package, + bare_root_package, self._io, whitelist=removed_plugins, ) diff --git a/src/poetry/console/commands/plugin/show.py b/src/poetry/console/commands/plugin/show.py index 82e6aab45d3..06f8e861e21 100644 --- a/src/poetry/console/commands/plugin/show.py +++ b/src/poetry/console/commands/plugin/show.py @@ -6,8 +6,7 @@ from typing import Union from poetry.console.commands.command import Command - -from .plugin_command_mixin import PluginCommandMixin +from poetry.console.commands.plugin.plugin_command_mixin import PluginCommandMixin if TYPE_CHECKING: diff --git a/src/poetry/factory.py b/src/poetry/factory.py index 61eadb90ebf..9fba72995a0 100644 --- a/src/poetry/factory.py +++ b/src/poetry/factory.py @@ -83,7 +83,6 @@ def create_poetry( } ) - # Configuring sources poetry.set_pool(self.create_pool(config, io)) plugin_manager = PluginManager("plugin", disable_plugins=disable_plugins) @@ -130,7 +129,7 @@ def create_config(cls, io: Optional["IO"] = None) -> Config: return config @classmethod - def create_pool(cls, config: "Config", io: Optional["IO"] = None) -> "Pool": + def create_pool(cls, config: Config, io: Optional["IO"] = None) -> "Pool": from poetry.repositories.pool import Pool if io is None: @@ -138,7 +137,7 @@ def create_pool(cls, config: "Config", io: Optional["IO"] = None) -> "Pool": pool = Pool() - for source_name, source in config.get("sources", {}).items(): + for _, source in config.get("sources", {}).items(): repository = cls.create_legacy_repository(source, config) is_default = source.get("default", False) is_secondary = source.get("secondary", False) diff --git a/src/poetry/packages/locker.py b/src/poetry/packages/locker.py index 2e2e157999b..025489b5927 100644 --- a/src/poetry/packages/locker.py +++ b/src/poetry/packages/locker.py @@ -11,7 +11,6 @@ from typing import Iterable from typing import Iterator from typing import List -from typing import NoReturn from typing import Optional from typing import Sequence from typing import Set @@ -449,7 +448,7 @@ def _get_content_hash(self) -> str: return content_hash - def _verify_lock_data(self, lock_data: dict) -> NoReturn: + def _verify_lock_data(self, lock_data: dict) -> None: lock_version = Version.parse(lock_data["metadata"].get("lock-version", "1.0")) current_version = Version.parse(self._VERSION) # We expect the locker to be able to read lock files diff --git a/src/poetry/puzzle/provider.py b/src/poetry/puzzle/provider.py index 28361323984..b1b7032cb82 100644 --- a/src/poetry/puzzle/provider.py +++ b/src/poetry/puzzle/provider.py @@ -189,8 +189,6 @@ def search_for_vcs(self, dependency: "VCSDependency") -> List["Package"]: dependency._constraint = package.version dependency._pretty_constraint = package.version.text - dependency._source_resolved_reference = package.source_resolved_reference - dependency._source_reference = package.source_reference dependency._source_resolved_reference = package.source_resolved_reference diff --git a/tests/installation/test_installer.py b/tests/installation/test_installer.py index a5fadaba094..80462fd9c9e 100644 --- a/tests/installation/test_installer.py +++ b/tests/installation/test_installer.py @@ -27,7 +27,7 @@ from poetry.installation import Installer as BaseInstaller from poetry.installation.executor import Executor as BaseExecutor from poetry.installation.noop_installer import NoopInstaller -from poetry.packages.locker import Locker as BaseLocker +from poetry.packages.locker import Locker from poetry.repositories import Pool from poetry.repositories import Repository from poetry.repositories.installed_repository import InstalledRepository @@ -102,7 +102,7 @@ def load( return cls() -class Locker(BaseLocker): +class MockLocker(Locker): def __init__(self, lock_path: Union[str, Path]): self._lock = TOMLFile(lock_path.joinpath("poetry.lock")) self._root = self._lock.path.parent @@ -116,13 +116,13 @@ def __init__(self, lock_path: Union[str, Path]): def written_data(self) -> Optional[Dict]: return self._written_data - def set_lock_path(self, lock: Union[str, Path]) -> "Locker": + def set_lock_path(self, lock: Union[str, Path]) -> "MockLocker": self._lock = TOMLFile(Path(lock).joinpath("poetry.lock")) self._root = self._lock.path.parent return self - def locked(self, is_locked: bool = True) -> "Locker": + def locked(self, is_locked: bool = True) -> "MockLocker": self._locked = is_locked return self @@ -176,7 +176,7 @@ def installed() -> CustomInstalledRepository: @pytest.fixture() def locker(project_root: Path) -> Locker: - return Locker(lock_path=project_root) + return MockLocker(lock_path=project_root) @pytest.fixture() @@ -311,7 +311,11 @@ def test_run_update_after_removing_dependencies( def test_run_update_should_not_remove_existing_but_non_locked_packages( - installer, locker, repo, package, installed + installer: Installer, + locker: Locker, + repo: Repository, + package: ProjectPackage, + installed: CustomInstalledRepository, ): locker.locked(True) locker.mock_lock_data( @@ -375,9 +379,9 @@ def test_run_update_should_not_remove_existing_but_non_locked_packages( installer.whitelist(["c"]) installer.run() - assert 0 == installer.executor.installations_count - assert 0 == installer.executor.updates_count - assert 0 == installer.executor.removals_count + assert installer.executor.installations_count == 0 + assert installer.executor.updates_count == 0 + assert installer.executor.removals_count == 0 def _configure_run_install_dev(