1
0
Fork 0
mirror of https://github.com/python-poetry/install.python-poetry.org.git synced 2024-09-17 23:27:11 -04:00

chore: migrate to ruff (#113)

This commit is contained in:
Branch Vincent 2023-05-14 11:47:14 -07:00 committed by GitHub
parent 649e855f81
commit fcd759d6fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 58 deletions

View file

@ -1,3 +0,0 @@
[flake8]
max-line-length = 88
ignore = E501, E203, W503

View file

@ -4,18 +4,6 @@ repos:
hooks: hooks:
- id: black - id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==22.7.1
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0 rev: v4.4.0
hooks: hooks:
@ -23,12 +11,10 @@ repos:
- id: end-of-file-fixer - id: end-of-file-fixer
- id: debug-statements - id: debug-statements
- id: pretty-format-json - id: pretty-format-json
args: args: [--autofix]
- --autofix
- id: check-json - id: check-json
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v3.4.0 rev: v0.0.267
hooks: hooks:
- id: pyupgrade - id: ruff
args: [--py36-plus]

View file

@ -22,7 +22,15 @@ installs, or use of pipx as alternatives to executing arbitrary, unversioned cod
script to alternatives, consider maintaining a local copy as part of your infrastructure. script to alternatives, consider maintaining a local copy as part of your infrastructure.
For full documentation, visit https://python-poetry.org/docs/#installation. For full documentation, visit https://python-poetry.org/docs/#installation.
""" """ # noqa: E501
import sys
# Eager version check so we fail nicely before possible syntax errors
if sys.version_info < (3, 6): # noqa: UP036
sys.stdout.write("Poetry installer requires Python 3.6 or newer to run!\n")
sys.exit(1)
import argparse import argparse
import json import json
@ -30,7 +38,6 @@ import os
import re import re
import shutil import shutil
import subprocess import subprocess
import sys
import sysconfig import sysconfig
import tempfile import tempfile
@ -107,8 +114,8 @@ def is_decorated():
if WINDOWS: if WINDOWS:
return ( return (
os.getenv("ANSICON") is not None os.getenv("ANSICON") is not None
or "ON" == os.getenv("ConEmuANSI") or os.getenv("ConEmuANSI") == "ON" # noqa: SIM112
or "xterm" == os.getenv("Term") or os.getenv("Term") == "xterm" # noqa: SIM112
) )
if not hasattr(sys.stdout, "fileno"): if not hasattr(sys.stdout, "fileno"):
@ -278,7 +285,7 @@ class VirtualEnvironment:
self._bin_path = self._path.joinpath( self._bin_path = self._path.joinpath(
"Scripts" if WINDOWS and not MINGW else "bin" "Scripts" if WINDOWS and not MINGW else "bin"
) )
# str is required for compatibility with subprocess run on CPython <= 3.7 on Windows # str is for compatibility with subprocess.run on CPython <= 3.7 on Windows
self._python = str( self._python = str(
self._path.joinpath(self._bin_path, "python.exe" if WINDOWS else "python") self._path.joinpath(self._bin_path, "python.exe" if WINDOWS else "python")
) )
@ -295,7 +302,8 @@ class VirtualEnvironment:
def make(cls, target: Path) -> "VirtualEnvironment": def make(cls, target: Path) -> "VirtualEnvironment":
if not sys.executable: if not sys.executable:
raise ValueError( raise ValueError(
"Unable to determine sys.executable. Set PATH to a sane value or set it explicitly with PYTHONEXECUTABLE." "Unable to determine sys.executable. Set PATH to a sane value or set it"
" explicitly with PYTHONEXECUTABLE."
) )
try: try:
@ -340,7 +348,7 @@ class VirtualEnvironment:
env = cls(target) env = cls(target)
# we do this here to ensure that outdated system default pip does not trigger older bugs # this ensures that outdated system default pip does not trigger older bugs
env.pip("install", "--disable-pip-version-check", "--upgrade", "pip") env.pip("install", "--disable-pip-version-check", "--upgrade", "pip")
return env return env
@ -527,18 +535,20 @@ class Installer:
mx = self.VERSION_REGEX.match(x) mx = self.VERSION_REGEX.match(x)
if mx is None: 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 return True
vx = tuple(int(p) for p in mx.groups()[:3]) + (mx.group(5),) vx = (*tuple(int(p) for p in mx.groups()[:3]), mx.group(5))
return vx >= (1, 1, 7) return vx >= (1, 1, 7)
if version and not _is_self_upgrade_supported(version): if version and not _is_self_upgrade_supported(version):
self._write( self._write(
colorize( colorize(
"warning", "warning",
f"You are installing {version}. When using the current installer, this version does not support " f"You are installing {version}. When using the current installer, "
f"updating using the 'self update' command. Please use 1.1.7 or later.", "this version does not support updating using the 'self update' "
"command. Please use 1.1.7 or later.",
) )
) )
if not self._accept_all: if not self._accept_all:
@ -551,7 +561,7 @@ class Installer:
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
raise PoetryInstallationError( raise PoetryInstallationError(
return_code=e.returncode, log=e.output.decode() return_code=e.returncode, log=e.output.decode()
) ) from e
self._write("") self._write("")
self.display_post_message(version) self.display_post_message(version)
@ -713,11 +723,12 @@ class Installer:
def get_windows_path_var(self) -> Optional[str]: def get_windows_path_var(self) -> Optional[str]:
import winreg import winreg
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root: with winreg.ConnectRegistry(
with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key: None, winreg.HKEY_CURRENT_USER
path, _ = winreg.QueryValueEx(key, "PATH") ) as root, winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
path, _ = winreg.QueryValueEx(key, "PATH")
return path return path
def display_post_message_fish(self, version: str) -> None: def display_post_message_fish(self, version: str) -> None:
fish_user_paths = subprocess.check_output( fish_user_paths = subprocess.check_output(
@ -778,8 +789,8 @@ class Installer:
mx = self.VERSION_REGEX.match(x) mx = self.VERSION_REGEX.match(x)
my = self.VERSION_REGEX.match(y) my = self.VERSION_REGEX.match(y)
vx = tuple(int(p) for p in mx.groups()[:3]) + (mx.group(5),) vx = (*tuple(int(p) for p in mx.groups()[:3]), mx.group(5))
vy = tuple(int(p) for p in my.groups()[:3]) + (my.group(5),) vy = (*tuple(int(p) for p in my.groups()[:3]), my.group(5))
if vx < vy: if vx < vy:
return -1 return -1
@ -838,13 +849,6 @@ 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"
) )
@ -930,7 +934,8 @@ def main():
text=True, text=True,
) )
installer._write(colorize("error", f"See {path} for error logs.")) installer._write(colorize("error", f"See {path} for error logs."))
text = f"{e.log}\nTraceback:\n\n{''.join(traceback.format_tb(e.__traceback__))}" tb = "".join(traceback.format_tb(e.__traceback__))
text = f"{e.log}\nTraceback:\n\n{tb}"
Path(path).write_text(text) Path(path).write_text(text)
return e.return_code return e.return_code

View file

@ -1,12 +1,29 @@
[tool.isort] [tool.ruff]
profile = "black" fix = true
force_single_line = true unfixable = [
atomic = true "ERA", # do not autoremove commented out code
lines_after_imports = 2 ]
lines_between_types = 1 target-version = "py37"
filter_files = true
[tool.black]
line-length = 88 line-length = 88
include = '\.pyi?$' extend-select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"ERA", # flake8-eradicate/eradicate
"I", # isort
"N", # pep8-naming
"PIE", # flake8-pie
"PGH", # pygrep
"RUF", # ruff checks
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"UP", # pyupgrade
]
[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"
[tool.ruff.isort]
force-single-line = true
lines-between-types = 1
lines-after-imports = 2