From 22012d44528d986be1632c7766d290e257796ee1 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Sat, 2 Jul 2022 23:28:43 -0400 Subject: [PATCH] Dedupe packages (with set()) earlier to improve logging and very slightly improve speed. --- tox_poetry_installer/hooks.py | 6 +++--- tox_poetry_installer/installer.py | 4 ++-- tox_poetry_installer/utilities.py | 16 ++++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/tox_poetry_installer/hooks.py b/tox_poetry_installer/hooks.py index 3caa457..162ef46 100644 --- a/tox_poetry_installer/hooks.py +++ b/tox_poetry_installer/hooks.py @@ -193,7 +193,7 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional f"Identified {len(dev_deps)} development dependencies to install to env" ) else: - dev_deps = [] + dev_deps = set() logger.info("Env does not install development dependencies, skipping") env_deps = utilities.find_additional_deps( @@ -220,7 +220,7 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional f"Identified {len(project_deps)} project dependencies to install to env" ) else: - project_deps = [] + project_deps = set() logger.info("Env does not install project package dependencies, skipping") except exceptions.ToxPoetryInstallerException as err: venv.status = err.__class__.__name__ @@ -231,7 +231,7 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional logger.error(f"Internal plugin error: {err}") raise err - dependencies = dev_deps + env_deps + project_deps + dependencies = dev_deps | env_deps | project_deps if ( venv.envconfig.config.option.parallel_install_threads != constants.DEFAULT_INSTALL_THREADS diff --git a/tox_poetry_installer/installer.py b/tox_poetry_installer/installer.py index 05466eb..5e0eda4 100644 --- a/tox_poetry_installer/installer.py +++ b/tox_poetry_installer/installer.py @@ -6,7 +6,7 @@ import concurrent.futures import contextlib import typing from datetime import datetime -from typing import Sequence +from typing import Collection from typing import Set from poetry.core.packages.package import Package as PoetryPackage @@ -22,7 +22,7 @@ if typing.TYPE_CHECKING: def install( poetry: "_poetry.Poetry", venv: ToxVirtualEnv, - packages: Sequence[PoetryPackage], + packages: Collection[PoetryPackage], parallels: int = 0, ): """Install a bunch of packages to a virtualenv diff --git a/tox_poetry_installer/utilities.py b/tox_poetry_installer/utilities.py index b051474..b350b4c 100644 --- a/tox_poetry_installer/utilities.py +++ b/tox_poetry_installer/utilities.py @@ -182,7 +182,7 @@ def find_project_deps( venv: "_poetry.VirtualEnv", poetry: "_poetry.Poetry", extras: Sequence[str] = (), -) -> List[PoetryPackage]: +) -> Set[PoetryPackage]: """Find the root project dependencies Recursively identify the dependencies of the root project package @@ -218,7 +218,7 @@ def find_project_deps( dep_name.lower(), packages, venv, allow_missing=[poetry.package.name] ) - return dependencies + return set(dependencies) def find_additional_deps( @@ -226,7 +226,7 @@ def find_additional_deps( venv: "_poetry.VirtualEnv", poetry: "_poetry.Poetry", dep_names: Sequence[str], -) -> List[PoetryPackage]: +) -> Set[PoetryPackage]: """Find additional dependencies Recursively identify the dependencies of an arbitrary list of package names @@ -243,12 +243,12 @@ def find_additional_deps( dep_name.lower(), packages, venv, allow_missing=[poetry.package.name] ) - return dependencies + return set(dependencies) def find_dev_deps( packages: PackageMap, venv: "_poetry.VirtualEnv", poetry: "_poetry.Poetry" -) -> List[PoetryPackage]: +) -> Set[PoetryPackage]: """Find the dev dependencies Recursively identify the Poetry dev dependencies @@ -261,7 +261,11 @@ def find_dev_deps( packages, venv, poetry, - poetry.pyproject.data["tool"]["poetry"].get("group", {}).get("dev", {}).get("dependencies", {}).keys() + poetry.pyproject.data["tool"]["poetry"] + .get("group", {}) + .get("dev", {}) + .get("dependencies", {}) + .keys(), ) # Legacy pyproject.toml poetry format: