Skip to content

Commit fcd759d

Browse files
authored
chore: migrate to ruff (#113)
1 parent 649e855 commit fcd759d

File tree

4 files changed

+62
-57
lines changed

4 files changed

+62
-57
lines changed

.flake8

Lines changed: 0 additions & 3 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,17 @@ repos:
44
hooks:
55
- id: black
66

7-
- repo: https://github.com/PyCQA/flake8
8-
rev: 6.0.0
9-
hooks:
10-
- id: flake8
11-
additional_dependencies:
12-
- flake8-bugbear==22.7.1
13-
14-
- repo: https://github.com/PyCQA/isort
15-
rev: 5.12.0
16-
hooks:
17-
- id: isort
18-
197
- repo: https://github.com/pre-commit/pre-commit-hooks
208
rev: v4.4.0
219
hooks:
2210
- id: trailing-whitespace
2311
- id: end-of-file-fixer
2412
- id: debug-statements
2513
- id: pretty-format-json
26-
args:
27-
- --autofix
14+
args: [--autofix]
2815
- id: check-json
2916

30-
- repo: https://github.com/asottile/pyupgrade
31-
rev: v3.4.0
17+
- repo: https://github.com/charliermarsh/ruff-pre-commit
18+
rev: v0.0.267
3219
hooks:
33-
- id: pyupgrade
34-
args: [--py36-plus]
20+
- id: ruff

install-poetry.py

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@
2222
script to alternatives, consider maintaining a local copy as part of your infrastructure.
2323
2424
For full documentation, visit https://python-poetry.org/docs/#installation.
25-
"""
25+
""" # noqa: E501
26+
import sys
27+
28+
29+
# Eager version check so we fail nicely before possible syntax errors
30+
if sys.version_info < (3, 6): # noqa: UP036
31+
sys.stdout.write("Poetry installer requires Python 3.6 or newer to run!\n")
32+
sys.exit(1)
33+
2634

2735
import argparse
2836
import json
2937
import os
3038
import re
3139
import shutil
3240
import subprocess
33-
import sys
3441
import sysconfig
3542
import tempfile
3643

@@ -107,8 +114,8 @@ def is_decorated():
107114
if WINDOWS:
108115
return (
109116
os.getenv("ANSICON") is not None
110-
or "ON" == os.getenv("ConEmuANSI")
111-
or "xterm" == os.getenv("Term")
117+
or os.getenv("ConEmuANSI") == "ON" # noqa: SIM112
118+
or os.getenv("Term") == "xterm" # noqa: SIM112
112119
)
113120

114121
if not hasattr(sys.stdout, "fileno"):
@@ -278,7 +285,7 @@ def __init__(self, path: Path) -> None:
278285
self._bin_path = self._path.joinpath(
279286
"Scripts" if WINDOWS and not MINGW else "bin"
280287
)
281-
# str is required for compatibility with subprocess run on CPython <= 3.7 on Windows
288+
# str is for compatibility with subprocess.run on CPython <= 3.7 on Windows
282289
self._python = str(
283290
self._path.joinpath(self._bin_path, "python.exe" if WINDOWS else "python")
284291
)
@@ -295,7 +302,8 @@ def bin_path(self):
295302
def make(cls, target: Path) -> "VirtualEnvironment":
296303
if not sys.executable:
297304
raise ValueError(
298-
"Unable to determine sys.executable. Set PATH to a sane value or set it explicitly with PYTHONEXECUTABLE."
305+
"Unable to determine sys.executable. Set PATH to a sane value or set it"
306+
" explicitly with PYTHONEXECUTABLE."
299307
)
300308

301309
try:
@@ -340,7 +348,7 @@ def make(cls, target: Path) -> "VirtualEnvironment":
340348

341349
env = cls(target)
342350

343-
# we do this here to ensure that outdated system default pip does not trigger older bugs
351+
# this ensures that outdated system default pip does not trigger older bugs
344352
env.pip("install", "--disable-pip-version-check", "--upgrade", "pip")
345353

346354
return env
@@ -527,18 +535,20 @@ def _is_self_upgrade_supported(x):
527535
mx = self.VERSION_REGEX.match(x)
528536

529537
if mx is None:
530-
# the version is not semver, perhaps scm or file, we assume upgrade is supported
538+
# the version is not semver, perhaps scm or file
539+
# we assume upgrade is supported
531540
return True
532541

533-
vx = tuple(int(p) for p in mx.groups()[:3]) + (mx.group(5),)
542+
vx = (*tuple(int(p) for p in mx.groups()[:3]), mx.group(5))
534543
return vx >= (1, 1, 7)
535544

536545
if version and not _is_self_upgrade_supported(version):
537546
self._write(
538547
colorize(
539548
"warning",
540-
f"You are installing {version}. When using the current installer, this version does not support "
541-
f"updating using the 'self update' command. Please use 1.1.7 or later.",
549+
f"You are installing {version}. When using the current installer, "
550+
"this version does not support updating using the 'self update' "
551+
"command. Please use 1.1.7 or later.",
542552
)
543553
)
544554
if not self._accept_all:
@@ -551,7 +561,7 @@ def _is_self_upgrade_supported(x):
551561
except subprocess.CalledProcessError as e:
552562
raise PoetryInstallationError(
553563
return_code=e.returncode, log=e.output.decode()
554-
)
564+
) from e
555565

