From 8d7e55eccae7a9bf8a4a88918068bc6971af65c5 Mon Sep 17 00:00:00 2001 From: ArchGuy Date: Mon, 13 Nov 2023 19:38:15 +0800 Subject: [PATCH] Fix poetry shell on Windows when using Python installed from POSIX-like emulators(#8644) --- src/poetry/utils/shell.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index f8c413afd81..6e7301fc5e0 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -70,7 +70,13 @@ def get(cls) -> Shell: def activate(self, env: VirtualEnv) -> int | None: activate_script = self._get_activate_script() - bin_dir = "Scripts" if WINDOWS else "bin" + if WINDOWS: + bin_path = env.path / "Scripts" + # Python innstalled via msys2 on Windows might produce a POSIX-like venv + # See https://github.com/python-poetry/poetry/issues/8638 + bin_dir = "Scripts" if bin_path.exists() else "bin" + else: + bin_dir = "bin" activate_path = env.path / bin_dir / activate_script # mypy requires using sys.platform instead of WINDOWS constant