Skip to content

Commit

Permalink
Fix linting and styling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Dec 19, 2021
1 parent 7fc06ac commit ad3678e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 62 deletions.
7 changes: 0 additions & 7 deletions src/poetry/console/commands/plugin/add.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import os

from typing import TYPE_CHECKING

from cleo.helpers import argument
from cleo.helpers import option

from poetry.console.commands.init import InitCommand
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"
Expand Down
16 changes: 4 additions & 12 deletions src/poetry/console/commands/plugin/plugin_command_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -90,8 +84,6 @@ def update(
io: "IO",
whitelist: List[str],
) -> int:
import os

from pathlib import Path

from poetry.factory import Factory
Expand Down
37 changes: 12 additions & 25 deletions src/poetry/console/commands/plugin/remove.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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"<warning>Plugin {plugin} is not installed.</warning>")
Expand All @@ -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,
)
Expand Down
3 changes: 1 addition & 2 deletions src/poetry/console/commands/plugin/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -130,15 +129,15 @@ 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:
io = NullIO()

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)
Expand Down
3 changes: 1 addition & 2 deletions src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 13 additions & 9 deletions tests/installation/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ad3678e

Please sign in to comment.