556566
self._write("")
557567
self.display_post_message(version)
@@ -713,11 +723,12 @@ def display_post_message_windows(self, version: str) -> None:
713723
def get_windows_path_var(self) -> Optional[str]:
714724
import winreg
715725

716-
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root:
717-
with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
718-
path, _ = winreg.QueryValueEx(key, "PATH")
726+
with winreg.ConnectRegistry(
727+
None, winreg.HKEY_CURRENT_USER
728+
) as root, winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
729+
path, _ = winreg.QueryValueEx(key, "PATH")
719730

720-
return path
731+
return path
721732

722733
def display_post_message_fish(self, version: str) -> None:
723734
fish_user_paths = subprocess.check_output(
@@ -778,8 +789,8 @@ def _compare_versions(x, y):
778789
mx = self.VERSION_REGEX.match(x)
779790
my = self.VERSION_REGEX.match(y)
780791

781-
vx = tuple(int(p) for p in mx.groups()[:3]) + (mx.group(5),)
782-
vy = tuple(int(p) for p in my.groups()[:3]) + (my.group(5),)
792+
vx = (*tuple(int(p) for p in mx.groups()[:3]), mx.group(5))
793+
vy = (*tuple(int(p) for p in my.groups()[:3]), my.group(5))
783794

784795
if vx < vy:
785796
return -1
@@ -838,13 +849,6 @@ def _get(self, url):
838849

839850

840851
def main():
841-
if sys.version_info < (3, 6):
842-
sys.stdout.write(
843-
colorize("error", "Poetry installer requires Python 3.6 or newer to run!")
844-
)
845-
# return error code
846-
return 1
847-
848852
parser = argparse.ArgumentParser(
849853
description="Installs the latest (or given) version of poetry"
850854
)
@@ -930,7 +934,8 @@ def main():
930934
text=True,
931935
)
932936
installer._write(colorize("error", f"See {path} for error logs."))
933-
text = f"{e.log}\nTraceback:\n\n{''.join(traceback.format_tb(e.__traceback__))}"
937+
tb = "".join(traceback.format_tb(e.__traceback__))
938+
text = f"{e.log}\nTraceback:\n\n{tb}"
934939
Path(path).write_text(text)
935940

936941
return e.return_code

pyproject.toml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1-
[tool.isort]
2-
profile = "black"
3-
force_single_line = true
4-
atomic = true
5-
lines_after_imports = 2
6-
lines_between_types = 1
7-
filter_files = true
1+
[tool.ruff]
2+
fix = true
3+
unfixable = [
4+
"ERA", # do not autoremove commented out code
5+
]
6+
target-version = "py37"
7+
line-length = 88
8+
extend-select = [
9+
"B", # flake8-bugbear
10+
"C4", # flake8-comprehensions
11+
"ERA", # flake8-eradicate/eradicate
12+
"I", # isort
13+
"N", # pep8-naming
14+
"PIE", # flake8-pie
15+
"PGH", # pygrep
16+
"RUF", # ruff checks
17+
"SIM", # flake8-simplify
18+
"TCH", # flake8-type-checking
19+
"TID", # flake8-tidy-imports
20+
"UP", # pyupgrade
21+
]
822

23+
[tool.ruff.flake8-tidy-imports]
24+
ban-relative-imports = "all"
925

10-
[tool.black]
11-
line-length = 88
12-
include = '\.pyi?$'
26+
[tool.ruff.isort]
27+
force-single-line = true
28+
lines-between-types = 1
29+
lines-after-imports = 2

0 commit comments

Comments
 (0)