Commit 607e70fc by Frost Ming Committed by GitHub

list .venv when it exists (#1762)

* list .venv when it exists

* only list when in-project is true

* missing config

* move logic to manager.list

* Add .venv when it exists
parent 9306cd25
......@@ -372,11 +372,20 @@ class EnvManager(object):
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:
......
import os
import tomlkit
from cleo.testers import CommandTester
......@@ -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()
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