|
| 1 | +import asyncio |
1 | 2 | import shutil |
2 | 3 | import subprocess |
3 | 4 | from datetime import datetime |
@@ -149,28 +150,37 @@ def compose(self) -> ComposeResult: |
149 | 150 | id="banner", |
150 | 151 | ) |
151 | 152 | yield banner |
152 | | - yield Label("Finding .venv directories...") |
| 153 | + yield Label("Searching for virtual environments...") |
153 | 154 | yield DataTable() |
154 | 155 | yield Footer() |
155 | 156 |
|
156 | | - def on_mount(self) -> None: |
| 157 | + async def on_mount(self) -> None: |
157 | 158 | self.title = """KillPy""" |
| 159 | + await self.find_venvs() |
158 | 160 |
|
| 161 | + async def find_venvs(self): |
159 | 162 | current_directory = Path.cwd() |
160 | 163 |
|
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] |
164 | 170 | venvs = remove_duplicates(venvs) |
| 171 | + |
165 | 172 | table = self.query_one(DataTable) |
166 | 173 | table.focus() |
167 | 174 | table.add_columns( |
168 | 175 | "Path", "Type", "Last Modified", "Size", "Size (Human Readable)" |
169 | 176 | ) |
| 177 | + |
170 | 178 | for venv in venvs: |
171 | 179 | table.add_row(*venv) |
| 180 | + |
172 | 181 | table.cursor_type = "row" |
173 | 182 | table.zebra_stripes = True |
| 183 | + |
174 | 184 | self.query_one(Label).update(f"Found {len(venvs)} .venv directories") |
175 | 185 |
|
176 | 186 | def on_key(self, event): |
|
0 commit comments