Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Ruff configs with Beslogic/shared-configs #293

Merged
merged 14 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ repos:
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.14.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, "2", --offset, "2", --preserve-quotes, --line-width, "100"]
- id: pretty-format-ini
args: [--autofix]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.6" # Must match requirements-dev.txt
rev: v0.6.1 # Must match requirements-dev.txt
hooks:
- id: ruff
args: [--fix]
- repo: https://github.com/hhatto/autopep8
rev: "v2.3.1" # Must match requirements-dev.txt
rev: v2.3.1 # Must match requirements-dev.txt
hooks:
- id: autopep8
- repo: https://github.com/asottile/add-trailing-comma
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"editor.rulers": [
80,
120
100
],
"[git-commit]": {
"editor.rulers": [
Expand Down Expand Up @@ -75,7 +75,7 @@
// 79, // PEP8-17 default max
// 88, // Black default
// 99, // PEP8-17 acceptable max
120, // Our hard rule
100, // Our hard rule
],
},
"mypy-type-checker.importStrategy": "fromEnvironment",
Expand Down
143 changes: 2 additions & 141 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,146 +1,7 @@
# https://docs.astral.sh/ruff/configuration/
[tool.ruff]
target-version = "py310"
line-length = 120
preview = true

[tool.ruff.lint]
select = ["ALL"]
# https://docs.astral.sh/ruff/rules/
ignore = [
###
# Not needed or wanted
###
"D1", # pydocstyle Missing doctring
"D401", # pydocstyle: non-imperative-mood
"EM", # flake8-errmsg
# This is often something we can't control: https://github.com/astral-sh/ruff/issues/9497
# Also false-positive with positional-only arguments: https://github.com/astral-sh/ruff/issues/3247
"FBT003", # flake8-boolean-trap: boolean-positional-value-in-call
"INP", # flake8-no-pep420
"ISC003", # flake8-implicit-str-concat: explicit-string-concatenation
# Short messages are still considered "long" messages
"TRY003", # tryceratops : raise-vanilla-args
# Don't remove commented code, also too inconsistant
"ERA001", # eradicate: commented-out-code
# contextlib.suppress is roughly 3x slower than try/except
"SIM105", # flake8-simplify: use-contextlib-suppress
# Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
"UP038", # non-pep604-isinstance
# Checked by type-checker (pyright)
"ANN", # flake-annotations
"PGH003", # blanket-type-ignore
"TCH", # flake8-type-checking
# Already shown by Pylance, checked by pyright, and can be caused by overloads.
"ARG002", # Unused method argument
# We want D213: multi-line-summary-second-line and D211: no-blank-line-before-class
"D203", # pydocstyle: one-blank-line-before-class
"D212", # pydocstyle: multi-line-summary-first-line
# Allow differentiating between broken (FIXME) and to be done/added/completed (TODO)
"TD001", # flake8-todos: invalid-todo-tag

###
# These should be warnings (https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774)
###
"FIX", # flake8-fixme
# Not all TODOs are worth an issue, this would be better as a warning
"TD003", # flake8-todos: missing-todo-link

# False-positives
"TCH004", # https://github.com/astral-sh/ruff/issues/3821

###
# Specific to this project
###
"D205", # Not all docstrings have a short description + desrciption
# TODO: Consider for more complete doc
"DOC201", # docstring-extraneous-returns
"DOC501", # docstring-missing-exception
# We have some Pascal case module names
"N999", # pep8-naming: Invalid module name
# Print are used as debug logs
"T20", # flake8-print
# This is a relatively small, low contributors project. Git blame suffice.
"TD002", # missing-todo-author
# Python 3.11, introduced "zero cost" exception handling
"PERF203", # try-except-in-loop

### FIXME/TODO: I'd normally set them as temporarily warnings, but no warnings in Ruff yet:
### https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774):
"CPY001", # flake8-copyright
"PTH", # flake8-use-pathlib
# Ignore until linux support
"EXE", # flake8-executable
]

[tool.ruff.lint.per-file-ignores]
"typings/**/*.pyi" = [
"F811", # Re-exports false positives
"F821", # https://github.com/astral-sh/ruff/issues/3011
# The following can't be controlled for external libraries:
"A", # Shadowing builtin names
"FBT", # flake8-boolean-trap
"ICN001", # unconventional-import-alias
"N8", # Naming conventions
"PLC2701", # Private name import
"PLR0904", # Too many public methods
"PLR0913", # Argument count
"PLR0917", # Too many positional arguments
"PLW3201", # misspelled dunder method name
"PYI042", # CamelCase TypeAlias
]

