Skip to content

Commit

Permalink
Migrate to same linting and formatting as in aiida-core
Browse files Browse the repository at this point in the history
We migrate to ruff for the linter and formatter with the settings of
aiida-core as well as the pre-commit hooks used for formatting. This
makes the repository more compatible with aiida-core and also allows
solves more linter problems automatically which should speed up
development
  • Loading branch information
agoscinski committed Nov 20, 2024
1 parent b7a57cb commit e6ca8d2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 56 deletions.
89 changes: 52 additions & 37 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: mixed-line-ending
- id: trailing-whitespace
- id: check-json
- id: check-yaml

- repo: https://github.com/pycqa/isort
rev: '5.12.0'
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: '22.10.0'
hooks:
- id: black

- id: check-merge-conflict
- id: check-yaml
- id: double-quote-string-fixer
- id: end-of-file-fixer
exclude: &exclude_pre_commit_hooks >
(?x)^(
tests/.*(?<!\.py)$|
docs/source/.+\.aiida/repo/.+|
CHANGELOG.md|
)$
- id: fix-encoding-pragma
args: [--remove]
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
exclude: *exclude_pre_commit_hooks
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
Expand All @@ -34,25 +34,40 @@ repos:
tests/.*|
conftest.py
)$
- repo: https://github.com/PyCQA/pylint
rev: v3.2.2
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.6
hooks:
- id: pylint
additional_dependencies:
- aiida-core~=2.0
- fastapi~=0.115.5
- uvicorn[standard]~=0.19.0
- pydantic~=2.0
- graphene~=3.0
- lark
- python-dateutil~=2.0
- python-jose
- python-multipart
- passlib
- pytest~=3.6,<5.0.0
- sphinx<4
exclude: >
- id: check-github-workflows

- repo: https://github.com/ikamensh/flynt/
rev: 1.0.1
hooks:
- id: flynt
args: [--line-length=120, --fail-on-change]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
- id: ruff-format
exclude: &exclude_ruff >
(?x)^(
docs/.*|
docs/source/topics/processes/include/snippets/functions/parse_docstring_expose_ipython.py|
docs/source/topics/processes/include/snippets/functions/signature_plain_python_call_illegal.py|
)$
- id: ruff
exclude: *exclude_ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.13.0
hooks:
- id: pretty-format-toml
args: [--autofix]
- id: pretty-format-yaml
args: [--autofix]
exclude: >-
(?x)^(
tests/.*|
environment.yml|
)$
48 changes: 29 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,36 @@ exclude = [
'codecov.yml',
]

[tool.isort]
profile = 'black'

[tool.pylint.master]
extension-pkg-whitelist = ['pydantic']

[tool.pylint.format]
max-line-length = 125

[tool.pylint.messages_control]
disable = [
'duplicate-code',
'fixme',
'invalid-name',
'too-many-ancestors',
'too-many-arguments',
[tool.ruff]
line-length = 120

[tool.ruff.format]
quote-style = 'single'

[tool.ruff.lint]
ignore = [
'F403', # Star imports unable to detect undefined names
'F405', # Import may be undefined or defined from star imports
'PLR0911', # Too many return statements
'PLR0912', # Too many branches
'PLR0913', # Too many arguments in function definition
'PLR0915', # Too many statements
'PLR2004', # Magic value used in comparison
'RUF005', # Consider iterable unpacking instead of concatenation
'RUF012', # Mutable class attributes should be annotated with `typing.ClassVar`
]
select = [
'E', # pydocstyle
'W', # pydocstyle
'F', # pyflakes
'I', # isort
'N', # pep8-naming
'PLC', # pylint-convention
'PLE', # pylint-error
'PLR', # pylint-refactor
'PLW', # pylint-warning
'RUF' # ruff
]

[tool.pylint.similarities]
ignore-imports = 'yes'

[tool.pytest.ini_options]
python_files = 'test_*.py example_*.py'
Expand Down

0 comments on commit e6ca8d2

Please sign in to comment.