|
--- /dev/fd/63 2022-02-25 17:10:16.000000000 -0500 |
|
+++ /dev/fd/62 2022-02-25 17:10:16.000000000 -0500 |
|
@@ -22,6 +22,7 @@ |
|
import site |
|
import subprocess |
|
import sys |
|
+import sysconfig |
|
import tempfile |
|
|
|
from contextlib import closing |
|
@@ -36,6 +37,7 @@ |
|
|
|
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 = { |
|
@@ -96,8 +98,8 @@ |
|
if WINDOWS: |
|
return ( |
|
os.getenv("ANSICON") is not None |
|
- or os.getenv("ConEmuANSI") == "ON" |
|
- or os.getenv("Term") == "xterm" |
|
+ or "ON" == os.getenv("ConEmuANSI") |
|
+ or "xterm" == os.getenv("Term") |
|
) |
|
|
|
if not hasattr(sys.stdout, "fileno"): |
|
@@ -158,7 +160,7 @@ |
|
|
|
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,16 +275,22 @@ |
|
class VirtualEnvironment: |
|
def __init__(self, path: Path) -> None: |
|
self._path = path |
|
- # str is required for compatibility with subprocess run on CPython <= 3.7 on |
|
- # Windows |
|
+ 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: |
|
@@ -314,8 +322,7 @@ |
|
|
|
env = cls(target) |
|
|
|
- # we do this here to ensure that outdated system default pip does not trigger |
|
- # older bugs |
|
+ # we do this here to ensure that outdated system default pip does not trigger older bugs |
|
env.pip("install", "--disable-pip-version-check", "--upgrade", "pip") |
|
|
|
return env |
|
@@ -470,7 +477,10 @@ |
|
elif self._path: |
|
version = self._path |
|
else: |
|
- version, current_version = self.get_version() |
|
+ try: |
|
+ version, current_version = self.get_version() |
|
+ except ValueError: |
|
+ return 1 |
|
|
|
if version is None: |
|
return 0 |
|
@@ -482,8 +492,7 @@ |
|
mx = self.VERSION_REGEX.match(x) |
|
|
|
if mx is None: |
|
- # the version is not semver, perhaps scm or file, we assume upgrade is |
|
- # supported |
|
+ # the version is not semver, perhaps scm or file, we assume upgrade is supported |
|
return True |
|
|
|
vx = tuple(int(p) for p in mx.groups()[:3]) + (mx.group(5),) |
|
@@ -493,9 +502,8 @@ |
|
self._write( |
|
colorize( |
|
"warning", |
|
- f"You are installing {version}. When using the current installer," |
|
- " this version does not support updating using the 'self update'" |
|
- " command. Please use 1.1.7 or later.", |
|
+ f"You are installing {version}. When using the current installer, this version does not support " |
|
+ f"updating using the 'self update' command. Please use 1.1.7 or later.", |
|
) |
|
) |
|
if not self._accept_all: |
|
@@ -606,12 +614,8 @@ |
|
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() |
|
@@ -755,11 +759,10 @@ |
|
) |
|
|
|
if self._version and self._version not in releases: |
|
- self._write( |
|
- colorize("error", "Version {} does not exist.".format(self._version)) |
|
- ) |
|
+ msg = "Version {} does not exist.".format(self._version) |
|
+ self._write(colorize("error", msg)) |
|
|
|
- return None, None |
|
+ raise ValueError(msg) |
|
|
|
version = self._version |
|
if not version: |
|
@@ -887,22 +890,11 @@ |
|
text=True, |
|
) |
|
installer._write(colorize("error", f"See {path} for error logs.")) |
|
- text = ( |
|
- f"{e.log}\n" |
|
- f"Traceback:\n\n{''.join(traceback.format_tb(e.__traceback__))}" |
|
- ) |
|
+ text = f"{e.log}\nTraceback:\n\n{''.join(traceback.format_tb(e.__traceback__))}" |
|
Path(path).write_text(text) |
|
|
|
return e.return_code |
|
|
|
|
|
if __name__ == "__main__": |
|
- sys.stdout.write( |
|
- colorize( |
|
- "warning", |
|
- "The canonical source for Poetry's installation script is now" |
|
- " https://install.python-poetry.org. Please update your usage to reflect" |
|
- " this.\n", |
|
- ) |
|
- ) |
|
sys.exit(main()) |