implement tox_add_option hook

This commit is contained in:
Obeida Shamoun 2023-05-20 00:03:44 +02:00
parent 0693ce4706
commit c81215bc3b
No known key found for this signature in database
GPG Key ID: C393AE9D78004C18
4 changed files with 26 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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,
)

View File

@ -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 "