# https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat
[tool.ruff.lint.flake8-implicit-str-concat]
allow-multiline = false

# https://docs.astral.sh/ruff/settings/#isort
[tool.ruff.lint.isort]
combine-as-imports = true
split-on-trailing-comma = false
# Unlike isort, Ruff only counts relative imports as local-folder by default for know.
# https://github.com/astral-sh/ruff/issues/3115
known-local-folder = [
"AutoControlledThread",
"AutoSplit",
"AutoSplitImage",
"capture_method",
"compare",
"error_messages",
"gen",
"hotkeys",
"menu_bar",
"region_selection",
"split_parser",
"user_profile",
"utils",
]

# https://docs.astral.sh/ruff/settings/#mccabe
[tool.ruff.lint.mccabe]
# Hard limit, arbitrary to 4 bytes
max-complexity = 31
# Arbitrary to 2 bytes, same as SonarLint
# max-complexity = 15

[tool.ruff.lint.pylint]
# Arbitrary to 1 byte, same as SonarLint
max-args = 7
# At least same as max-complexity
max-branches = 15

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"cv2.imread".msg = """\
it doesn't support special characters. Use `utils.imread` instead.
https://github.com/opencv/opencv/issues/4292#issuecomment-2266019697"""
"cv2.imwrite".msg = """\
it doesn't support special characters. Use `utils.imwrite` instead.
https://github.com/opencv/opencv/issues/4292#issuecomment-2266019697"""

