Commit 59a38bd9 by Bjorn Neergaard

refactor: rework deprecation of get-poetry.py to include CI brownout and restructured messaging

parent b2b49927
...@@ -21,6 +21,7 @@ import hashlib ...@@ -21,6 +21,7 @@ import hashlib
import json import json
import os import os
import platform import platform
import random
import re import re
import shutil import shutil
import stat import stat
...@@ -69,6 +70,8 @@ SHELL = os.getenv("SHELL", "") ...@@ -69,6 +70,8 @@ SHELL = os.getenv("SHELL", "")
WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt") WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt")
BROWNOUT_CHANCE = 5 # percent chance to randomly fail in CI
FOREGROUND_COLORS = { FOREGROUND_COLORS = {
"black": 30, "black": 30,
"red": 31, "red": 31,
...@@ -118,6 +121,7 @@ STYLES = { ...@@ -118,6 +121,7 @@ STYLES = {
"comment": style("yellow", None, None), "comment": style("yellow", None, None),
"error": style("red", None, None), "error": style("red", None, None),
"warning": style("yellow", None, None), "warning": style("yellow", None, None),
"deprecation": style("magenta", None, None),
} }
...@@ -437,6 +441,58 @@ class Installer: ...@@ -437,6 +441,58 @@ class Installer:
return None, None return None, None
def _is_supported(x):
mx = self.VERSION_REGEX.match(x)
vx = tuple(int(p) for p in mx.groups()[:3]) + (mx.group(5),)
return vx < (1, 2, 0)
print(
colorize(
"deprecation",
"This installer is deprecated, and cannot install Poetry 1.2.0a1 or"
" newer.\nAdditionally, Poetry installations created by this installer"
" cannot `self update` to 1.2.0a1 or later.\nYou should migrate to"
" https://install.python-poetry.org instead. Instructions are available"
" at https://python-poetry.org/docs/#installation.\n",
)
)
if not os.environ.get("GET_POETRY_IGNORE_DEPRECATION"):
if os.environ.get("CI"):
print(
colorize(
"deprecation",
"A CI environment has been detected! Due to the above"
" deprecation, this installer is subject to an escalating"
" brownout percentage (currently {percent}%)!\nIf you"
" understand the above warning and wish to opt out of this"
" brownout, set GET_POETRY_IGNORE_DEPRECATION=1 in the"
" environment.\n".format(percent=BROWNOUT_CHANCE),
)
)
if random.randrange(1, 100) < BROWNOUT_CHANCE:
print(
colorize(
"error",
"This invocation of the installer has been terminated due"
" to the brownout described above. Please carefully read"
" the above notices and update your CI pipeline"
" accordingly!",
)
)
return None, None
else:
print(
colorize(
"error",
"This installer will now exit. If you understand the above"
" warning and wish to proceed anyway, set"
" GET_POETRY_IGNORE_DEPRECATION=1 in the environment and run"
" this installer again.",
)
)
return None, None
version = self._version version = self._version
if not version: if not version:
for release in reversed(releases): for release in reversed(releases):
...@@ -444,38 +500,41 @@ class Installer: ...@@ -444,38 +500,41 @@ class Installer:
if m.group(5) and not self.allows_prereleases(): if m.group(5) and not self.allows_prereleases():
continue continue
if _is_supported(release):
version = release version = release
break
def _is_supported(x):
mx = self.VERSION_REGEX.match(x)
vx = tuple(int(p) for p in mx.groups()[:3]) + (mx.group(5),)
return vx < (1, 2, 0)
if not _is_supported(version):
print( print(
colorize( colorize(
"error", "warning",
"Version {version} does not support this installation method." "Version {version} will be installed as it is the latest"
" Please specify a version prior to 1.2.0a1 explicitly using the" " version supported by this installer.\nThis is not the"
" '--version' option.\nPlease see" " latest version of Poetry! If you wish to install the"
" https://python-poetry.org/blog/announcing-poetry-1-2-0a1.html#deprecation-of-the-get-poetry-py-script" " latest version, please migrate to the new installer as"
" for more information.".format(version=version), " described above!\n".format(version=release),
) )
) )
return None, None
break
else:
print( print(
colorize( colorize(
"warning", "warning",
"This installer is deprecated. Poetry versions installed using this" "Version {version} is available but is not supported by"
" script will not be able to use 'self update' command to upgrade to" " this installer!".format(version=release),
" 1.2.0a1 or later. It is recommended to use" )
" https://install.python-poetry.org instead. Instructions are" )
" available at https://python-poetry.org/docs/#installation",
if not _is_supported(version):
print(
colorize(
"error",
"Version {version} is not supported by this installer! Please"
" specify a version prior to 1.2.0a1 to continue!".format(
version=version
),
) )
) )
return None, None
current_version = None current_version = None
if os.path.exists(POETRY_LIB): if os.path.exists(POETRY_LIB):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment