1
0
Fork 0
mirror of https://github.com/python-poetry/install.python-poetry.org.git synced 2024-11-21 13:41:04 -05:00

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.
This commit is contained in:
s0600204 2021-12-26 20:43:40 +00:00 committed by Bjorn Neergaard
parent 09509fbe05
commit 110f89092a

View file

@ -22,6 +22,7 @@ import shutil
import site
import subprocess
import sys
import sysconfig
import tempfile
from contextlib import closing
@ -36,6 +37,7 @@ from urllib.request import urlopen
SHELL = os.getenv("SHELL", "")
WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt")
MINGW = sysconfig.get_platform().startswith("mingw")
MACOS = sys.platform == "darwin"
FOREGROUND_COLORS = {
@ -158,7 +160,7 @@ def bin_dir(version: Optional[str] = None) -> Path:
user_base = site.getuserbase()
if WINDOWS:
if WINDOWS and not MINGW:
bin_dir = os.path.join(user_base, "Scripts")
else:
bin_dir = os.path.join(user_base, "bin")
@ -273,15 +275,20 @@ class PoetryInstallationError(RuntimeError):
class VirtualEnvironment:
def __init__(self, path: Path) -> None:
self._path = path
self._bin_path = self._path.joinpath("Scripts" if WINDOWS and not MINGW else "bin")
# str is required for compatibility with subprocess run on CPython <= 3.7 on Windows
self._python = str(
self._path.joinpath("Scripts/python.exe" if WINDOWS else "bin/python")
self._path.joinpath(self._bin_path, "python.exe" if WINDOWS else "python")
)
@property
def path(self):
return self._path
@property
def bin_path(self):
return self._bin_path
@classmethod
def make(cls, target: Path) -> "VirtualEnvironment":
try:
@ -602,12 +609,8 @@ class Installer:
self._install_comment(version, "Creating script")
self._bin_dir.mkdir(parents=True, exist_ok=True)
script = "poetry"
script_bin = "bin"
if WINDOWS:
script = "poetry.exe"
script_bin = "Scripts"
target_script = env.path.joinpath(script_bin, script)
script = "poetry.exe" if WINDOWS else "poetry"
target_script = env.bin_path.joinpath(script)
if self._bin_dir.joinpath(script).exists():
self._bin_dir.joinpath(script).unlink()