Skip to content

Commit 91548dc

Browse files
committed
feat: implement asynchronous searching for virtual environments close #2
1 parent bde535f commit 91548dc

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

killpy/__main__.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import shutil
23
import subprocess
34
from datetime import datetime
@@ -149,28 +150,37 @@ def compose(self) -> ComposeResult:
149150
id="banner",
150151
)
151152
yield banner
152-
yield Label("Finding .venv directories...")
153+
yield Label("Searching for virtual environments...")
153154
yield DataTable()
154155
yield Footer()
155156

156-
def on_mount(self) -> None:
157+
async def on_mount(self) -> None:
157158
self.title = """KillPy"""
159+
await self.find_venvs()
158160

161+
async def find_venvs(self):
159162
current_directory = Path.cwd()
160163

161-
venvs = find_venvs(current_directory)
162-
venvs += list_conda_environments()
163-
venvs += find_venvs_with_pyvenv(current_directory)
164+
venvs = await asyncio.gather(
165+
asyncio.to_thread(find_venvs, current_directory),
166+
asyncio.to_thread(list_conda_environments),
167+
asyncio.to_thread(find_venvs_with_pyvenv, current_directory),
168+
)
169+
venvs = [env for sublist in venvs for env in sublist]
164170
venvs = remove_duplicates(venvs)
171+
165172
table = self.query_one(DataTable)
166173
table.focus()
167174
table.add_columns(
168175
"Path", "Type", "Last Modified", "Size", "Size (Human Readable)"
169176
)
177+
170178
for venv in venvs:
171179
table.add_row(*venv)
180+
172181
table.cursor_type = "row"
173182
table.zebra_stripes = True
183+
174184
self.query_one(Label).update(f"Found {len(venvs)} .venv directories")
175185

176186
def on_key(self, event):

0 commit comments

Comments
 (0)