Skip to content

Commit 110f890

Browse files
s0600204neersighted
authored andcommitted
Fix installing under MinGW on Windows
python[.exe], when installed via (msys) MinGW on Windows, can be found under a path structure similar to that you might find on *nix systems. The install-python.py script was not taking this into consideration, causing installation failure under Windows + MinGW. A similar fault in poetry itself was resolved with python-poetry/poetry#3713.
1 parent 09509fb commit 110f890

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

install-poetry.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import site
2323
import subprocess
2424
import sys
25+
import sysconfig
2526
import tempfile
2627

2728
from contextlib import closing
@@ -36,6 +37,7 @@
3637

3738
SHELL = os.getenv("SHELL", "")
3839
WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt")
40+
MINGW = sysconfig.get_platform().startswith("mingw")
3941
MACOS = sys.platform == "darwin"
4042

4143
FOREGROUND_COLORS = {
@@ -158,7 +160,7 @@ def bin_dir(version: Optional[str] = None) -> Path:
158160

159161
user_base = site.getuserbase()
160162

161-
if WINDOWS:
163+
if WINDOWS and not MINGW:
162164
bin_dir = os.path.join(user_base, "Scripts")
163165
else:
164166
bin_dir = os.path.join(user_base, "bin")
@@ -273,15 +275,20 @@ def __init__(self, return_code: int = 0, log: Optional[str] = None):
273275
class VirtualEnvironment:
274276
def __init__(self, path: Path) -> None:
275277
self._path = path
278+
self._bin_path = self._path.joinpath("Scripts" if WINDOWS and not MINGW else "bin")
276279
# str is required for compatibility with subprocess run on CPython <= 3.7 on Windows
277280
self._python = str(
278-
self._path.joinpath("Scripts/python.exe" if WINDOWS else "bin/python")
281+
self._path.joinpath(self._bin_path, "python.exe" if WINDOWS else "python")
279282
)
280283

281284
@property
282285
def path(self):
283286
return self._path
284287

288+
@property
289+
def bin_path(self):
290+
return self._bin_path
291+
285292
@classmethod
286293
def make(cls, target: Path) -> "VirtualEnvironment":
287294
try:
@@ -602,12 +609,8 @@ def make_bin(self, version: str, env: VirtualEnvironment) -> None:
602609
self._install_comment(version, "Creating script")
603610
self._bin_dir.mkdir(parents=True, exist_ok=True)
604611

605-
script = "poetry"
606-
script_bin = "bin"
607-
if WINDOWS:
608-
script = "poetry.exe"
609-
script_bin = "Scripts"
610-
target_script = env.path.joinpath(script_bin, script)
612+
script = "poetry.exe" if WINDOWS else "poetry"
613+
target_script = env.bin_path.joinpath(script)
611614

612615
if self._bin_dir.joinpath(script).exists():
613616
self._bin_dir.joinpath(script).unlink()

0 commit comments

Comments
 (0)