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

rfe: Introuce ruff-pre-commit #4139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
32 changes: 16 additions & 16 deletions .ci/cfg-lint-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@


def cfg_lint_check():
print('Running cfg lint check...')
print("Running cfg lint check...")
exit_code = 0
for file in sys.argv[1:]:
status_code = 0
blank_line = 0
cfg_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
os.pardir, file))
with open(cfg_path, 'r') as f:
cfg_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), os.pardir, file)
)
with open(cfg_path, "r") as f:
contents = f.read()
for num, line in enumerate(contents.splitlines(), 1):
# Only strip whitespaces, handle other blank characters below
stripped_line = line.lstrip(' ')
blank_line = (blank_line + 1
if re.search(r'^\s*$', stripped_line) else 0)
stripped_line = line.lstrip(" ")
blank_line = blank_line + 1 if re.search(r"^\s*$", stripped_line) else 0
if blank_line >= 2:
print(f'{file}:{num}: Too many blank lines')
print(f"{file}:{num}: Too many blank lines")
status_code = 1
if re.search(r'\s$', line):
print(f'{file}:{num}: Trailing whitespaces')
if re.search(r"\s$", line):
print(f"{file}:{num}: Trailing whitespaces")
status_code = 1
if re.search(r'^\s', stripped_line):
print(f'{file}:{num}: Wrong indent(Unexpected blank characters')
if re.search(r"^\s", stripped_line):
print(f"{file}:{num}: Wrong indent(Unexpected blank characters")
status_code = 1
if (len(line) - len(stripped_line)) % 4:
print(f'{file}:{num}: Wrong indent(4x spaces mismatch)')
print(f"{file}:{num}: Wrong indent(4x spaces mismatch)")
status_code = 1
if not contents.endswith('\n'):
print(f'{file} Missing final newline')
if not contents.endswith("\n"):
print(f"{file} Missing final newline")
status_code = 1
exit_code = exit_code or status_code
sys.exit(exit_code)


if __name__ == '__main__':
if __name__ == "__main__":
cfg_lint_check()
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
pip install -r requirements-ci.txt
- name: Run inspekt
if: ${{ matrix.python-version > 3.6 }}
run: inspekt checkall --disable-style E501,E265,W601,E402,E722,E741 --disable-lint=W,R,C,E0601,E1002,E1101,E1103,E1120,F0401,I0011,I1101 --enable-lint W0611,W1201 --no-license-check
run: inspekt checkall --disable-style E203,E501,E265,W601,E402,E722,E741 --disable-lint=W,R,C,E0601,E1002,E1101,E1103,E1120,F0401,I0011,I1101 --enable-lint W0611,W1201 --no-license-check
- name: Run inspekt (py36)
if: ${{ matrix.python-version == 3.6 }}
run: inspekt checkall --disable-style E501,E265,W601,E402,E722,E741 --disable-lint=W,R,C,E0012,E0601,E1002,E1101,E1103,E1120,F0401,I0011,I1101 --enable-lint W0611,W1201 --no-license-check
run: inspekt checkall --disable-style E203,E501,E265,W601,E402,E722,E741 --disable-lint=W,R,C,E0012,E0601,E1002,E1101,E1103,E1120,F0401,I0011,I1101 --enable-lint W0611,W1201 --no-license-check
- run: echo "This job's status is ${{ job.status }}."

commitlint:
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ repos:
args: ["--fix=lf"]
- id: no-commit-to-branch
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.5
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format
36 changes: 36 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Same as Black.
line-length = 88
indent-width = 4

[lint]
select = [
# pycodestyle
"E",
"W",
# Pyflakes
"F",
# isort
"I",
# flake8-logging-format
"G",
# pylint Error
"PLE",
]
ignore = ["E203", "E402", "E501", "E722", "E741"]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
Loading
Loading