diff --git a/src/poetry/config/config.py b/src/poetry/config/config.py index 720e479f48f..041e81ba4c8 100644 --- a/src/poetry/config/config.py +++ b/src/poetry/config/config.py @@ -38,6 +38,7 @@ class Config: "in-project": None, "path": os.path.join("{cache-dir}", "virtualenvs"), "options": {"always-copy": False, "system-site-packages": False}, + "prefer-shell-python": False, }, "experimental": {"new-installer": True}, "installer": {"parallel": True, "max-workers": None}, @@ -140,6 +141,7 @@ def _get_normalizer(name: str) -> Callable: "virtualenvs.in-project", "virtualenvs.options.always-copy", "virtualenvs.options.system-site-packages", + "virtualenvs.options.prefer-shell-python", "experimental.new-installer", "installer.parallel", }: diff --git a/src/poetry/console/application.py b/src/poetry/console/application.py index 6d398910909..b5b30b58a23 100644 --- a/src/poetry/console/application.py +++ b/src/poetry/console/application.py @@ -294,21 +294,21 @@ def configure_env( executable = None find_compatible = None - # add on option to trigger this - with contextlib.suppress(CalledProcessError): - executable = decode( - subprocess.check_output( - list_to_shell_command( - [ - "python", - "-c", - '"import sys; print(sys.executable)"', - ] - ), - shell=True, - ).strip() - ) - find_compatible = True + if poetry.config.get("virtualenvs").get("prefer-shell-python"): + with contextlib.suppress(CalledProcessError): + executable = decode( + subprocess.check_output( + list_to_shell_command( + [ + "python", + "-c", + '"import sys; print(sys.executable)"', + ] + ), + shell=True, + ).strip() + ) + find_compatible = True env_manager = EnvManager(poetry) env = env_manager.create_venv( diff --git a/src/poetry/console/commands/config.py b/src/poetry/console/commands/config.py index eba22e636b2..9b0ddf7ac63 100644 --- a/src/poetry/console/commands/config.py +++ b/src/poetry/console/commands/config.py @@ -78,6 +78,11 @@ def unique_config_values(self) -> Dict[str, Tuple[Any, Any, Any]]: lambda val: str(Path(val)), str(Path(CACHE_DIR) / "virtualenvs"), ), + "virtualenvs.prefer-shell-python": ( + boolean_validator, + boolean_normalizer, + False, + ), "experimental.new-installer": ( boolean_validator, boolean_normalizer, diff --git a/tests/console/commands/test_config.py b/tests/console/commands/test_config.py index b136ca29c73..87e6889785e 100644 --- a/tests/console/commands/test_config.py +++ b/tests/console/commands/test_config.py @@ -54,6 +54,7 @@ def test_list_displays_default_value_if_not_set( virtualenvs.options.always-copy = false virtualenvs.options.system-site-packages = false virtualenvs.path = {path} # {virtualenvs} +virtualenvs.prefer-shell-python = false """.format( cache=json.dumps(str(config_cache_dir)), path=json.dumps(os.path.join("{cache-dir}", "virtualenvs")), @@ -79,6 +80,7 @@ def test_list_displays_set_get_setting( virtualenvs.options.always-copy = false virtualenvs.options.system-site-packages = false virtualenvs.path = {path} # {virtualenvs} +virtualenvs.prefer-shell-python = false """.format( cache=json.dumps(str(config_cache_dir)), path=json.dumps(os.path.join("{cache-dir}", "virtualenvs")), @@ -128,6 +130,7 @@ def test_list_displays_set_get_local_setting( virtualenvs.options.always-copy = false virtualenvs.options.system-site-packages = false virtualenvs.path = {path} # {virtualenvs} +virtualenvs.prefer-shell-python = false """.format( cache=json.dumps(str(config_cache_dir)), path=json.dumps(os.path.join("{cache-dir}", "virtualenvs")),