Skip to content

Commit

Permalink
chore(pre-commit): replace several linter by ruff (#136)
Browse files Browse the repository at this point in the history
* chore(pre-commit): replace several linter by ruff

* chore(pre-commit): update pre-commit hooks
  • Loading branch information
finswimmer committed May 2, 2023
1 parent 642642a commit a40e643
Show file tree
Hide file tree
Showing 17 changed files with 326 additions and 329 deletions.
39 changes: 7 additions & 32 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,24 @@ exclude: >
)$
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [ --py37-plus ]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
rev: v1.10.0
hooks:
- id: python-use-type-annotations
- id: python-check-blanket-noqa

- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
additional_dependencies: &flake8_deps
- flake8-bugbear
- flake8-type-checking

- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.263
hooks:
- id: isort
args: [--add-import, from __future__ import annotations]
exclude: |
(?x)(
^docs/.+\.py$
)
- id: ruff
args: [ --exit-non-zero-on-fix ]

- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: *flake8_deps
47 changes: 42 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,48 @@ extend-exclude = '''
)
'''

[tool.isort]
profile = "black"
atomic = true
filter_files = true
known_first_party = ["pythonfinder"]
[tool.ruff]
target-version = "py37"
fix = true
line-length = 90
select = [
"B", # flake8-bugbear
"E", # pycodestyle (flake8)
"F", # pyflakes (flake8)
"I", # isort
"PGH", # pygrep-hooks
"RUF", # Ruff u.a. yesqa
"TCH", # flake8-type-checking
"UP", # pyupgrade
"W", # pycodestyle (flake8)
]
ignore = [
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
"E501", # line too long (flake8)
"PGH003", # Use specific rule codes when ignoring type issues
]
unfixable = [
"F841", # Local variable {x} is assigned to but never used (flake8)
]
[tool.ruff.per-file-ignores]
"__init__.py" = [
"F401", # module imported but unused (flake8)
"F403", # ‘from module import *’ used; unable to detect undefined names (flake8)
]
"docs/*" = [
"I",
]

[tool.ruff.flake8-type-checking]
runtime-evaluated-base-classes = [
"pydantic.BaseModel",
"pythonfinder.models.common.FinderBaseModel",
"pythonfinder.models.mixins.PathEntry",
]

[tool.ruff.isort]
known-first-party = ["pythonfinder"]
required-imports = ["from __future__ import annotations"]

[tool.towncrier]
package = "pythonfinder"
Expand Down
35 changes: 0 additions & 35 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -84,41 +84,6 @@ filterwarnings =
[bdist_wheel]
universal = 1

[flake8]
max-line-length = 90
select = C,E,F,W,B
ignore =
# The default ignore list:
# E121,E123,E126,E226,E24,E704,
D203,F401,E123,E203,W503,E501,E402,F841,B950,TC,TC1
# Our additions:
# E127: continuation line over-indented for visual indent
# E128: continuation line under-indented for visual indent
# E129: visually indented line with same indent as next logical line
# E222: multiple spaces after operator
# E231: missing whitespace after ','
# E402: module level import not at top of file
# E501: line too long
# E231,E402,E501
extend_exclude =
docs/source/*,
tests/*,
setup.py
max-complexity=16

[isort]
atomic = true
not_skip = __init__.py
skip = src/pythonfinder/_vendor
line_length = 90
indent = ' '
multi_line_output = 3
known_third_party = cached_property,click,invoke,packaging,parver,pydantic,pytest,requests,setuptools,six,towncrier
known_first_party = pythonfinder,tests
combine_as_imports=True
include_trailing_comma = True
force_grid_wrap=0

[mypy]
ignore_missing_imports=true
follow_imports=skip
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import codecs
import os
import re
import sys

from setuptools import Command, find_packages, setup
from setuptools import find_packages, setup

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

Expand Down
2 changes: 2 additions & 0 deletions src/pythonfinder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from .exceptions import InvalidPythonVersion
from .models import SystemPath
from .pythonfinder import Finder
Expand Down
2 changes: 1 addition & 1 deletion src/pythonfinder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def cli(
comes_from_path = getattr(comes_from, "path", found.path)
else:
comes_from_path = found.path
arch = getattr(py, "architecture", None)

click.secho("Found python at the following locations:", fg="green")
click.secho(
"{py.name!s}: {py.version!s} ({py.architecture!s}) @ {comes_from!s}".format(
Expand Down
2 changes: 2 additions & 0 deletions src/pythonfinder/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from __future__ import annotations

from .path import SystemPath
from .python import PythonVersion
8 changes: 6 additions & 2 deletions src/pythonfinder/models/common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import annotations

from pydantic import BaseModel, Extra


class FinderBaseModel(BaseModel):
def __setattr__(self, name, value): # noqa: C901 (ignore complexity)
def __setattr__(self, name, value):
private_attributes = {
field_name for field_name in self.__annotations__ if field_name.startswith("_")
field_name
for field_name in self.__annotations__
if field_name.startswith("_")
}

if name in private_attributes or name in self.__fields__:
Expand Down
Loading

0 comments on commit a40e643

Please sign in to comment.