Skip to content

Commit

Permalink
feat(config)!: change virtualenvs.prefer-active-python default to true
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Oct 20, 2024
1 parent 948f2e8 commit d600f6d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,12 @@ This setting controls the global virtual environment storage path. It most likel

**Type**: `boolean`

**Default**: `false`
**Default**: `true`

**Environment Variable**: `POETRY_VIRTUALENVS_PREFER_ACTIVE_PYTHON`

*Default changed to `true` in 2.0.0*

*Introduced in 1.2.0*

Use currently activated Python version to create a new virtual environment.
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Config:
"system-site-packages": False,
"no-pip": False,
},
"prefer-active-python": False,
"prefer-active-python": True,
"prompt": "{project_name}-py{python_version}",
},
"experimental": {
Expand Down
12 changes: 6 additions & 6 deletions tests/console/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_list_displays_default_value_if_not_set(
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
virtualenvs.prefer-active-python = true
virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
"""

Expand Down Expand Up @@ -99,7 +99,7 @@ def test_list_displays_set_get_setting(
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
virtualenvs.prefer-active-python = true
virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
"""

Expand Down Expand Up @@ -151,7 +151,7 @@ def test_unset_setting(
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
virtualenvs.prefer-active-python = true
virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
"""
assert config.set_config_source.call_count == 0 # type: ignore[attr-defined]
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_unset_repo_setting(
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
virtualenvs.prefer-active-python = true
virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
"""
assert config.set_config_source.call_count == 0 # type: ignore[attr-defined]
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_list_displays_set_get_local_setting(
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
virtualenvs.prefer-active-python = true
virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
"""

Expand Down Expand Up @@ -348,7 +348,7 @@ def test_list_must_not_display_sources_from_pyproject_toml(
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
virtualenvs.prefer-active-python = true
virtualenvs.prompt = "{{project_name}}-py{{python_version}}"
"""

Expand Down
8 changes: 8 additions & 0 deletions tests/utils/env/test_env_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ def test_deactivate_non_activated_but_existing(
mocker: MockerFixture,
venv_name: str,
) -> None:
config.config["virtualenvs"]["prefer-active-python"] = False
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]

Expand Down Expand Up @@ -521,6 +522,7 @@ def test_deactivate_activated(
mocker: MockerFixture,
venv_name: str,
) -> None:
config.config["virtualenvs"]["prefer-active-python"] = False
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]

Expand Down Expand Up @@ -894,6 +896,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_generic_
venv_name: str,
venv_flags_default: dict[str, bool],
) -> None:
config.config["virtualenvs"]["prefer-active-python"] = False
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]

Expand Down Expand Up @@ -952,6 +955,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
venv_name: str,
venv_flags_default: dict[str, bool],
) -> None:
config.config["virtualenvs"]["prefer-active-python"] = False
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]

Expand Down Expand Up @@ -987,6 +991,7 @@ def test_create_venv_tries_to_find_a_compatible_python_executable_using_specific
def test_create_venv_fails_if_no_compatible_python_version_could_be_found(
manager: EnvManager, poetry: Poetry, config: Config, mocker: MockerFixture
) -> None:
config.config["virtualenvs"]["prefer-active-python"] = False
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]

Expand Down Expand Up @@ -1016,6 +1021,7 @@ def test_create_venv_fails_if_no_compatible_python_version_could_be_found(
def test_create_venv_does_not_try_to_find_compatible_versions_with_executable(
manager: EnvManager, poetry: Poetry, config: Config, mocker: MockerFixture
) -> None:
config.config["virtualenvs"]["prefer-active-python"] = False
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]

Expand Down Expand Up @@ -1048,6 +1054,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
venv_name: str,
venv_flags_default: dict[str, bool],
) -> None:
config.config["virtualenvs"]["prefer-active-python"] = False
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]

Expand Down Expand Up @@ -1151,6 +1158,7 @@ def test_create_venv_project_name_empty_sets_correct_prompt(
mocker: MockerFixture,
config_virtualenvs_path: Path,
) -> None:
config.config["virtualenvs"]["prefer-active-python"] = False
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]

Expand Down

0 comments on commit d600f6d

Please sign in to comment.