mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
### Description `lintrunner` is a linter runner successfully used by pytorch, onnx and onnx-script. It provides a uniform experience running linters locally and in CI. It supports all major dev systems: Windows, Linux and MacOs. The checks are enforced by the `Python format` workflow. This PR adopts `lintrunner` to onnxruntime and fixed ~2000 flake8 errors in Python code. `lintrunner` now runs all required python lints including `ruff`(replacing `flake8`), `black` and `isort`. Future lints like `clang-format` can be added. Most errors are auto-fixed by `ruff` and the fixes should be considered robust. Lints that are more complicated to fix are applied `# noqa` for now and should be fixed in follow up PRs. ### Notable changes 1. This PR **removed some suboptimal patterns**: - `not xxx in` -> `xxx not in` membership checks - bare excepts (`except:` -> `except Exception`) - unused imports The follow up PR will remove: - `import *` - mutable values as default in function definitions (`def func(a=[])`) - more unused imports - unused local variables 2. Use `ruff` to replace `flake8`. `ruff` is much (40x) faster than flake8 and is more robust. We are using it successfully in onnx and onnx-script. It also supports auto-fixing many flake8 errors. 3. Removed the legacy flake8 ci flow and updated docs. 4. The added workflow supports SARIF code scanning reports on github, example snapshot:  5. Removed `onnxruntime-python-checks-ci-pipeline` as redundant ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> Unified linting experience in CI and local. Replacing https://github.com/microsoft/onnxruntime/pull/14306 --------- Signed-off-by: Justin Chu <justinchu@microsoft.com>
79 lines
2.2 KiB
TOML
79 lines
2.2 KiB
TOML
[tool.black]
|
|
line-length = 120
|
|
# NOTE: Do not extend the exclude list. Edit .lintrunner.toml instead
|
|
extend-exclude = "cmake|onnxruntime/core/flatbuffers/"
|
|
target-version = ["py37", "py38", "py39", "py310", "py311"]
|
|
|
|
[tool.isort]
|
|
# NOTE: Do not extend the exclude list. Edit .lintrunner.toml instead
|
|
profile = "black"
|
|
line_length = 120
|
|
extend_skip_glob = [
|
|
"cmake/*",
|
|
"orttraining/*",
|
|
"onnxruntime/core/flatbuffers/*",
|
|
]
|
|
|
|
[tool.pydocstyle]
|
|
convention = "google"
|
|
|
|
[tool.pylint.BASIC]
|
|
good-names = [
|
|
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
|
|
"p", "q", "r", "s", "t", "u", "v", "w", "ex", "Run", "_", "x", "y", "z"
|
|
]
|
|
|
|
[tool.pylint.messages_control]
|
|
disable = [
|
|
"format",
|
|
"line-too-long",
|
|
"import-error",
|
|
"no-name-in-module",
|
|
"no-member",
|
|
"too-many-arguments",
|
|
"too-many-locals",
|
|
"too-few-public-methods",
|
|
"missing-docstring",
|
|
"fixme",
|
|
]
|
|
|
|
[tool.pyright]
|
|
exclude = ["onnxruntime/core/flatbuffers/*"]
|
|
reportMissingImports = false
|
|
|
|
[tool.ruff]
|
|
# NOTE: Do not create an exclude list. Edit .lintrunner.toml instead
|
|
target-version = "py37"
|
|
select = [
|
|
"E", # pycodestyle
|
|
"F", # Pyflakes
|
|
"W", # pycodestyle
|
|
"B", # flake8-bugbear
|
|
"N", # pep8-naming
|
|
"YTT", # flake8-2020
|
|
"RUF", # Ruff-specific rules
|
|
"SIM", # flake8-simplify
|
|
"UP", # pyupgrade
|
|
]
|
|
# NOTE: Refrain from growing the ignore list unless for exceptional cases.
|
|
# Always include a comment to explain why.
|
|
ignore = [
|
|
"E501", # Line length controlled by black
|
|
"N803", # Argument casing
|
|
"N812", # Allow import torch.nn.functional as F
|
|
"N999", # Module names
|
|
"SIM102", # We don't perfer always combining if branches
|
|
"SIM108", # We don't encourage ternary operators
|
|
"SIM114", # Don't combine if branches for debugability
|
|
"SIM116", # Don't use dict lookup to replace if-else
|
|
]
|
|
ignore-init-module-imports = true
|
|
unfixable = [
|
|
"F401", # Unused imports
|
|
]
|
|
|
|
[tool.ruff.per-file-ignores]
|
|
# NOTE: Refrain from growing the ignore list unless for exceptional cases.
|
|
# Prefer inline ignores with `noqa: xxx`.
|
|
# Eventually this list should become empty.
|
|
"orttraining/orttraining/test/**" = ["N802"] # Function casing
|