-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IDX-2719 - Add ruff linter for bazel smoke target
- Loading branch information
Enzo Desiage
committed
Apr 13, 2023
1 parent
45f3d07
commit ed78439
Showing
8 changed files
with
262 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euxo pipefail | ||
|
||
RUFF_PATH="$(readlink "$ruff_path")" | ||
REPO_PATH="$(dirname "$(readlink "$WORKSPACE")")" | ||
cd "$REPO_PATH" | ||
|
||
"$RUFF_PATH" check . --fix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
RUFF_PATH="$(readlink "$ruff_path")" | ||
REPO_PATH="$(dirname "$(readlink "$WORKSPACE")")" | ||
cd "$REPO_PATH" | ||
|
||
if ! "$RUFF_PATH" check . -q; then | ||
cat >&2 <<EOF | ||
[-] Linting Python files failed | ||
Please run the following command to fix it: | ||
$ bazel run //:ruff-format | ||
EOF | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
The module fetches ruff binary to be used by bazel smoke | ||
""" | ||
|
||
RUFF_BUILD = """ | ||
package(default_visibility = ["//visibility:public"]) | ||
exports_files(["ruff"]) | ||
""" | ||
|
||
VERSION = "0.0.260" | ||
SHA256 = { | ||
"aarch64-apple-darwin": "4e045df5e55f1e23b34910865fe66c8e9d4ea98dbdb5320fc8ff09b8c337d69e", | ||
"x86_64-apple-darwin": "3b251413bd5dfa60997489b33024b5f596cb3781f5cf3763529fb24cd97059c0", | ||
"x86_64-unknown-linux-gnu": "abb106ee7d1434faa733e6dd442b1d306fa32e0840fde24fbbf96c2289968c63", | ||
} | ||
|
||
URL = "https://github.com/charliermarsh/ruff/releases/download/v{version}/ruff-{platform}.tar.gz" | ||
|
||
def _ruff_impl(repository_ctx): | ||
os_arch = repository_ctx.os.arch | ||
|
||
if os_arch == "x86_64" or os_arch == "amd64": | ||
arch = "x86_64" | ||
elif os_arch == "aarch64": | ||
arch = "aarch64" | ||
else: | ||
fail("Unsupported architecture: '" + os_arch + "'") | ||
|
||
os_name = repository_ctx.os.name | ||
if os_name == "linux": | ||
platform = arch + "-unknown-linux-gnu" | ||
elif os_name == "mac os x": | ||
platform = arch + "-apple-darwin" | ||
|
||
else: | ||
fail("Unsupported operating system: " + os_name) | ||
|
||
if platform not in SHA256: | ||
fail("Unsupported platform: '" + platform + "'") | ||
|
||
repository_ctx.report_progress("Fetching " + repository_ctx.name) | ||
repository_ctx.download_and_extract(url = URL.format(version = VERSION, platform = platform), sha256 = SHA256[platform]) | ||
repository_ctx.file("BUILD.bazel", RUFF_BUILD, executable = True) | ||
|
||
_ruff = repository_rule( | ||
implementation = _ruff_impl, | ||
attrs = {}, | ||
) | ||
|
||
def ruff(name): | ||
_ruff(name = name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
[tool.ruff] | ||
unfixable = [] | ||
|
||
select = [ | ||
"C9", # Mccabe | ||
"F", # Pyflakes | ||
"I", # Isort | ||
"N", # Pep-8 naming | ||
"D", # Pydocstyle | ||
"E", # Pydocstyle error | ||
"W", # Pydocstyle warning | ||
] | ||
|
||
# Allow autofix for all enabled rules (when `--fix`) is provided. | ||
fixable = [ | ||
"A", | ||
"B", | ||
"C", | ||
"D", | ||
"E", | ||
"F", | ||
"G", | ||
"I", | ||
"N", | ||
"Q", | ||
"S", | ||
"T", | ||
"W", | ||
"ANN", | ||
"ARG", | ||
"BLE", | ||
"COM", | ||
"DJ", | ||
"DTZ", | ||
"EM", | ||
"ERA", | ||
"EXE", | ||
"FBT", | ||
"ICN", | ||
"INP", | ||
"ISC", | ||
"NPY", | ||
"PD", | ||
"PGH", | ||
"PIE", | ||
"PL", | ||
"PT", | ||
"PTH", | ||
"PYI", | ||
"RET", | ||
"RSE", | ||
"RUF", | ||
"SIM", | ||
"SLF", | ||
"TCH", | ||
"TID", | ||
"TRY", | ||
"UP", | ||
"YTT", | ||
] | ||
|
||
# Exclude a variety of commonly ignored directories. | ||
exclude = [ | ||
".bzr", | ||
".direnv", | ||
".eggs", | ||
".git", | ||
".hg", | ||
".mypy_cache", | ||
".nox", | ||
".pants.d", | ||
".pytype", | ||
".ruff_cache", | ||
".svn", | ||
".tox", | ||
".venv", | ||
"__pypackages__", | ||
"_build", | ||
"buck-out", | ||
"build", | ||
"dist", | ||
"node_modules", | ||
"venv", | ||
"env", | ||
] | ||
|
||
line-length = 120 | ||
|
||
# Allow unused variables when underscore-prefixed. | ||
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" | ||
|
||
target-version = "py37" | ||
|
||
ignore = [ | ||
"C901", | ||
"D10", | ||
"D100", | ||
"D101", | ||
"D102", | ||
"D103", | ||
"D104", | ||
"D107", | ||
"D202", | ||
"D203", | ||
"D205", | ||
"D212", | ||
"D400", | ||
"D401", | ||
"D407", | ||
"D415", | ||
"D416", | ||
"D417", | ||
"E402", | ||
"E501", | ||
"E501", | ||
"E713", | ||
"F403", | ||
"I001", | ||
"N801", | ||
"N802", | ||
"N803", | ||
"N804", | ||
"N805", | ||
"N806", | ||
"N818", | ||
"N999", | ||
] | ||
|
||
[tool.ruff.mccabe] | ||
# Unlike Flake8, default to a complexity level of 10. | ||
max-complexity = 10 | ||
|
||
[tool.isort] | ||
profile = "black" | ||
remove_redundant_aliases = true |