Commit d699b24b by Andrea Ghensi Committed by GitHub

Add --executable option to env info command (#7547)

parent 152f01e4
...@@ -39,6 +39,7 @@ pyenv install 3.9.8 ...@@ -39,6 +39,7 @@ pyenv install 3.9.8
pyenv local 3.9.8 # Activate Python 3.9 for the current project pyenv local 3.9.8 # Activate Python 3.9 for the current project
poetry install poetry install
``` ```
{{% /note %}} {{% /note %}}
{{% note %}} {{% note %}}
...@@ -106,6 +107,13 @@ to `env info`: ...@@ -106,6 +107,13 @@ to `env info`:
poetry env info --path poetry env info --path
``` ```
If you only want to know the path to the python executable (useful for running mypy from a global environment without installing it in the virtual environment), you can pass the `--executable` option
to `env info`:
```bash
poetry env info --executable
```
## Listing the environments associated with the project ## Listing the environments associated with the project
You can also list all the virtual environments associated with the current project You can also list all the virtual environments associated with the current project
...@@ -140,10 +148,13 @@ poetry env remove test-O3eWbxRl-py3.7 ...@@ -140,10 +148,13 @@ poetry env remove test-O3eWbxRl-py3.7
``` ```
You can delete more than one environment at a time. You can delete more than one environment at a time.
```bash ```bash
poetry env remove python3.6 python3.7 python3.8 poetry env remove python3.6 python3.7 python3.8
``` ```
Use the `--all` option to delete all virtual environments at once. Use the `--all` option to delete all virtual environments at once.
```bash ```bash
poetry env remove --all poetry env remove --all
``` ```
......
...@@ -15,7 +15,12 @@ class EnvInfoCommand(Command): ...@@ -15,7 +15,12 @@ class EnvInfoCommand(Command):
name = "env info" name = "env info"
description = "Displays information about the current environment." description = "Displays information about the current environment."
options = [option("path", "p", "Only display the environment's path.")] options = [
option("path", "p", "Only display the environment's path."),
option(
"executable", "e", "Only display the environment's python executable path."
),
]
def handle(self) -> int: def handle(self) -> int:
from poetry.utils.env import EnvManager from poetry.utils.env import EnvManager
...@@ -30,6 +35,14 @@ class EnvInfoCommand(Command): ...@@ -30,6 +35,14 @@ class EnvInfoCommand(Command):
return 0 return 0
if self.option("executable"):
if not env.is_venv():
return 1
self.line(str(env.python))
return 0
self._display_complete_info(env) self._display_complete_info(env)
return 0 return 0
......
...@@ -58,3 +58,9 @@ def test_env_info_displays_path_only(tester: CommandTester): ...@@ -58,3 +58,9 @@ def test_env_info_displays_path_only(tester: CommandTester):
tester.execute("--path") tester.execute("--path")
expected = str(Path("/prefix")) + "\n" expected = str(Path("/prefix")) + "\n"
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
def test_env_info_displays_executable_only(tester: CommandTester):
tester.execute("--executable")
expected = str(sys.executable) + "\n"
assert tester.io.fetch_output() == expected
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment