Skip to content

Commit

Permalink
list .venv when it exists (#1762)
Browse files Browse the repository at this point in the history
* list .venv when it exists

* only list when in-project is true

* missing config

* move logic to manager.list

* Add .venv when it exists
  • Loading branch information
Frost Ming committed Feb 28, 2020
1 parent 9306cd2 commit 607e70f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,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 @@ -58,3 +60,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()

0 comments on commit 607e70f

Please sign in to comment.