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

Added pyupgrade check and upgraded script code (#16)

This commit is contained in:
Bartosz Sokorski 2022-09-07 08:56:46 +02:00 committed by GitHub
parent ae8a9ad9a8
commit 9b64f71d73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 12 deletions

View file

@ -26,3 +26,9 @@ repos:
args: args:
- --autofix - --autofix
- id: check-json - id: check-json
- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
hooks:
- id: pyupgrade
args: [--py36-plus]

View file

@ -134,7 +134,7 @@ def colorize(style, text):
if not is_decorated(): if not is_decorated():
return text return text
return "{}{}\033[0m".format(STYLES[style], text) return f"{STYLES[style]}{text}\033[0m"
def string_to_bool(value): def string_to_bool(value):
@ -267,7 +267,7 @@ POST_MESSAGE_CONFIGURE_WINDOWS = """"""
class PoetryInstallationError(RuntimeError): class PoetryInstallationError(RuntimeError):
def __init__(self, return_code: int = 0, log: Optional[str] = None): def __init__(self, return_code: int = 0, log: Optional[str] = None):
super(PoetryInstallationError, self).__init__() super().__init__()
self.return_code = return_code self.return_code = return_code
self.log = log self.log = log
@ -367,32 +367,32 @@ class Cursor:
self._output = sys.stdout self._output = sys.stdout
def move_up(self, lines: int = 1) -> "Cursor": def move_up(self, lines: int = 1) -> "Cursor":
self._output.write("\x1b[{}A".format(lines)) self._output.write(f"\x1b[{lines}A")
return self return self
def move_down(self, lines: int = 1) -> "Cursor": def move_down(self, lines: int = 1) -> "Cursor":
self._output.write("\x1b[{}B".format(lines)) self._output.write(f"\x1b[{lines}B")
return self return self
def move_right(self, columns: int = 1) -> "Cursor": def move_right(self, columns: int = 1) -> "Cursor":
self._output.write("\x1b[{}C".format(columns)) self._output.write(f"\x1b[{columns}C")
return self return self
def move_left(self, columns: int = 1) -> "Cursor": def move_left(self, columns: int = 1) -> "Cursor":
self._output.write("\x1b[{}D".format(columns)) self._output.write(f"\x1b[{columns}D")
return self return self
def move_to_column(self, column: int) -> "Cursor": def move_to_column(self, column: int) -> "Cursor":
self._output.write("\x1b[{}G".format(column)) self._output.write(f"\x1b[{column}G")
return self return self
def move_to_position(self, column: int, row: int) -> "Cursor": def move_to_position(self, column: int, row: int) -> "Cursor":
self._output.write("\x1b[{};{}H".format(row + 1, column)) self._output.write(f"\x1b[{row + 1};{column}H")
return self return self
@ -789,7 +789,7 @@ class Installer:
) )
if self._version and self._version not in releases: if self._version and self._version not in releases:
msg = "Version {} does not exist.".format(self._version) msg = f"Version {self._version} does not exist."
self._write(colorize("error", msg)) self._write(colorize("error", msg))
raise ValueError(msg) raise ValueError(msg)
@ -807,9 +807,7 @@ class Installer:
if current_version == version and not self._force: if current_version == version and not self._force:
self._write( self._write(
"The latest version ({}) is already installed.".format( f'The latest version ({colorize("b", version)}) is already installed.'
colorize("b", version)
)
) )
return None, current_version return None, current_version
@ -835,6 +833,13 @@ class Installer:
def main(): def main():
if sys.version_info < (3, 6):
sys.stdout.write(
colorize("error", "Poetry installer requires Python 3.6 or newer to run!")
)
# return error code
return 1
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Installs the latest (or given) version of poetry" description="Installs the latest (or given) version of poetry"
) )