-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add pre-commit hooks with ruff formatter/linter rules #26
Changes from all commits
6d659d7
a3c72aa
d4ab67a
012a7a8
2510fce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.1.5 | ||
hooks: | ||
- id: ruff # Run the linter | ||
args: [ --fix ] | ||
types_or: [ python, pyi, jupyter ] | ||
- id: ruff-format # Run the formatter | ||
types_or: [ python, pyi, jupyter ] | ||
|
||
# https://pre-commit.ci/#configuration | ||
ci: | ||
autofix_prs: true | ||
autoupdate_schedule: quarterly | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[tool.ruff.format] | ||
# https://docs.astral.sh/ruff/settings/#format | ||
line-ending = "lf" # Use UNIX `\n` line endings for all files | ||
|
||
[tool.ruff.lint] | ||
# https://docs.astral.sh/ruff/rules/ | ||
select = [ | ||
"E", # pycodestyle errors | ||
"F", # pyflakes | ||
"I", # isort | ||
"NPY", # numpy | ||
"PL", # pylint | ||
"UP", # pyupgrade | ||
"W", # pycodestyle warnings | ||
] | ||
Comment on lines
+5
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know if these rules from https://docs.astral.sh/ruff/rules are too much or too little! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good to me for now. We can always adapt if we want more or someone feels slowed down by any of the linters. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
- https://lightning.ai/docs/pytorch/2.1.0/cli/lightning_cli.html | ||
- https://pytorch-lightning.medium.com/introducing-lightningcli-v2-supercharge-your-training-c070d43c7dd6 | ||
""" | ||
import torch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See example commit 012a7a8 where |
||
from lightning.pytorch.cli import ArgsType, LightningCLI | ||
|
||
from src.datamodule import BaseDataModule | ||
|
@@ -34,6 +33,7 @@ def cli_main( | |
trainer_defaults=trainer_defaults, | ||
args=args, | ||
) | ||
return cli | ||
|
||
|
||
# %% | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have set-up pre-commit.ci GitHub App to fix lint/formatting errors in Pull Requests by default, but we can disable this if it gets annoying.
Also,
pre-commit autoupdate
will be ran quarterly (default is weekly, but that might get noisy).Extra configs can be found at https://pre-commit.ci/#configuration