Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,24 @@


if TYPE_CHECKING:
from collections.abc import Callable

from cleo.io.inputs.argument import Argument
from cleo.io.inputs.option import Option

from poetry.config.config_source import ConfigSource


def _int_validator(minimum: int) -> Callable[[str], bool]:
def validator(val: str) -> bool:
try:
return int(val) >= minimum
except ValueError:
return False

return validator


CONFIG_MIGRATIONS = [
ConfigSourceMigration(
old_key="experimental.system-git-client", new_key="system-git-client"
Expand Down Expand Up @@ -90,11 +103,11 @@ def unique_config_values(self) -> dict[str, tuple[Any, Any]]:
"virtualenvs.use-poetry-python": (boolean_validator, boolean_normalizer),
"virtualenvs.prompt": (str, str),
"system-git-client": (boolean_validator, boolean_normalizer),
"requests.max-retries": (lambda val: int(val) >= 0, int_normalizer),
"requests.max-retries": (_int_validator(0), int_normalizer),
"installer.re-resolve": (boolean_validator, boolean_normalizer),
"installer.parallel": (boolean_validator, boolean_normalizer),
"installer.builtin-uninstall": (boolean_validator, boolean_normalizer),
"installer.max-workers": (lambda val: int(val) > 0, int_normalizer),
"installer.max-workers": (_int_validator(1), int_normalizer),
"installer.no-binary": (
PackageFilterPolicy.validator,
PackageFilterPolicy.normalize,
Expand All @@ -104,7 +117,7 @@ def unique_config_values(self) -> dict[str, tuple[Any, Any]]:
PackageFilterPolicy.normalize,
),
"solver.lazy-wheel": (boolean_validator, boolean_normalizer),
"solver.min-release-age": (lambda val: int(val) >= 0, int_normalizer),
"solver.min-release-age": (_int_validator(0), int_normalizer),
"solver.min-release-age-exclude": (
PackageFilterPolicy.validator,
PackageFilterPolicy.normalize,
Expand Down
14 changes: 14 additions & 0 deletions tests/console/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ def test_cannot_set_invalid_value(tester: CommandTester) -> None:
assert str(e.value) == '"foo" is an invalid value for virtualenvs.create'


@pytest.mark.parametrize(
"setting",
["requests.max-retries", "installer.max-workers", "solver.min-release-age"],
)
@pytest.mark.parametrize("value", ["foo", "1.5", ""])
def test_cannot_set_non_integer_value(
tester: CommandTester, setting: str, value: str
) -> None:
with pytest.raises(RuntimeError) as e:
tester.execute(f"{setting} '{value}'")

assert str(e.value) == f'"{value}" is an invalid value for {setting}'


def test_cannot_unset_with_value(tester: CommandTester) -> None:
with pytest.raises(RuntimeError) as e:
tester.execute("virtualenvs.create false --unset")
Expand Down
Loading