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

Ruff linter #537

Open
wants to merge 1 commit into
base: main
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
name: Pre-Commit Checks
name: Linting

on:
pull_request:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

jobs:
pre-commit:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
- name: Install requirements
run: |
pip install -U pip
pip install pylint
pip install -U black
pip install .[dev]
pip install wandb
pip install tqdm
- name: Run black
run: |
python -m black .
- uses: pre-commit/[email protected]

- name: Cache pre-commit environment
uses: actions/cache@v3
with:
path: |
~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ runner.os }}-pre-commit

- name: Install dependencies
run: pip install pre-commit

- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure
46 changes: 5 additions & 41 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,9 @@ repos:
- id: trailing-whitespace
exclude: *exclude_files

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
hooks:
- id: black
name: Black Formating
exclude: *exclude_files

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: Sort imports
exclude: *exclude_files

- repo: https://github.com/PyCQA/pylint
rev: pylint-2.5.2
hooks:
- id: pylint
language: system
args: [
'--disable=line-too-long',
'--disable=no-member',
'--disable=missing-module-docstring',
'--disable=missing-class-docstring',
'--disable=missing-function-docstring',
'--disable=too-many-arguments',
'--disable=too-many-positional-arguments',
'--disable=too-many-locals',
'--disable=not-callable',
'--disable=logging-fstring-interpolation',
'--disable=logging-not-lazy',
'--disable=invalid-name',
'--disable=too-few-public-methods',
'--disable=too-many-instance-attributes',
'--disable=too-many-statements',
'--disable=too-many-branches',
'--disable=import-outside-toplevel',
'--disable=cell-var-from-loop',
'--disable=duplicate-code',
'--disable=use-dict-literal',
]
exclude: *exclude_files
- id: ruff
args: [ --fix]
- id: ruff-format
98 changes: 67 additions & 31 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,73 @@ requires = [
]
build-backend = "setuptools.build_meta"

# Make isort compatible with black
[tool.isort]
profile = "black"

# Pylint
[tool.pylint.'MESSAGES CONTROL']
disable = [
"line-too-long",
"no-member",
"missing-module-docstring",
"missing-class-docstring",
"missing-function-docstring",
"too-many-arguments",
"too-many-locals",
"not-callable",
"logging-fstring-interpolation",
"logging-not-lazy",
"logging-too-many-args",
"invalid-name",
"too-few-public-methods",
"too-many-instance-attributes",
"too-many-statements",
"too-many-branches",
"import-outside-toplevel",
"cell-var-from-loop",
"duplicate-code",
"use-dict-literal",
]

[tool.pylint.MASTER]
ignore-paths = [
[tool.ruff]
target-version = "py37"
line-length = 120
exclude = [
"^mace/tools/torch_geometric/.*$",
"^mace/tools/scatter.py$",
]

[tool.ruff.lint]
select = ["ALL"]
ignore = [
# Rule families
"ANN", # flake8-annotations (not ready, require types for ALL args)
"ARG", # Check for unused function arguments
"BLE", # General catch of Exception
"C90", # Check for functions with a high McCabe complexity
"COM", # flake8-commas (conflict with line wrapper)
"CPY", # Missing copyright notice at top of file (need preview mode)
"D", # pydocstyle
"EM", # Format nice error messages
"ERA", # Check for commented-out code
"FIX", # Check for FIXME, TODO and other developer notes
"FURB", # refurb (need preview mode, too many preview errors)
"G", # validate logging format strings
"INP", # Ban PEP-420 implicit namespace packages
"N", # pep8-naming (many var/arg names are intended)
"NPY", # NumPy-specific rules (TODO: enable this)
"PTH", # Prefer pathlib over os.path
"S", # flake8-bandit (TODO: enable this)
"SLF", # Access "private" class members
"T20", # Check for print/pprint
"TD", # TODO tags related

# Single rules
"B023", # Function definition does not bind loop variable
"B028", # No explicit stacklevel keyword argument found
"B904", # Within an except clause, raise exceptions with ...
"C408", # unnecessary-collection-call
"D105", # Missing docstring in magic method
"D205", # 1 blank line required between summary line and description
"D212", # Multi-line docstring summary should start at the first line
"DTZ003", # TODO: fix this (issue #3791)
"E501", # Line too long
"FBT001", # Boolean-typed positional argument in function definition
"FBT002", # Boolean default positional argument in function
"ISC001", # Ignore for purpose of auto formatting
"N801", # Invalid Name
"PD901", # pandas-df-variable-name
"PERF203", # try-except-in-loop
"PERF401", # manual-list-comprehension
"PLR0911", # too many return statements
"PLR0912", # too many branches
"PLR0913", # too many arguments
"PLR0915", # too many statements
"PLR2004", # magic values in comparison
"PLW2901", # Outer for loop variable overwritten by inner assignment target
"PT013", # pytest-incorrect-pytest-import
"PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple`
"RET505", # Unnecessary `else` after `return` statement
"SIM105", # Use contextlib.suppress() instead of try-except-pass
"TRY003", # Avoid specifying long messages outside the exception class
"TRY300", # Checks for return statements in try blocks
"TRY301", # Checks for raise statements within try blocks
]
pydocstyle.convention = "google"

[tool.isort]
split-on-trailing-comma = false
required-imports = ["from __future__ import annotations"]
skip = ["__init__.py"]
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ console_scripts =
wandb = wandb
fpsample = fpsample
dev =
black
isort
ruff
mypy
pre-commit
pytest
pylint
schedulefree = schedulefree
Loading