|
22 | 22 | import site |
23 | 23 | import subprocess |
24 | 24 | import sys |
| 25 | +import sysconfig |
25 | 26 | import tempfile |
26 | 27 |
|
27 | 28 | from contextlib import closing |
|
36 | 37 |
|
37 | 38 | SHELL = os.getenv("SHELL", "") |
38 | 39 | WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt") |
| 40 | +MINGW = sysconfig.get_platform().startswith("mingw") |
39 | 41 | MACOS = sys.platform == "darwin" |
40 | 42 |
|
41 | 43 | FOREGROUND_COLORS = { |
@@ -158,7 +160,7 @@ def bin_dir(version: Optional[str] = None) -> Path: |
158 | 160 |
|
159 | 161 | user_base = site.getuserbase() |
160 | 162 |
|
161 | | - if WINDOWS: |
| 163 | + if WINDOWS and not MINGW: |
162 | 164 | bin_dir = os.path.join(user_base, "Scripts") |
163 | 165 | else: |
164 | 166 | bin_dir = os.path.join(user_base, "bin") |
@@ -273,15 +275,20 @@ def __init__(self, return_code: int = 0, log: Optional[str] = None): |
273 | 275 | class VirtualEnvironment: |
274 | 276 | def __init__(self, path: Path) -> None: |
275 | 277 | self._path = path |
| 278 | + self._bin_path = self._path.joinpath("Scripts" if WINDOWS and not MINGW else "bin") |
276 | 279 | # str is required for compatibility with subprocess run on CPython <= 3.7 on Windows |
277 | 280 | 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") |
279 | 282 | ) |
280 | 283 |
|
281 | 284 | @property |
282 | 285 | def path(self): |
283 | 286 | return self._path |
284 | 287 |
|
| 288 | + @property |
| 289 | + def bin_path(self): |
| 290 | + return self._bin_path |
| 291 | + |
285 | 292 | @classmethod |
286 | 293 | def make(cls, target: Path) -> "VirtualEnvironment": |
287 | 294 | try: |
@@ -602,12 +609,8 @@ def make_bin(self, version: str, env: VirtualEnvironment) -> None: |
602 | 609 | self._install_comment(version, "Creating script") |
603 | 610 | self._bin_dir.mkdir(parents=True, exist_ok=True) |
604 | 611 |
|
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) |
611 | 614 |
|
612 | 615 | if self._bin_dir.joinpath(script).exists(): |
613 | 616 | self._bin_dir.joinpath(script).unlink() |
|
0 commit comments