Skip to content

Commit 839c728

Browse files
committed
Move towards usage of ruff
1 parent 6bb0b78 commit 839c728

22 files changed

Lines changed: 229 additions & 109 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.log
33
.coverage
44
.pytest_cache
5+
.ruff_cache
56
.tox/
67
__pycache__/
78
build/

.pre-commit-config.yaml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 22.3.0
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.13.0
44
hooks:
5-
- id: black
5+
- id: ruff-check
6+
args: [--fix, --exit-non-zero-on-fix]
7+
- id: ruff-format
68

7-
- repo: https://github.com/PyCQA/flake8
8-
rev: 3.8.3
9-
hooks:
10-
- id: flake8
11-
additional_dependencies: [flake8-bugbear]
12-
13-
- repo: https://github.com/pre-commit/mirrors-isort
14-
rev: v5.8.0
15-
hooks:
16-
- id: isort
17-
name: isort
18-
args:
19-
- --settings=.
20-
21-
- repo: https://github.com/pre-commit/mirrors-pylint
22-
rev: v2.7.4
9+
- repo: https://github.com/pylint-dev/pylint
10+
rev: v3.3.8
2311
hooks:
2412
- id: pylint
2513
name: pylint
26-
args:
27-
- --rcfile=.pylintrc
28-
- --exit-zero
2914
verbose: true
30-
additional_dependencies: &pylint_deps
31-
- pylint-odoo==6.2.0

.pylintrc

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

pyproject.toml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,58 @@ build-backend = "setuptools.build_meta"
66
line-length = 88
77
target-version = ['py36', 'py37', 'py38', 'py39', 'py310']
88
include = '(\.pyi?$|src|tests)'
9+
10+
[tool.ruff]
11+
target-version = "py310"
12+
fix = true
13+
14+
[tool.ruff.lint]
15+
extend-select = [
16+
"B",
17+
"C90",
18+
"E501", # line too long (default 88)
19+
"I", # isort
20+
"UP", # pyupgrade
21+
]
22+
extend-safe-fixes = ["UP008"]
23+
exclude = ["setup/*"]
24+
25+
[tool.ruff.lint.mccabe]
26+
max-complexity = 16
27+
28+
[tool.pylint.main]
29+
ignored-modules = ["dateutil", "git_aggregator", "odoo", "pytest", "pytest_odoo", "yaml"]
30+
31+
[tool.pylint.imports]
32+
ignored-modules = ["dateutil", "git_aggregator", "odoo", "pytest", "pytest_odoo", "yaml"]
33+
34+
[tool.pylint."messages control"]
35+
disable = """
36+
attribute-defined-outside-init,
37+
bad-inline-option,
38+
bad-mcs-classmethod-argument,
39+
broad-except,
40+
deprecated-pragma,
41+
duplicate-code,
42+
file-ignored,
43+
invalid-name,
44+
locally-disabled,
45+
logging-fstring-interpolation,
46+
missing-class-docstring,
47+
missing-function-docstring,
48+
missing-module-docstring,
49+
protected-access,
50+
raw-checker-failed,
51+
redefined-outer-name,
52+
suppressed-message,
53+
too-few-public-methods,
54+
too-many-arguments,
55+
too-many-instance-attributes,
56+
too-many-locals,
57+
too-many-positional-arguments,
58+
too-many-return-statements,
59+
unused-argument,
60+
use-implicit-booleaness-not-comparison,
61+
use-symbolic-message-instead,
62+
useless-suppression,
63+
"""

setup.cfg

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ package_dir =
2222
packages = find:
2323
python_requires = >=3.6
2424
install_requires =
25-
black
2625
coverage
27-
debugpy
28-
flake8
2926
git-aggregator
3027
ipython
31-
isort>=4.3.10
3228
pylint_odoo
3329
python-dateutil
3430
pytest-cov
@@ -37,7 +33,15 @@ install_requires =
3733

3834
[options.entry_points]
3935
console_scripts =
40-
dob = doblib.__main__:main
36+
dob = doblib.__main__:main
37+
38+
[options.extras_require]
39+
no-ruff =
40+
black
41+
flake8
42+
isort>=4.3.10
43+
ruff =
44+
ruff
4145

4246
[options.packages.find]
4347
where = src

src/doblib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "0.19.8"
1+
VERSION = "0.20.0"

src/doblib/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ def load_arguments(args):
9797
return parser.parse_known_args(args)
9898

9999

100+
# ruff: noqa: C901
101+
# pylint: disable=R0912
100102
def main(args=None):
101103
args = args or sys.argv[1:]
102104

src/doblib/action.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def load_action_arguments(args, actions=None):
3535
default=False,
3636
help="Run the action as a dry-run and don't commit changes",
3737
)
38+
# ruff: noqa: E501
3839
parser.add_argument_group(
3940
"Actions",
4041
"Database actions are defined under the `actions` section in the configuration "
@@ -366,6 +367,7 @@ def _action_delete(self, env, model, domain, item, *, dry_run=False):
366367

367368
def _action_update(self, env, model, domain, item, *, dry_run=False):
368369
"""Runs the update action"""
370+
# pylint: disable=R0912
369371
values = item.get("values", {})
370372
if not values or model not in env:
371373
return

src/doblib/aggregate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from git_aggregator.repo import Repo
1414
from git_aggregator.utils import ThreadNameKeeper
1515

16-
from . import base, env, utils
16+
from . import env, utils
1717

1818

1919
def aggregate_repo(repo, args, sem, err_queue, mode=None):
@@ -145,6 +145,8 @@ def _aggregator(self, args, mode=None):
145145
traceback.print_exception(exc_type, exc_obj, exc_trace)
146146
return 1
147147

148+
return 0
149+
148150
def init(self, args=None):
149151
"""Initialize the environment using the git-aggregator"""
150152
args, _ = load_init_arguments(args or [])

src/doblib/ci.py

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
import sys
88
from fnmatch import fnmatch
99

10-
import isort
1110
import pytest
1211

1312
from . import base, env, utils
1413

15-
CI = ("black", "eslint", "flake8", "isort", "prettier", "pylint")
14+
CI = ("black", "eslint", "flake8", "isort", "prettier", "pylint", "ruff", "ruff-format")
1615

1716

1817
def load_ci_arguments(args):
@@ -31,6 +30,13 @@ class CIEnvironment(env.Environment):
3130

3231
def _ci_black(self, options, args, paths, ignores):
3332
"""Run black"""
33+
try:
34+
# pylint: disable=C0415,W0611
35+
import black
36+
except ImportError:
37+
utils.error("black is not installed")
38+
return 1
39+
3440
cmd = [sys.executable, "-m", "black"]
3541

3642
# Replace pattern matching with regex
@@ -75,6 +81,13 @@ def _ci_eslint(self, options, args, paths, ignores):
7581

7682
def _ci_flake8(self, options, left, paths, ignores):
7783
"""Run flake8 tests"""
84+
try:
85+
# pylint: disable=C0415,E0401,W0611
86+
import flake8
87+
except ImportError:
88+
utils.error("flake8 is not installed")
89+
return 1
90+
7891
cmd = [sys.executable, "-m", "flake8"]
7992
if ignores:
8093
cmd.append("--extend-exclude=" + ",".join(ignores))
@@ -88,6 +101,12 @@ def _ci_flake8(self, options, left, paths, ignores):
88101

89102
def _ci_isort(self, options, args, paths, ignores):
90103
"""Run isort"""
104+
try:
105+
# pylint: disable=C0415,E0401,W0611
106+
import isort
107+
except ImportError:
108+
utils.error("isort is not installed")
109+
return 1
91110

92111
cmd = [sys.executable, "-m", "isort"]
93112
if not options.fix:
@@ -151,6 +170,13 @@ def _ci_prettier(self, options, args, paths, ignores):
151170

152171
def _ci_pylint(self, options, args, paths, ignores):
153172
"""Run pylint tests for Odoo"""
173+
try:
174+
# pylint: disable=C0415,E0401,W0611
175+
import pylint
176+
except ImportError:
177+
utils.error("pylint is not installed")
178+
return 1
179+
154180
files = set()
155181

156182
extensions = self.get(
@@ -182,6 +208,50 @@ def _ci_pylint(self, options, args, paths, ignores):
182208

183209
return utils.call(*cmd, *args, *files, pipe=False)
184210

211+
def _ci_ruff(self, options, args, paths, ignores):
212+
try:
213+
# pylint: disable=C0415,E0401,W0611
214+
import ruff
215+
except ImportError:
216+
utils.error("ruff is not installed")
217+
return 1
218+
219+
cmd = [
220+
sys.executable,
221+
"-m",
222+
"ruff",
223+
"check",
224+
"--fix" if options.fix else "--no-fix",
225+
"--force-exclude",
226+
]
227+
for pattern in ignores:
228+
cmd += ["--exclude", pattern]
229+
230+
return utils.call(*cmd, *args, *paths, pipe=False)
231+
232+
def _ci_ruff_format(self, options, args, paths, ignores):
233+
try:
234+
# pylint: disable=C0415,E0401,W0611
235+
import ruff
236+
except ImportError:
237+
utils.error("ruff is not installed")
238+
return 1
239+
240+
cmd = [
241+
sys.executable,
242+
"-m",
243+
"ruff",
244+
"format",
245+
"--force-exclude",
246+
]
247+
if not options.fix:
248+
cmd.append("--check")
249+
250+
for pattern in ignores:
251+
cmd += ["--exclude", pattern]
252+
253+
return utils.call(*cmd, *args, *paths, pipe=False)
254+
185255
def _ci_paths(self):
186256
return self.get("odoo", "addons_path", default=[]) + self.get(
187257
base.SECTION, "ci_path", default=[]
@@ -193,15 +263,17 @@ def ci(self, ci, args=None):
193263

194264
# Always include this script in the tests
195265
ignores = self.get(base.SECTION, "blacklist", default=[])
196-
func = getattr(self, f"_ci_{ci}", None)
266+
func = getattr(self, f"_ci_{ci.replace('-', '_')}", None)
197267
if ci in CI and callable(func):
268+
# pylint: disable=E1102
198269
return func(args, left, self._ci_paths(), ignores)
199270

200271
utils.error(f"Unknown CI {ci}")
201272
return 1
202273

203274
def _install_patches_for_pytest(self):
204275
"""Apply patches for pytest"""
276+
# pylint: disable=C0415
205277
from odoo.tests.common import BaseCase
206278

207279
if hasattr(BaseCase, "run"):
@@ -227,7 +299,8 @@ def test(self, args=None):
227299
if not self._init_odoo():
228300
return False
229301

230-
# pylint: disable=C0415,E0401
302+
# pylint: disable=C0415,E0401,W0611
303+
# ruff: noqa: F401
231304
import odoo
232305
from odoo.cli.server import report_configuration
233306
from odoo.tools import config

0 commit comments

Comments
 (0)