Skip to content

Commit

Permalink
Add --executable option to env info command (#7547)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanzoghenzo authored Apr 17, 2023
1 parent 152f01e commit d699b24
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/managing-environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pyenv install 3.9.8
pyenv local 3.9.8 # Activate Python 3.9 for the current project
poetry install
```

{{% /note %}}

{{% note %}}
Expand Down Expand Up @@ -106,6 +107,13 @@ to `env info`:
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

You can also list all the virtual environments associated with the current project
Expand Down Expand Up @@ -140,10 +148,13 @@ poetry env remove test-O3eWbxRl-py3.7
```

You can delete more than one environment at a time.

```bash
poetry env remove python3.6 python3.7 python3.8
```

Use the `--all` option to delete all virtual environments at once.

```bash
poetry env remove --all
```
Expand Down
15 changes: 14 additions & 1 deletion src/poetry/console/commands/env/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class EnvInfoCommand(Command):
name = "env info"
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:
from poetry.utils.env import EnvManager
Expand All @@ -30,6 +35,14 @@ def handle(self) -> int:

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)
return 0

Expand Down
6 changes: 6 additions & 0 deletions tests/console/commands/env/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ def test_env_info_displays_path_only(tester: CommandTester):
tester.execute("--path")
expected = str(Path("/prefix")) + "\n"
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

0 comments on commit d699b24

Please sign in to comment.