Skip to content

Commit

Permalink
Pre-commit: Switch to ruff for linting and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sphuber committed Dec 22, 2023
1 parent a4face2 commit ff01083
Show file tree
Hide file tree
Showing 45 changed files with 269 additions and 278 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/validate_release_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ def get_version_from_module(content: str) -> str:

try:
return next(
ast.literal_eval(statement.value) for statement in module.body if isinstance(statement, ast.Assign)
for target in statement.targets if isinstance(target, ast.Name) and target.id == '__version__'
ast.literal_eval(statement.value)
for statement in module.body
if isinstance(statement, ast.Assign)
for target in statement.targets
if isinstance(target, ast.Name) and target.id == '__version__'
)
except StopIteration as exception:
raise IOError('Unable to find the `__version__` attribute in the module.') from exception
Expand Down
44 changes: 11 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,14 @@ repos:
hooks:
- id: flynt

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

- repo: https://github.com/pre-commit/mirrors-yapf
rev: 'v0.32.0'
hooks:
- id: yapf
name: yapf
types: [python]
args: ['-i']
additional_dependencies: ['toml']
exclude: &exclude_files >
(?x)^(
docs/.*|
)$

- repo: https://github.com/PyCQA/pydocstyle
rev: '6.1.1'
hooks:
- id: pydocstyle
additional_dependencies: ['toml']
exclude: *exclude_files

- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
types: [python]
language: system
exclude: *exclude_files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
hooks:
- id: ruff-format
exclude: &exclude_files >
(?x)^(
docs/.*|
)$
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
exclude: *exclude_files
62 changes: 26 additions & 36 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ docs = [
]
pre-commit = [
'pre-commit~=2.2',
'pylint==2.15.5',
'pylint-aiida~=0.1',
]
tests = [
'pgtest~=1.3',
Expand Down Expand Up @@ -84,32 +82,6 @@ exclude = [
line-length = 120
fail-on-change = true

[tool.isort]
force_sort_within_sections = true
include_trailing_comma = true
line_length = 120
multi_line_output = 3

[tool.pydocstyle]
ignore = [
'D104',
'D202',
'D203',
'D213'
]

[tool.pylint.master]
load-plugins = ['pylint_aiida']

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

[tool.pylint.messages_control]
disable = [
'duplicate-code',
'import-outside-toplevel',
'too-many-arguments',
]

[tool.pytest.ini_options]
filterwarnings = [
Expand All @@ -120,11 +92,29 @@ testpaths = [
'tests',
]

[tool.yapf]
align_closing_bracket_with_visual_indent = true
based_on_style = 'google'
coalesce_brackets = true
column_limit = 120
dedent_closing_brackets = true
indent_dictionary_value = false
split_arguments_when_comma_terminated = true
[tool.ruff]
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
]
line-length = 120
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.ruff.format]
quote-style = 'single'
8 changes: 4 additions & 4 deletions src/aiida_pseudo/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""Module for the command line interface."""
from .family import cmd_family
from .install import cmd_install, cmd_install_family, cmd_install_pseudo_dojo, cmd_install_sssp
from .list import cmd_list
from .root import cmd_root
from .family import cmd_family # noqa: F401
from .install import cmd_install, cmd_install_family, cmd_install_pseudo_dojo, cmd_install_sssp # noqa: F401
from .list import cmd_list # noqa: F401
from .root import cmd_root # noqa: F401
18 changes: 11 additions & 7 deletions src/aiida_pseudo/cli/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"""Commands to inspect or modify the contents of pseudo potential families."""
import json

import click
from aiida.cmdline.params import options as options_core
from aiida.cmdline.utils import decorators, echo
import click

from .params import arguments, options, types
from .root import cmd_root
Expand All @@ -28,7 +28,6 @@ def cmd_family_show(family, stringency, unit, raw):
from ..groups.mixins import RecommendedCutoffMixin

if isinstance(family, RecommendedCutoffMixin):

try:
family.validate_stringency(stringency)
except ValueError as exception:
Expand All @@ -37,10 +36,15 @@ def cmd_family_show(family, stringency, unit, raw):
unit = unit or family.get_cutoffs_unit(stringency)

headers = ['Element', 'Pseudo', 'MD5', f'Wavefunction ({unit})', f'Charge density ({unit})']
rows = [[
pseudo.element, pseudo.filename, pseudo.md5,
*family.get_recommended_cutoffs(elements=pseudo.element, stringency=stringency, unit=unit)
] for pseudo in family.nodes]
rows = [
[
pseudo.element,
pseudo.filename,
pseudo.md5,
*family.get_recommended_cutoffs(elements=pseudo.element, stringency=stringency, unit=unit),
]
for pseudo in family.nodes
]
else:
headers = ['Element', 'Pseudo', 'MD5']
rows = [[pseudo.element, pseudo.filename, pseudo.md5] for pseudo in family.nodes]
Expand All @@ -64,7 +68,7 @@ def cmd_family_cutoffs():
@options.STRINGENCY(required=True)
@options.UNIT()
@decorators.with_dbenv()
def cmd_family_cutoffs_set(family, cutoffs, stringency, unit): # noqa: D301
def cmd_family_cutoffs_set(family, cutoffs, stringency, unit):
"""Set the recommended cutoffs for a pseudo potential family and a specified stringency.
The cutoffs should be provided as a JSON file through the argument `CUTOFFS` which should have the structure:
Expand Down
Loading

0 comments on commit ff01083

Please sign in to comment.