# https://github.com/hhatto/autopep8#usage
# https://github.com/hhatto/autopep8#more-advanced-usage
[tool.autopep8]
max_line_length = 120
max_line_length = 100
aggressive = 3
exclude = ".venv/*,src/gen/*"
ignore = [
Expand All @@ -151,7 +12,7 @@ ignore = [
# Check for the "Fix" flag https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"E2", # Whitespace
"E3", # Blank lines
"E703", # useless-semicolon
"E703", # useless-semicolon
"E71", # Statement (comparisons)
"E731", # lambda-assignment
"W29", # Whitespace warning
Expand Down
154 changes: 154 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# SPDX-License-Identifier: MIT
# Copyright 2024 Beslogic Inc.

# The source skeleton for this configuration can be found at
# https://github.com/BesLogic/shared-configs/blob/main/ruff.toml
# Modifications to this file that are not project-specific should also be done upstream.
# These configs are incompatible with ruff<0.5.7

# https://docs.astral.sh/ruff/configuration/
target-version = "py310" # Change this to the oldest supported version by your application
line-length = 100
preview = true

[lint]
select = ["ALL"]
# https://docs.astral.sh/ruff/rules/
ignore = [
###
# Not needed or wanted
###
"D1", # pydocstyle Missing doctring
"D401", # pydocstyle: non-imperative-mood
"EM", # flake8-errmsg
"EXE", # flake8-executable
# This is often something we can't control: https://github.com/astral-sh/ruff/issues/9497
# Also false-positive with positional-only arguments: https://github.com/astral-sh/ruff/issues/3247
"FBT003", # flake8-boolean-trap: boolean-positional-value-in-call
"INP", # flake8-no-pep420
"ISC003", # flake8-implicit-str-concat: explicit-string-concatenation
# Short messages are still considered "long" messages
"TRY003", # tryceratops : raise-vanilla-args
# Don't remove commented code, also too inconsistant
"ERA001", # eradicate: commented-out-code
# contextlib.suppress is roughly 3x slower than try/except
"SIM105", # flake8-simplify: use-contextlib-suppress
# Negative performance impact and more verbose https://github.com/astral-sh/ruff/issues/7871
"UP038", # non-pep604-isinstance
# deprecated and is actually slower for cases relevant to unpacking: https://github.com/astral-sh/ruff/issues/12754
"UP027", # unpacked-list-comprehension
# Checked by type-checker (pyright/mypy)
"ANN", # flake-annotations
"PGH003", # blanket-type-ignore
"TCH", # flake8-type-checking
# Already shown by Pylance, checked by pyright, and can be caused by overloads.
"ARG002", # Unused method argument
# We want D213: multi-line-summary-second-line and D211: no-blank-line-before-class
"D203", # pydocstyle: one-blank-line-before-class
"D212", # pydocstyle: multi-line-summary-first-line
# Allow differentiating between broken (FIXME) and to be done/added/completed (TODO)
"TD001", # flake8-todos: invalid-todo-tag

###
# These should be warnings (https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774)
###
"FIX", # flake8-fixme
# Not all TODOs are worth an issue, this would be better as a warning
"TD003", # flake8-todos: missing-todo-link

# False-positives
"TCH004", # https://github.com/astral-sh/ruff/issues/3821

###
# Conflict with formatter (you can remove this section if you don't use Ruff as a formatter)
###
# "COM812", # missing-trailing-comma
# "ISC001", # single-line-implicit-string-concatenation

###
# Rules about missing special documentation. Up to you if you wanna enable these, you must also disable D406, D407
###
"DOC201", # docstring-missing-returns
"DOC402", # docstring-missing-yields
"DOC501", # docstring-missing-exception
# "D406", # new-line-after-section-name, conflicts with DOC
# "D407", # dashed-underline-after-section, conflicts with DOC

###
# Specific to this project
###
"D205", # Not all docstrings have a short description + desrciption
# TODO: Consider for more complete doc
"DOC201", # docstring-extraneous-returns
"DOC501", # docstring-missing-exception
# We have some Pascal case module names
"N999", # pep8-naming: Invalid module name
# Print are used as debug logs
"T20", # flake8-print
# This is a relatively small, low contributors project. Git blame suffice.
"TD002", # missing-todo-author
# Python 3.11, introduced "zero cost" exception handling
"PERF203", # try-except-in-loop

###
# FIXME/TODO: I'd normally set them as temporarily warnings, but no warnings in Ruff yet:
# https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774):
###
"CPY001", # flake8-copyright
"PTH", # flake8-use-pathlib
# Ignore until linux support
"EXE", # flake8-executable
]

# https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat
[lint.flake8-implicit-str-concat]
allow-multiline = false

# https://docs.astral.sh/ruff/settings/#isort
[lint.isort]
combine-as-imports = true
split-on-trailing-comma = false
# This should be automatically detected in src layout, but somehow pre-commit messes it up
known-first-party = ["gen"]

# https://docs.astral.sh/ruff/settings/#mccabe
[lint.mccabe]
# Arbitrary to 2 bytes, same as SonarLint
max-complexity = 15

[lint.pylint]
# Arbitrary to 1 byte, same as SonarLint
max-args = 7
# At least same as max-complexity
max-branches = 15

[lint.per-file-ignores]
"**/typings/**/*.pyi" = [
"F811", # Re-exports false positives
# The following can't be controlled for external libraries:
"A", # Shadowing builtin names
"E741", # ambiguous variable name
"F403", # `from . import *` used; unable to detect undefined names
"FBT", # flake8-boolean-trap
"ICN001", # unconventional-import-alias
"N8", # Naming conventions
"PLC2701", # Private name import
"PLR0904", # Too many public methods
"PLR0913", # Argument count
"PLR0917", # Too many positional arguments
"PLW3201", # misspelled dunder method name
"PYI042", # CamelCase TypeAlias
# Stubs can sometimes re-export entire modules.
# Issues with using a star-imported name will be caught by type-checkers.
"F405", # may be undefined, or defined from star imports
]

[lint.flake8-tidy-imports.banned-api]
"cv2.imread".msg = """\
it doesn't support special characters. \
Use `cv2.imdecode(np.fromfile(filename, dtype=np.uint8), flags)` instead.
https://github.com/opencv/opencv/issues/4292#issuecomment-2266019697"""
"cv2.imwrite".msg = """\
it doesn't support special characters. \
Use `cv2.imencode(os.path.splitext(filename)[1], img)[1].tofile(filename)` instead.
https://github.com/opencv/opencv/issues/4292#issuecomment-2266019697"""
2 changes: 1 addition & 1 deletion scripts/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Linters & Formatters
add-trailing-comma>=3.1.0 # Must match .pre-commit-config.yaml
autopep8>=2.3.1 # Must match .pre-commit-config.yaml
ruff>=0.5.6 # New checks # Must match .pre-commit-config.yaml
ruff>=0.6.1 # Pre-commit fix # Must match .pre-commit-config.yaml
#
# Types
types-D3DShot ; sys_platform == 'win32'
Expand Down
Loading
Loading