Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: fix handling of venv opts env vars #9015

Merged
merged 2 commits into from
Feb 25, 2024
Merged
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
7 changes: 7 additions & 0 deletions src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ def get(self, setting_name: str, default: Any = None) -> Any:

value = value[key]

if self._use_environment and isinstance(value, dict):
# this is a configuration table, it is likely that we missed env vars
# in order to capture them recurse, eg: virtualenvs.options
return {k: self.get(f"{setting_name}.{k}") for k in value}

return self.process(value)

def process(self, value: Any) -> Any:
Expand All @@ -299,6 +304,8 @@ def _get_normalizer(name: str) -> Callable[[str], Any]:
"virtualenvs.create",
"virtualenvs.in-project",
"virtualenvs.options.always-copy",
"virtualenvs.options.no-pip",
"virtualenvs.options.no-setuptools",
"virtualenvs.options.system-site-packages",
"virtualenvs.options.prefer-active-python",
"experimental.system-git-client",
Expand Down
17 changes: 17 additions & 0 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ def test_config_get_from_environment_variable(
assert config.get(name) is value


def test_config_get_from_environment_variable_nested(
config: Config,
environ: Iterator[None],
) -> None:
options = config.default_config["virtualenvs"]["options"]
expected = {}

for k, v in options.items():
if isinstance(v, bool):
expected[k] = not v
os.environ[f"POETRY_VIRTUALENVS_OPTIONS_{k.upper().replace('-', '_')}"] = (
"true" if expected[k] else "false"
)

assert config.get("virtualenvs.options") == expected


@pytest.mark.parametrize(
("path_config", "expected"),
[("~/.venvs", Path.home() / ".venvs"), ("venv", Path("venv"))],
Expand Down
Loading