diff --git a/docs/configuration.md b/docs/configuration.md index f5ae70cc6b8..ab6ae5d9e61 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -423,10 +423,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. diff --git a/src/poetry/config/config.py b/src/poetry/config/config.py index 74182a358fd..070bc13e6eb 100644 --- a/src/poetry/config/config.py +++ b/src/poetry/config/config.py @@ -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}", }, "requests": { diff --git a/tests/console/commands/test_config.py b/tests/console/commands/test_config.py index 095c6ab7a29..a509a343c67 100644 --- a/tests/console/commands/test_config.py +++ b/tests/console/commands/test_config.py @@ -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}}" """ @@ -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}}" """ @@ -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] @@ -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] @@ -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}}" """ @@ -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}}" """ diff --git a/tests/utils/env/test_env_manager.py b/tests/utils/env/test_env_manager.py index e607e239bd5..72a1ae111ba 100644 --- a/tests/utils/env/test_env_manager.py +++ b/tests/utils/env/test_env_manager.py @@ -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"] @@ -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"] @@ -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"] @@ -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"] @@ -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"] @@ -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"] @@ -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"] @@ -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"]