Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list .venv when it exists #1762

Merged
merged 5 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,20 @@ def list(self, name=None): # type: (Optional[str]) -> List[VirtualEnv]
else:
venv_path = Path(venv_path)

return [
env_list = [
VirtualEnv(Path(p))
for p in sorted(venv_path.glob("{}-py*".format(venv_name)))
]

venv = self._poetry.file.parent / ".venv"
if (
self._poetry.config.get("virtualenvs.in-project")
and venv.exists()
and venv.is_dir()
):
env_list.insert(0, VirtualEnv(venv))
return env_list

def remove(self, python): # type: (str) -> Env
venv_path = self._poetry.config.get("virtualenvs.path")
if venv_path is None:
Expand Down
18 changes: 18 additions & 0 deletions tests/console/commands/env/test_list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import tomlkit

from cleo.testers import CommandTester
Expand Down Expand Up @@ -56,3 +58,19 @@ def test_activated(app, tmp_dir):
)

assert expected == tester.io.fetch_output()


def test_in_project_venv(app, tmpdir):
os.environ.pop("VIRTUAL_ENV", None)
app.poetry.config.merge({"virtualenvs": {"in-project": True}})

(app.poetry.file.parent / ".venv").mkdir(exist_ok=True)

command = app.find("env list")
tester = CommandTester(command)
tester.execute()

expected = ".venv (Activated)\n"

assert expected == tester.io.fetch_output()
(app.poetry.file.parent / ".venv").rmdir()