Skip to content

Commit a40e643

Browse files
authored
chore(pre-commit): replace several linter by ruff (#136)
* chore(pre-commit): replace several linter by ruff * chore(pre-commit): update pre-commit hooks
1 parent 642642a commit a40e643

17 files changed

+326
-329
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,24 @@ exclude: >
44
)$
55
66
repos:
7-
- repo: https://github.com/asottile/pyupgrade
8-
rev: v3.3.1
9-
hooks:
10-
- id: pyupgrade
11-
args: [ --py37-plus ]
12-
137
- repo: https://github.com/pre-commit/pre-commit-hooks
14-
rev: v4.3.0
8+
rev: v4.4.0
159
hooks:
1610
- id: trailing-whitespace
1711
- id: end-of-file-fixer
1812

1913
- repo: https://github.com/pre-commit/pygrep-hooks
20-
rev: v1.9.0
14+
rev: v1.10.0
2115
hooks:
2216
- id: python-use-type-annotations
23-
- id: python-check-blanket-noqa
24-
25-
- repo: https://github.com/asottile/yesqa
26-
rev: v1.4.0
27-
hooks:
28-
- id: yesqa
29-
additional_dependencies: &flake8_deps
30-
- flake8-bugbear
31-
- flake8-type-checking
3217

33-
- repo: https://github.com/pycqa/isort
34-
rev: 5.12.0
18+
- repo: https://github.com/charliermarsh/ruff-pre-commit
19+
rev: v0.0.263
3520
hooks:
36-
- id: isort
37-
args: [--add-import, from __future__ import annotations]
38-
exclude: |
39-
(?x)(
40-
^docs/.+\.py$
41-
)
21+
- id: ruff
22+
args: [ --exit-non-zero-on-fix ]
4223

4324
- repo: https://github.com/psf/black
44-
rev: 23.1.0
25+
rev: 23.3.0
4526
hooks:
4627
- id: black
47-
48-
- repo: https://github.com/pycqa/flake8
49-
rev: 6.0.0
50-
hooks:
51-
- id: flake8
52-
additional_dependencies: *flake8_deps

pyproject.toml

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,48 @@ extend-exclude = '''
99
)
1010
'''
1111

12-
[tool.isort]
13-
profile = "black"
14-
atomic = true
15-
filter_files = true
16-
known_first_party = ["pythonfinder"]
12+
[tool.ruff]
13+
target-version = "py37"
14+
fix = true
15+
line-length = 90
16+
select = [
17+
"B", # flake8-bugbear
18+
"E", # pycodestyle (flake8)
19+
"F", # pyflakes (flake8)
20+
"I", # isort
21+
"PGH", # pygrep-hooks
22+
"RUF", # Ruff u.a. yesqa
23+
"TCH", # flake8-type-checking
24+
"UP", # pyupgrade
25+
"W", # pycodestyle (flake8)
26+
]
27+
ignore = [
28+
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
29+
"E501", # line too long (flake8)
30+
"PGH003", # Use specific rule codes when ignoring type issues
31+
]
32+
unfixable = [
33+
"F841", # Local variable {x} is assigned to but never used (flake8)
34+
]
35+
[tool.ruff.per-file-ignores]
36+
"__init__.py" = [
37+
"F401", # module imported but unused (flake8)
38+
"F403", # ‘from module import *’ used; unable to detect undefined names (flake8)
39+
]
40+
"docs/*" = [
41+
"I",
42+
]
43+
44+
[tool.ruff.flake8-type-checking]
45+
runtime-evaluated-base-classes = [
46+
"pydantic.BaseModel",
47+
"pythonfinder.models.common.FinderBaseModel",
48+
"pythonfinder.models.mixins.PathEntry",
49+
]
50+
51+
[tool.ruff.isort]
52+
known-first-party = ["pythonfinder"]
53+
required-imports = ["from __future__ import annotations"]
1754

1855
[tool.towncrier]
1956
package = "pythonfinder"

setup.cfg

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -84,41 +84,6 @@ filterwarnings =
8484
[bdist_wheel]
8585
universal = 1
8686

87-
[flake8]
88-
max-line-length = 90
89-
select = C,E,F,W,B
90-
ignore =
91-
# The default ignore list:
92-
# E121,E123,E126,E226,E24,E704,
93-
D203,F401,E123,E203,W503,E501,E402,F841,B950,TC,TC1
94-
# Our additions:
95-
# E127: continuation line over-indented for visual indent
96-
# E128: continuation line under-indented for visual indent
97-
# E129: visually indented line with same indent as next logical line
98-
# E222: multiple spaces after operator
99-
# E231: missing whitespace after ','
100-
# E402: module level import not at top of file
101-
# E501: line too long
102-
# E231,E402,E501
103-
extend_exclude =
104-
docs/source/*,
105-
tests/*,
106-
setup.py
107-
max-complexity=16
108-
109-
[isort]
110-
atomic = true
111-
not_skip = __init__.py
112-
skip = src/pythonfinder/_vendor
113-
line_length = 90
114-
indent = ' '
115-
multi_line_output = 3
116-
known_third_party = cached_property,click,invoke,packaging,parver,pydantic,pytest,requests,setuptools,six,towncrier
117-
known_first_party = pythonfinder,tests
118-
combine_as_imports=True
119-
include_trailing_comma = True
120-
force_grid_wrap=0
121-
12287
[mypy]
12388
ignore_missing_imports=true
12489
follow_imports=skip

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import codecs
44
import os
55
import re
6-
import sys
76

8-
from setuptools import Command, find_packages, setup
7+
from setuptools import find_packages, setup
98

109
here = os.path.abspath(os.path.dirname(__file__))
1110

src/pythonfinder/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .exceptions import InvalidPythonVersion
24
from .models import SystemPath
35
from .pythonfinder import Finder

src/pythonfinder/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def cli(
6060
comes_from_path = getattr(comes_from, "path", found.path)
6161
else:
6262
comes_from_path = found.path
63-
arch = getattr(py, "architecture", None)
63+
6464
click.secho("Found python at the following locations:", fg="green")
6565
click.secho(
6666
"{py.name!s}: {py.version!s} ({py.architecture!s}) @ {comes_from!s}".format(

src/pythonfinder/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
from __future__ import annotations
2+
13
from .path import SystemPath
24
from .python import PythonVersion

src/pythonfinder/models/common.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
from __future__ import annotations
2+
13
from pydantic import BaseModel, Extra
24

35

46
class FinderBaseModel(BaseModel):
5-
def __setattr__(self, name, value): # noqa: C901 (ignore complexity)
7+
def __setattr__(self, name, value):
68
private_attributes = {
7-
field_name for field_name in self.__annotations__ if field_name.startswith("_")
9+
field_name
10+
for field_name in self.__annotations__
11+
if field_name.startswith("_")
812
}
913

1014
if name in private_attributes or name in self.__fields__:

0 commit comments

Comments
 (0)