Skip to content

Commit 3241a11

Browse files
Add code commentary to poetry venv creation.
Issue #6 raised the question why running `poetry env info --path` was needed. Since this wasn't documented before, I added a few code comments to explain. * sphinx_polyversion/pyvenv.py (Poetry) : commentary
1 parent cbd7e18 commit 3241a11

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

sphinx_polyversion/pyvenv.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ def __init__(self, path: Path, name: str, *, args: Iterable[str]):
230230
args : Iterable[str]
231231
The cmd arguments to pass to `poetry install`.
232232
"""
233-
super().__init__(path, name, path / ".venv")
233+
super().__init__(
234+
path,
235+
name,
236+
path / ".venv", # placeholder, determined later
237+
)
234238
self.args = args
235239

236240
async def __aenter__(self) -> Self:
@@ -276,7 +280,12 @@ async def __aenter__(self) -> Self:
276280
cast(int, process.returncode), " ".join(cmd), out, err
277281
)
278282

279-
# locate venv
283+
# ---- locate venv
284+
# In the previous process poetry will have created or
285+
# ensured the existence of a venv in `venv_path` path folder.
286+
# However the venv itself constitutes a subdirectory with
287+
# an arbitrary name generated by poetry.
288+
# Thus we ask poetry to give as the name of the venv folder.
280289
cmd: list[str] = ["poetry", "env", "info", "--path"]
281290
process = await asyncio.create_subprocess_exec(
282291
*cmd, cwd=self.path, env=env, stdout=PIPE, stderr=PIPE
@@ -291,7 +300,8 @@ async def __aenter__(self) -> Self:
291300
raise BuildError from CalledProcessError(
292301
cast(int, process.returncode), " ".join(cmd), out, err
293302
)
294-
self.venv = Path(out)
303+
self.venv = Path(out) # actual venv location
304+
295305
return self
296306

297307

0 commit comments

Comments
 (0)