Skip to content

Commit

Permalink
add option virtualenvs.prefer-shell-python
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Nov 30, 2021
1 parent fd6cea8 commit 848af21
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -138,6 +139,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",
}:
Expand Down
30 changes: 15 additions & 15 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,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(
Expand Down
5 changes: 5 additions & 0 deletions src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions tests/console/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_list_displays_default_value_if_not_set(
virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-shell-python = false
"""

assert expected == tester.io.fetch_output()
Expand All @@ -79,6 +80,7 @@ def test_list_displays_set_get_setting(
virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-shell-python = false
"""

assert config.set_config_source.call_count == 0
Expand Down Expand Up @@ -126,6 +128,7 @@ def test_list_displays_set_get_local_setting(
virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-shell-python = false
"""

assert config.set_config_source.call_count == 1
Expand Down

0 comments on commit 848af21

Please sign in to comment.