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

Added ruff to pre-commit #28

Merged
merged 1 commit into from
Jun 25, 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
78 changes: 42 additions & 36 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
repos:
# ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.9
hooks:
- id: ruff
types_or: [ python, pyi, jupyter ]
args: [ --fix ]
files: ^ads
exclude: ^docs/
- id: ruff-format
types_or: [ python, pyi, jupyter ]
exclude: ^docs/
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
exclude: ^docs/
- id: check-docstring-first
exclude: ^(docs/|tests/)
- id: check-json
- id: check-merge-conflict
- id: check-yaml
args: ['--allow-multiple-documents']
- id: detect-private-key
- id: end-of-file-fixer
- id: pretty-format-json
args: ['--autofix']
- id: trailing-whitespace
args: [ --markdown-linebreak-ext=md ]
exclude: ^docs/
# Black, the code formatter, natively supports pre-commit
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
exclude: ^docs/
- id: check-ast
exclude: ^docs/
- id: check-docstring-first
exclude: ^(docs/|tests/)
- id: check-json
- id: check-merge-conflict
- id: check-yaml
args: ['--allow-multiple-documents']
- id: detect-private-key
- id: end-of-file-fixer
- id: pretty-format-json
args: ['--autofix']
- id: trailing-whitespace
args: [ --markdown-linebreak-ext=md ]
exclude: ^docs/
# Regex based rst files common mistakes detector
- repo: https://github.com/pre-commit/pygrep-hooks
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
files: ^docs/
- id: rst-inline-touching-normal
files: ^docs/
- id: rst-backticks
files: ^docs/
- id: rst-inline-touching-normal
files: ^docs/
# Hardcoded secrets and ocids detector
- repo: https://github.com/gitleaks/gitleaks
- repo: https://github.com/gitleaks/gitleaks
rev: v8.17.0
hooks:
- id: gitleaks
- id: gitleaks
# Oracle copyright checker
- repo: https://github.com/oracle-samples/oci-data-science-ai-samples/
- repo: https://github.com/oracle-samples/oci-data-science-ai-samples/
rev: cbe0136
hooks:
- id: check-copyright
name: check-copyright
entry: .pre-commit-scripts/check-copyright.py
language: script
types_or: ['python', 'shell', 'bash']
exclude: ^docs/
- id: check-copyright
name: check-copyright
entry: .pre-commit-scripts/check-copyright.py
language: script
types_or: ['python', 'shell', 'bash']
exclude: ^docs/
42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,45 @@ oci-datascience = "oci_mlflow.deployment"

[project.entry-points."mlflow.request_auth_provider"]
oci-datascience = "oci_mlflow.auth_plugin:OCIMLFlowAuthRequestProvider"

# Configuring Ruff (https://docs.astral.sh/ruff/configuration/)
[tool.ruff]
fix = true

[tool.ruff.lint]
exclude = ["*.yaml", "*jinja2"]
# rules - https://docs.astral.sh/ruff/rules/
extend-ignore = ["E402", "N806", "N803"]
ignore = [
"S101", # use of assert
"B008", # function call in argument defaults
"B017", # pytest.raises considered evil
"B023", # function definition in loop (TODO: un-ignore this)
"B028", # explicit stacklevel for warnings
"C901", # function is too complex (TODO: un-ignore this)
"E501", # from scripts/lint_backend.sh
"PLR091", # complexity rules
"PLR2004", # magic numbers
"PLW2901", # `for` loop variable overwritten by assignment target
"SIM105", # contextlib.suppress (has a performance cost)
"SIM117", # multiple nested with blocks (doesn't look good with gr.Row etc)
"UP006", # use `list` instead of `List` for type annotations (fails for 3.8)
"UP007", # use X | Y for type annotations (TODO: can be enabled once Pydantic plays nice with them)
]
extend-select = [
"ARG",
"B",
"C",
"E",
"F",
"I",
"N",
"PL",
"S101",
"SIM",
"UP",
"W",
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mock
pip
pytest
pytest-codecov
ruff