From c81215bc3b9f723027708aff664b68349a6b6bc1 Mon Sep 17 00:00:00 2001 From: Obeida Shamoun <2135622+oshmoun@users.noreply.github.com> Date: Sat, 20 May 2023 00:03:44 +0200 Subject: [PATCH] implement tox_add_option hook --- tox.ini | 6 +++--- tox_poetry_installer/__init__.py | 1 + tox_poetry_installer/hooks.py | 23 +++++++++++++++++++++-- tox_poetry_installer/utilities.py | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/tox.ini b/tox.ini index fe639a5..e271141 100644 --- a/tox.ini +++ b/tox.ini @@ -20,7 +20,7 @@ commands = [testenv:static] description = Static formatting and quality enforcement -basepython = py3.10 +basepython = py310 platform = linux ignore_errors = true locked_deps = @@ -45,7 +45,7 @@ commands = [testenv:static-tests] description = Static formatting and quality enforcement for the tests -basepython = py3.10 +basepython = py310 platform = linux ignore_errors = true locked_deps = @@ -62,7 +62,7 @@ commands = [testenv:security] description = Security checks -basepython = py3.10 +basepython = py310 platform = linux ignore_errors = true skip_install = true diff --git a/tox_poetry_installer/__init__.py b/tox_poetry_installer/__init__.py index 46e0b0a..fda75d3 100644 --- a/tox_poetry_installer/__init__.py +++ b/tox_poetry_installer/__init__.py @@ -1,4 +1,5 @@ # pylint: disable=missing-docstring from tox_poetry_installer.hooks import tox_add_core_config from tox_poetry_installer.hooks import tox_add_env_config +from tox_poetry_installer.hooks import tox_add_option from tox_poetry_installer.hooks import tox_on_install diff --git a/tox_poetry_installer/hooks.py b/tox_poetry_installer/hooks.py index f87a9f6..41b5e91 100644 --- a/tox_poetry_installer/hooks.py +++ b/tox_poetry_installer/hooks.py @@ -7,6 +7,7 @@ themselves manageable). from itertools import chain from typing import List +from tox.config.cli.parser import ToxParser from tox.config.sets import ConfigSet from tox.config.sets import EnvConfigSet from tox.plugin import impl @@ -31,6 +32,25 @@ def tox_add_core_config(core_conf: ConfigSet): ) +@impl +def tox_add_option(parser: ToxParser): + """Add additional command line arguments to tox to configure plugin behavior""" + parser.add_argument( + "--require-poetry", + action="store_true", + dest="require_poetry", + help="(deprecated) Trigger a failure if Poetry is not available to Tox", + ) + + parser.add_argument( + "--parallel-install-threads", + type=int, + dest="parallel_install_threads", + default=constants.DEFAULT_INSTALL_THREADS, + help="Number of locked dependencies to install simultaneously; set to 0 to disable parallel installation", + ) + + @impl def tox_add_env_config(env_conf: EnvConfigSet): """Add required env configuration options to the tox INI file""" @@ -164,10 +184,9 @@ def tox_on_install( raise err dependencies = utilities.dedupe_packages(group_deps + env_deps + project_deps) - installer.install( poetry, tox_env, dependencies, - tox_env.core["parallel_install_threads"], + tox_env.options.parallel_install_threads, ) diff --git a/tox_poetry_installer/utilities.py b/tox_poetry_installer/utilities.py index e005b4e..dce3656 100644 --- a/tox_poetry_installer/utilities.py +++ b/tox_poetry_installer/utilities.py @@ -37,7 +37,7 @@ def check_preconditions(venv: ToxVirtualEnv) -> "_poetry.Poetry": if isinstance(venv, PackageToxEnv): raise exceptions.SkipEnvironment(f"Skipping Tox provisioning env '{venv.name}'") - if venv.conf["require_poetry"]: + if venv.options.require_poetry: logger.warning( "DEPRECATION: The '--require-poetry' runtime option is deprecated and will be " "removed in version 1.0.0. Please update test environments that require Poetry to "