From f55f12b447ba1a79c182f5c1b073623df6d815d3 Mon Sep 17 00:00:00 2001 From: Ethan Paul <24588726+enpaul@users.noreply.github.com> Date: Fri, 16 Apr 2021 19:57:50 -0400 Subject: [PATCH] Update plugin modules to use internal logging wrapper --- tox_poetry_installer/hooks.py | 36 +++++++++++++------------------ tox_poetry_installer/installer.py | 19 ++++++---------- tox_poetry_installer/utilities.py | 26 +++++++--------------- 3 files changed, 29 insertions(+), 52 deletions(-) diff --git a/tox_poetry_installer/hooks.py b/tox_poetry_installer/hooks.py index 93831ea..1a0489c 100644 --- a/tox_poetry_installer/hooks.py +++ b/tox_poetry_installer/hooks.py @@ -12,9 +12,9 @@ from tox.config import Parser as ToxParser from tox.venv import VirtualEnv as ToxVirtualEnv from tox_poetry_installer import __about__ -from tox_poetry_installer import constants from tox_poetry_installer import exceptions from tox_poetry_installer import installer +from tox_poetry_installer import logger from tox_poetry_installer import utilities from tox_poetry_installer.datatypes import PackageMap @@ -83,19 +83,17 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional and venv.envconfig.config.option.require_poetry ): venv.status = err.__class__.__name__ - tox.reporter.error(str(err)) + logger.error(str(err)) return False - tox.reporter.verbosity1(str(err)) + logger.info(str(err)) return None - tox.reporter.verbosity1( - f"{constants.REPORTER_PREFIX} Loaded project pyproject.toml from {poetry.file}" - ) + logger.info(f"Loaded project pyproject.toml from {poetry.file}") virtualenv = utilities.convert_virtualenv(venv) if not poetry.locker.is_fresh(): - tox.reporter.warning( + logger.warning( f"The Poetry lock file is not up to date with the latest changes in {poetry.file}" ) @@ -112,42 +110,38 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional if venv.envconfig.install_dev_deps: dev_deps = utilities.find_dev_deps(packages, virtualenv, poetry) - tox.reporter.verbosity1( - f"{constants.REPORTER_PREFIX} Identified {len(dev_deps)} development dependencies to install to env" + logger.info( + f"Identified {len(dev_deps)} development dependencies to install to env" ) else: dev_deps = [] - tox.reporter.verbosity1( - f"{constants.REPORTER_PREFIX} Env does not install development dependencies, skipping" - ) + logger.info("Env does not install development dependencies, skipping") env_deps = utilities.find_additional_deps( packages, virtualenv, poetry, venv.envconfig.locked_deps ) - tox.reporter.verbosity1( - f"{constants.REPORTER_PREFIX} Identified {len(env_deps)} environment dependencies to install to env" + logger.info( + f"Identified {len(env_deps)} environment dependencies to install to env" ) if not venv.envconfig.skip_install and not venv.envconfig.config.skipsdist: project_deps = utilities.find_project_deps( packages, virtualenv, poetry, venv.envconfig.extras ) - tox.reporter.verbosity1( - f"{constants.REPORTER_PREFIX} Identified {len(project_deps)} project dependencies to install to env" + logger.info( + f"Identified {len(project_deps)} project dependencies to install to env" ) else: project_deps = [] - tox.reporter.verbosity1( - f"{constants.REPORTER_PREFIX} Env does not install project package, skipping" - ) + logger.info("Env does not install project package, skipping") except exceptions.ToxPoetryInstallerException as err: venv.status = err.__class__.__name__ - tox.reporter.error(f"{constants.REPORTER_PREFIX} {err}") + logger.error(str(err)) return False except Exception as err: venv.status = "InternalError" - tox.reporter.error(f"{constants.REPORTER_PREFIX} Internal plugin error: {err}") + logger.error(f"Internal plugin error: {err}") raise err dependencies = dev_deps + env_deps + project_deps diff --git a/tox_poetry_installer/installer.py b/tox_poetry_installer/installer.py index 6f612d6..1685ea0 100644 --- a/tox_poetry_installer/installer.py +++ b/tox_poetry_installer/installer.py @@ -9,11 +9,10 @@ from typing import Optional from typing import Sequence from typing import Set -import tox from poetry.core.packages import Package as PoetryPackage from tox.venv import VirtualEnv as ToxVirtualEnv -from tox_poetry_installer import constants +from tox_poetry_installer import logger from tox_poetry_installer import utilities if typing.TYPE_CHECKING: @@ -36,8 +35,8 @@ def install( """ from tox_poetry_installer import _poetry - tox.reporter.verbosity1( - f"{constants.REPORTER_PREFIX} Installing {len(packages)} packages to environment at {venv.envconfig.envdir}" + logger.info( + f"Installing {len(packages)} packages to environment at {venv.envconfig.envdir}" ) pip = _poetry.PipInstaller( @@ -68,14 +67,8 @@ def install( for dependency in packages: if dependency not in installed: installed.add(dependency) - tox.reporter.verbosity2( - f"{constants.REPORTER_PREFIX} Installing {dependency}" - ) + logger.debug(f"Installing {dependency}") executor(pip.install, dependency) else: - tox.reporter.verbosity2( - f"{constants.REPORTER_PREFIX} Skipping {dependency}, already installed" - ) - tox.reporter.verbosity2( - f"{constants.REPORTER_PREFIX} Waiting for installs to finish..." - ) + logger.debug(f"Skipping {dependency}, already installed") + logger.debug("Waiting for installs to finish...") diff --git a/tox_poetry_installer/utilities.py b/tox_poetry_installer/utilities.py index b2a450f..fd95daf 100644 --- a/tox_poetry_installer/utilities.py +++ b/tox_poetry_installer/utilities.py @@ -9,7 +9,6 @@ from typing import Sequence from typing import Set from typing import Union -import tox from poetry.core.packages import Dependency as PoetryDependency from poetry.core.packages import Package as PoetryPackage from tox.action import Action as ToxAction @@ -17,6 +16,7 @@ from tox.venv import VirtualEnv as ToxVirtualEnv from tox_poetry_installer import constants from tox_poetry_installer import exceptions +from tox_poetry_installer import logger from tox_poetry_installer.datatypes import PackageMap if typing.TYPE_CHECKING: @@ -101,14 +101,10 @@ def identify_transients( for requirement in packages[transient.name].requires: if requirement.name not in searched: _deps_of_dep(requirement) - tox.reporter.verbosity2( - f"{constants.REPORTER_PREFIX} Including {transient} for installation" - ) + logger.debug(f"Including {transient} for installation") transients.append(packages[transient.name]) else: - tox.reporter.verbosity2( - f"{constants.REPORTER_PREFIX} Skipping {transient}: package requires {transient.marker}" - ) + logger.debug(f"Skipping {transient}: package requires {transient.marker}") try: if isinstance(dep, str): @@ -119,18 +115,14 @@ def identify_transients( dep_name = err.args[0] if dep_name in _poetry.Provider.UNSAFE_PACKAGES: - tox.reporter.warning( - f"{constants.REPORTER_PREFIX} Installing package '{dep_name}' using Poetry is not supported and will be skipped" - ) - tox.reporter.verbosity2( - f"{constants.REPORTER_PREFIX} Skipping {dep_name}: designated unsafe by Poetry" + logger.warning( + f"Installing package '{dep_name}' using Poetry is not supported and will be skipped" ) + logger.debug(f"Skipping {dep_name}: designated unsafe by Poetry") return [] if dep_name in allow_missing: - tox.reporter.verbosity2( - f"{constants.REPORTER_PREFIX} Skipping {dep_name}: package is allowed to be unlocked" - ) + logger.debug(f"Skipping {dep_name}: package is allowed to be unlocked") return [] if any( @@ -171,9 +163,7 @@ def find_project_deps( extra_deps: List[PoetryPackage] = [] for extra in extras: - tox.reporter.verbosity1( - f"{constants.REPORTER_PREFIX} Processing project extra '{extra}'" - ) + logger.info(f"Processing project extra '{extra}'") try: extra_deps += [packages[item.name] for item in poetry.package.extras[extra]] except KeyError: