Skip to content

Commit 2ea4c28

Browse files
Sync Ruff configs with Beslogic/shared-configs (#293)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3e33b23 commit 2ea4c28

22 files changed

+657
-344
lines changed

Diff for: .pre-commit-config.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ repos:
1414
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
1515
rev: v2.14.0
1616
hooks:
17+
- id: pretty-format-yaml
18+
args: [--autofix, --indent, "2", --offset, "2", --preserve-quotes, --line-width, "100"]
1719
- id: pretty-format-ini
1820
args: [--autofix]
1921
- repo: https://github.com/astral-sh/ruff-pre-commit
20-
rev: "v0.5.6" # Must match requirements-dev.txt
22+
rev: v0.6.1 # Must match requirements-dev.txt
2123
hooks:
2224
- id: ruff
2325
args: [--fix]
2426
- repo: https://github.com/hhatto/autopep8
25-
rev: "v2.3.1" # Must match requirements-dev.txt
27+
rev: v2.3.1 # Must match requirements-dev.txt
2628
hooks:
2729
- id: autopep8
2830
- repo: https://github.com/asottile/add-trailing-comma

Diff for: .vscode/settings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"editor.rulers": [
33
80,
4-
120
4+
100
55
],
66
"[git-commit]": {
77
"editor.rulers": [
@@ -75,7 +75,7 @@
7575
// 79, // PEP8-17 default max
7676
// 88, // Black default
7777
// 99, // PEP8-17 acceptable max
78-
120, // Our hard rule
78+
100, // Our hard rule
7979
],
8080
},
8181
"mypy-type-checker.importStrategy": "fromEnvironment",

Diff for: pyproject.toml

+2-141
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,7 @@
1-
# https://docs.astral.sh/ruff/configuration/
2-
[tool.ruff]
3-
target-version = "py310"
4-
line-length = 120
5-
preview = true
6-
7-
[tool.ruff.lint]
8-
select = ["ALL"]
9-
# https://docs.astral.sh/ruff/rules/
10-
ignore = [
11-
###
12-
# Not needed or wanted
13-
###
14-
"D1", # pydocstyle Missing doctring
15-
"D401", # pydocstyle: non-imperative-mood
16-
"EM", # flake8-errmsg
17-
# This is often something we can't control: https://github.com/astral-sh/ruff/issues/9497
18-
# Also false-positive with positional-only arguments: https://github.com/astral-sh/ruff/issues/3247
19-
"FBT003", # flake8-boolean-trap: boolean-positional-value-in-call
20-
"INP", # flake8-no-pep420
21-
"ISC003", # flake8-implicit-str-concat: explicit-string-concatenation
22-
# Short messages are still considered "long" messages
23-
"TRY003", # tryceratops : raise-vanilla-args
24-
# Don't remove commented code, also too inconsistant
25-
"ERA001", # eradicate: commented-out-code
26-
# contextlib.suppress is roughly 3x slower than try/except
27-
"SIM105", # flake8-simplify: use-contextlib-suppress
28-
# Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
29-
"UP038", # non-pep604-isinstance
30-
# Checked by type-checker (pyright)
31-
"ANN", # flake-annotations
32-
"PGH003", # blanket-type-ignore
33-
"TCH", # flake8-type-checking
34-
# Already shown by Pylance, checked by pyright, and can be caused by overloads.
35-
"ARG002", # Unused method argument
36-
# We want D213: multi-line-summary-second-line and D211: no-blank-line-before-class
37-
"D203", # pydocstyle: one-blank-line-before-class
38-
"D212", # pydocstyle: multi-line-summary-first-line
39-
# Allow differentiating between broken (FIXME) and to be done/added/completed (TODO)
40-
"TD001", # flake8-todos: invalid-todo-tag
41-
42-
###
43-
# These should be warnings (https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774)
44-
###
45-
"FIX", # flake8-fixme
46-
# Not all TODOs are worth an issue, this would be better as a warning
47-
"TD003", # flake8-todos: missing-todo-link
48-
49-
# False-positives
50-
"TCH004", # https://github.com/astral-sh/ruff/issues/3821
51-
52-
###
53-
# Specific to this project
54-
###
55-
"D205", # Not all docstrings have a short description + desrciption
56-
# TODO: Consider for more complete doc
57-
"DOC201", # docstring-extraneous-returns
58-
"DOC501", # docstring-missing-exception
59-
# We have some Pascal case module names
60-
"N999", # pep8-naming: Invalid module name
61-
# Print are used as debug logs
62-
"T20", # flake8-print
63-
# This is a relatively small, low contributors project. Git blame suffice.
64-
"TD002", # missing-todo-author
65-
# Python 3.11, introduced "zero cost" exception handling
66-
"PERF203", # try-except-in-loop
67-
68-
### FIXME/TODO: I'd normally set them as temporarily warnings, but no warnings in Ruff yet:
69-
### https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774):
70-
"CPY001", # flake8-copyright
71-
"PTH", # flake8-use-pathlib
72-
# Ignore until linux support
73-
"EXE", # flake8-executable
74-
]
75-
76-
[tool.ruff.lint.per-file-ignores]
77-
"typings/**/*.pyi" = [
78-
"F811", # Re-exports false positives
79-
"F821", # https://github.com/astral-sh/ruff/issues/3011
80-
# The following can't be controlled for external libraries:
81-
"A", # Shadowing builtin names
82-
"FBT", # flake8-boolean-trap
83-
"ICN001", # unconventional-import-alias
84-
"N8", # Naming conventions
85-
"PLC2701", # Private name import
86-
"PLR0904", # Too many public methods
87-
"PLR0913", # Argument count
88-
"PLR0917", # Too many positional arguments
89-
"PLW3201", # misspelled dunder method name
90-
"PYI042", # CamelCase TypeAlias
91-
]
92-
93-
# https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat
94-
[tool.ruff.lint.flake8-implicit-str-concat]
95-
allow-multiline = false
96-
97-
# https://docs.astral.sh/ruff/settings/#isort
98-
[tool.ruff.lint.isort]
99-
combine-as-imports = true
100-
split-on-trailing-comma = false
101-
# Unlike isort, Ruff only counts relative imports as local-folder by default for know.
102-
# https://github.com/astral-sh/ruff/issues/3115
103-
known-local-folder = [
104-
"AutoControlledThread",
105-
"AutoSplit",
106-
"AutoSplitImage",
107-
"capture_method",
108-
"compare",
109-
"error_messages",
110-
"gen",
111-
"hotkeys",
112-
"menu_bar",
113-
"region_selection",
114-
"split_parser",
115-
"user_profile",
116-
"utils",
117-
]
118-
119-
# https://docs.astral.sh/ruff/settings/#mccabe
120-
[tool.ruff.lint.mccabe]
121-
# Hard limit, arbitrary to 4 bytes
122-
max-complexity = 31
123-
# Arbitrary to 2 bytes, same as SonarLint
124-
# max-complexity = 15
125-
126-
[tool.ruff.lint.pylint]
127-
# Arbitrary to 1 byte, same as SonarLint
128-
max-args = 7
129-
# At least same as max-complexity
130-
max-branches = 15
131-
132-
[tool.ruff.lint.flake8-tidy-imports.banned-api]
133-
"cv2.imread".msg = """\
134-
it doesn't support special characters. Use `utils.imread` instead.
135-
https://github.com/opencv/opencv/issues/4292#issuecomment-2266019697"""
136-
"cv2.imwrite".msg = """\
137-
it doesn't support special characters. Use `utils.imwrite` instead.
138-
https://github.com/opencv/opencv/issues/4292#issuecomment-2266019697"""
139-
1401
# https://github.com/hhatto/autopep8#usage
1412
# https://github.com/hhatto/autopep8#more-advanced-usage
1423
[tool.autopep8]
143-
max_line_length = 120
4+
max_line_length = 100
1445
aggressive = 3
1456
exclude = ".venv/*,src/gen/*"
1467
ignore = [
@@ -151,7 +12,7 @@ ignore = [
15112
# Check for the "Fix" flag https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
15213
"E2", # Whitespace
15314
"E3", # Blank lines
154-
"E703", # useless-semicolon
15+
"E703", # useless-semicolon
15516
"E71", # Statement (comparisons)
15617
"E731", # lambda-assignment
15718
"W29", # Whitespace warning

Diff for: ruff.toml

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright 2024 Beslogic Inc.
3+
4+
# The source skeleton for this configuration can be found at
5+
# https://github.com/BesLogic/shared-configs/blob/main/ruff.toml
6+
# Modifications to this file that are not project-specific should also be done upstream.
7+
# These configs are incompatible with ruff<0.5.7
8+
9+
# https://docs.astral.sh/ruff/configuration/
10+
target-version = "py310" # Change this to the oldest supported version by your application
11+
line-length = 100
12+
preview = true
13+
14+
[lint]
15+
select = ["ALL"]
16+
# https://docs.astral.sh/ruff/rules/
17+
ignore = [
18+
###
19+
# Not needed or wanted
20+
###
21+
"D1", # pydocstyle Missing doctring
22+
"D401", # pydocstyle: non-imperative-mood
23+
"EM", # flake8-errmsg
24+
"EXE", # flake8-executable
25+
# This is often something we can't control: https://github.com/astral-sh/ruff/issues/9497
26+
# Also false-positive with positional-only arguments: https://github.com/astral-sh/ruff/issues/3247
27+
"FBT003", # flake8-boolean-trap: boolean-positional-value-in-call
28+
"INP", # flake8-no-pep420
29+
"ISC003", # flake8-implicit-str-concat: explicit-string-concatenation
30+
# Short messages are still considered "long" messages
31+
"TRY003", # tryceratops : raise-vanilla-args
32+
# Don't remove commented code, also too inconsistant
33+
"ERA001", # eradicate: commented-out-code
34+
# contextlib.suppress is roughly 3x slower than try/except
35+
"SIM105", # flake8-simplify: use-contextlib-suppress
36+
# Negative performance impact and more verbose https://github.com/astral-sh/ruff/issues/7871
37+
"UP038", # non-pep604-isinstance
38+
# deprecated and is actually slower for cases relevant to unpacking: https://github.com/astral-sh/ruff/issues/12754
39+
"UP027", # unpacked-list-comprehension
40+
# Checked by type-checker (pyright/mypy)
41+
"ANN", # flake-annotations
42+
"PGH003", # blanket-type-ignore
43+
"TCH", # flake8-type-checking
44+
# Already shown by Pylance, checked by pyright, and can be caused by overloads.
45+
"ARG002", # Unused method argument
46+
# We want D213: multi-line-summary-second-line and D211: no-blank-line-before-class
47+
"D203", # pydocstyle: one-blank-line-before-class
48+
"D212", # pydocstyle: multi-line-summary-first-line
49+
# Allow differentiating between broken (FIXME) and to be done/added/completed (TODO)
50+
"TD001", # flake8-todos: invalid-todo-tag
51+
52+
###
53+
# These should be warnings (https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774)
54+
###
55+
"FIX", # flake8-fixme
56+
# Not all TODOs are worth an issue, this would be better as a warning
57+
"TD003", # flake8-todos: missing-todo-link
58+
59+
# False-positives
60+
"TCH004", # https://github.com/astral-sh/ruff/issues/3821
61+
62+
###
63+
# Conflict with formatter (you can remove this section if you don't use Ruff as a formatter)
64+
###
65+
# "COM812", # missing-trailing-comma
66+
# "ISC001", # single-line-implicit-string-concatenation
67+
68+
###
69+
# Rules about missing special documentation. Up to you if you wanna enable these, you must also disable D406, D407
70+
###
71+
"DOC201", # docstring-missing-returns
72+
"DOC402", # docstring-missing-yields
73+
"DOC501", # docstring-missing-exception
74+
# "D406", # new-line-after-section-name, conflicts with DOC
75+
# "D407", # dashed-underline-after-section, conflicts with DOC
76+
77+
###
78+
# Specific to this project
79+
###
80+
"D205", # Not all docstrings have a short description + desrciption
81+
# TODO: Consider for more complete doc
82+
"DOC201", # docstring-extraneous-returns
83+
"DOC501", # docstring-missing-exception
84+
# We have some Pascal case module names
85+
"N999", # pep8-naming: Invalid module name
86+
# Print are used as debug logs
87+
"T20", # flake8-print
88+
# This is a relatively small, low contributors project. Git blame suffice.
89+
"TD002", # missing-todo-author
90+
# Python 3.11, introduced "zero cost" exception handling
91+
"PERF203", # try-except-in-loop
92+
93+
###
94+
# FIXME/TODO: I'd normally set them as temporarily warnings, but no warnings in Ruff yet:
95+
# https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774):
96+
###
97+
"CPY001", # flake8-copyright
98+
"PTH", # flake8-use-pathlib
99+
# Ignore until linux support
100+
"EXE", # flake8-executable
101+
]
102+
103+
# https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat
104+
[lint.flake8-implicit-str-concat]
105+
allow-multiline = false
106+
107+
# https://docs.astral.sh/ruff/settings/#isort
108+
[lint.isort]
109+
combine-as-imports = true
110+
split-on-trailing-comma = false
111+
# This should be automatically detected in src layout, but somehow pre-commit messes it up
112+
known-first-party = ["gen"]
113+
114+
# https://docs.astral.sh/ruff/settings/#mccabe
115+
[lint.mccabe]
116+
# Arbitrary to 2 bytes, same as SonarLint
117+
max-complexity = 15
118+
119+
[lint.pylint]
120+
# Arbitrary to 1 byte, same as SonarLint
121+
max-args = 7
122+
# At least same as max-complexity
123+
max-branches = 15
124+
125+
[lint.per-file-ignores]
126+
"**/typings/**/*.pyi" = [
127+
"F811", # Re-exports false positives
128+
# The following can't be controlled for external libraries:
129+
"A", # Shadowing builtin names
130+
"E741", # ambiguous variable name
131+
"F403", # `from . import *` used; unable to detect undefined names
132+
"FBT", # flake8-boolean-trap
133+
"ICN001", # unconventional-import-alias
134+
"N8", # Naming conventions
135+
"PLC2701", # Private name import
136+
"PLR0904", # Too many public methods
137+
"PLR0913", # Argument count
138+
"PLR0917", # Too many positional arguments
139+
"PLW3201", # misspelled dunder method name
140+
"PYI042", # CamelCase TypeAlias
141+
# Stubs can sometimes re-export entire modules.
142+
# Issues with using a star-imported name will be caught by type-checkers.
143+
"F405", # may be undefined, or defined from star imports
144+
]
145+
146+
[lint.flake8-tidy-imports.banned-api]
147+
"cv2.imread".msg = """\
148+
it doesn't support special characters. \
149+
Use `cv2.imdecode(np.fromfile(filename, dtype=np.uint8), flags)` instead.
150+
https://github.com/opencv/opencv/issues/4292#issuecomment-2266019697"""
151+
"cv2.imwrite".msg = """\
152+
it doesn't support special characters. \
153+
Use `cv2.imencode(os.path.splitext(filename)[1], img)[1].tofile(filename)` instead.
154+
https://github.com/opencv/opencv/issues/4292#issuecomment-2266019697"""

Diff for: scripts/requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Linters & Formatters
1515
add-trailing-comma>=3.1.0 # Must match .pre-commit-config.yaml
1616
autopep8>=2.3.1 # Must match .pre-commit-config.yaml
17-
ruff>=0.5.6 # New checks # Must match .pre-commit-config.yaml
17+
ruff>=0.6.1 # Pre-commit fix # Must match .pre-commit-config.yaml
1818
#
1919
# Types
2020
types-D3DShot ; sys_platform == 'win32'

0 commit comments

Comments
 (0)