Skip to content

Commit

Permalink
Dependencies: Switch to using ruff for linting and formatting
Browse files Browse the repository at this point in the history
`ruff` replaces `yapf`, `isort` and `pylint` as it is much faster
than all these three tools combined.
  • Loading branch information
sphuber committed Feb 26, 2024
1 parent 090e475 commit 492438f
Show file tree
Hide file tree
Showing 88 changed files with 690 additions and 806 deletions.
9 changes: 6 additions & 3 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 All @@ -30,7 +33,7 @@ def get_version_from_module(content: str) -> str:
args = parser.parse_args()
TAG_PREFIX = 'refs/tags/v'
assert args.GITHUB_REF.startswith(TAG_PREFIX), f'GITHUB_REF should start with "{TAG_PREFIX}": {args.GITHUB_REF}'
tag_version = args.GITHUB_REF[len(TAG_PREFIX):]
tag_version = args.GITHUB_REF[len(TAG_PREFIX) :]
package_version = get_version_from_module(Path('aiida_common_workflows/__init__.py').read_text(encoding='utf-8'))
error_message = f'The tag version `{tag_version}` is different from the package version `{package_version}`'
assert tag_version == package_version, error_message
27 changes: 6 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,9 @@ 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.31.0
hooks:
- id: yapf
name: yapf
types: [python]
args: ['-i']
additional_dependencies: ['toml']

- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
types: [python]
language: system
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
hooks:
- id: ruff-format
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
6 changes: 1 addition & 5 deletions aiida_common_workflows/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# -*- coding: utf-8 -*-
# pylint: disable=wrong-import-position,wildcard-import

"""Module for the command line interface."""
import click_completion

# Activate the completion of parameter types provided by the click_completion package
click_completion.init()

from .launch import cmd_launch
from .plot import cmd_plot
from .root import cmd_root
96 changes: 68 additions & 28 deletions aiida_common_workflows/cli/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"""Commands to launch common workflows."""
import functools

from aiida.cmdline.params import types
import click
from aiida.cmdline.params import types

from aiida_common_workflows.plugins import get_workflow_entry_point_names, load_workflow_entry_point

Expand Down Expand Up @@ -41,7 +41,7 @@ def cmd_launch():
@options.CODES()
@options.PROTOCOL(
type=click.Choice(['fast', 'moderate', 'precise', 'verification-PBE-v1', 'verification-PBE-v1-sirius']),
default='fast'
default='fast',
)
@options.RELAX_TYPE()
@options.ELECTRONIC_TYPE()
Expand All @@ -57,10 +57,25 @@ def cmd_launch():
@options.REFERENCE_WORKCHAIN()
@options.ENGINE_OPTIONS()
@click.option('--show-engines', is_flag=True, help='Show information on the required calculation engines.')
def cmd_relax( # pylint: disable=too-many-branches
plugin, structure, codes, protocol, relax_type, electronic_type, spin_type, threshold_forces, threshold_stress,
number_machines, number_mpi_procs_per_machine, number_cores_per_mpiproc, wallclock_seconds, daemon,
magnetization_per_site, reference_workchain, engine_options, show_engines
def cmd_relax( # noqa: PLR0912,PLR0913,PLR0915
plugin,
structure,
codes,
protocol,
relax_type,
electronic_type,
spin_type,
threshold_forces,
threshold_stress,
number_machines,
number_mpi_procs_per_machine,
number_cores_per_mpiproc,
wallclock_seconds,
daemon,
magnetization_per_site,
reference_workchain,
engine_options,
show_engines,
):
"""Relax a crystal structure using the common relax workflow for one of the existing plugin implementations.
Expand All @@ -69,7 +84,7 @@ def cmd_relax( # pylint: disable=too-many-branches
If no code is installed for at least one of the calculation engines, the command will fail.
Use the `--show-engine` flag to display the required calculation engines for the selected plugin workflow.
"""
# pylint: disable=too-many-locals,too-many-statements

process_class = load_workflow_entry_point('relax', plugin)
generator = process_class.get_input_generator()

Expand All @@ -81,19 +96,19 @@ def cmd_relax( # pylint: disable=too-many-branches
if len(number_machines) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--number-machines'
param_hint='--number-machines',
)

if number_mpi_procs_per_machine is not None and len(number_mpi_procs_per_machine) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--number-mpi-procs-per-machine'
param_hint='--number-mpi-procs-per-machine',
)

if number_cores_per_mpiproc is not None and len(number_cores_per_mpiproc) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--number-cores-per-mpiproc'
param_hint='--number-cores-per-mpiproc',
)

if wallclock_seconds is None:
Expand All @@ -102,7 +117,7 @@ def cmd_relax( # pylint: disable=too-many-branches
if len(wallclock_seconds) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--wallclock-seconds'
param_hint='--wallclock-seconds',
)

if not generator.is_valid_protocol(protocol):
Expand Down Expand Up @@ -195,10 +210,24 @@ def cmd_relax( # pylint: disable=too-many-branches
@options.MAGNETIZATION_PER_SITE()
@options.ENGINE_OPTIONS()
@click.option('--show-engines', is_flag=True, help='Show information on the required calculation engines.')
def cmd_eos( # pylint: disable=too-many-branches,too-many-statements
plugin, structure, codes, protocol, relax_type, electronic_type, spin_type, threshold_forces, threshold_stress,
number_machines, number_mpi_procs_per_machine, number_cores_per_mpiproc, wallclock_seconds, daemon,
magnetization_per_site, engine_options, show_engines
def cmd_eos( # noqa: PLR0912,PLR0913,PLR0915
plugin,
structure,
codes,
protocol,
relax_type,
electronic_type,
spin_type,
threshold_forces,
threshold_stress,
number_machines,
number_mpi_procs_per_machine,
number_cores_per_mpiproc,
wallclock_seconds,
daemon,
magnetization_per_site,
engine_options,
show_engines,
):
"""Compute the equation of state of a crystal structure using the common relax workflow.
Expand All @@ -207,7 +236,7 @@ def cmd_eos( # pylint: disable=too-many-branches,too-many-statements
If no code is installed for at least one of the calculation engines, the command will fail.
Use the `--show-engine` flag to display the required calculation engines for the selected plugin workflow.
"""
# pylint: disable=too-many-locals

from aiida_common_workflows.plugins import get_entry_point_name_from_class
from aiida_common_workflows.workflows.eos import EquationOfStateWorkChain

Expand All @@ -222,19 +251,19 @@ def cmd_eos( # pylint: disable=too-many-branches,too-many-statements
if len(number_machines) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--number-machines'
param_hint='--number-machines',
)

if number_mpi_procs_per_machine is not None and len(number_mpi_procs_per_machine) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--number-mpi-procs-per-machine'
param_hint='--number-mpi-procs-per-machine',
)

if number_cores_per_mpiproc is not None and len(number_cores_per_mpiproc) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--number-cores-per-mpiproc'
param_hint='--number-cores-per-mpiproc',
)

if wallclock_seconds is None:
Expand All @@ -243,7 +272,7 @@ def cmd_eos( # pylint: disable=too-many-branches,too-many-statements
if len(wallclock_seconds) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--wallclock-seconds'
param_hint='--wallclock-seconds',
)

if not generator.is_valid_protocol(protocol):
Expand Down Expand Up @@ -332,10 +361,21 @@ def cmd_eos( # pylint: disable=too-many-branches,too-many-statements
@options.MAGNETIZATION_PER_SITE()
@options.ENGINE_OPTIONS()
@click.option('--show-engines', is_flag=True, help='Show information on the required calculation engines.')
def cmd_dissociation_curve( # pylint: disable=too-many-branches
plugin, structure, codes, protocol, electronic_type, spin_type, number_machines, number_mpi_procs_per_machine,
def cmd_dissociation_curve( # noqa: PLR0912, PLR0913
plugin,
structure,
codes,
protocol,
electronic_type,
spin_type,
number_machines,
number_mpi_procs_per_machine,
number_cores_per_mpiproc,
wallclock_seconds, daemon, magnetization_per_site, engine_options, show_engines
wallclock_seconds,
daemon,
magnetization_per_site,
engine_options,
show_engines,
):
"""Compute the dissociation curve of a diatomic molecule using the common relax workflow.
Expand All @@ -347,7 +387,7 @@ def cmd_dissociation_curve( # pylint: disable=too-many-branches
If no code is installed for at least one of the calculation engines, the command will fail.
Use the `--show-engine` flag to display the required calculation engines for the selected plugin workflow.
"""
# pylint: disable=too-many-locals

from aiida_common_workflows.plugins import get_entry_point_name_from_class
from aiida_common_workflows.workflows.dissociation import DissociationCurveWorkChain
from aiida_common_workflows.workflows.relax.generator import RelaxType
Expand All @@ -363,19 +403,19 @@ def cmd_dissociation_curve( # pylint: disable=too-many-branches
if len(number_machines) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--number-machines'
param_hint='--number-machines',
)

if number_mpi_procs_per_machine is not None and len(number_mpi_procs_per_machine) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--number-mpi-procs-per-machine'
param_hint='--number-mpi-procs-per-machine',
)

if number_cores_per_mpiproc is not None and len(number_cores_per_mpiproc) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--number-cores-per-mpiproc'
param_hint='--number-cores-per-mpiproc',
)

if wallclock_seconds is None:
Expand All @@ -384,7 +424,7 @@ def cmd_dissociation_curve( # pylint: disable=too-many-branches
if len(wallclock_seconds) != number_engines:
raise click.BadParameter(
f'{process_class.__name__} has {number_engines} engine steps, so requires {number_engines} values',
param_hint='--wallclock-seconds'
param_hint='--wallclock-seconds',
)

if not generator.is_valid_protocol(protocol):
Expand Down
Loading

0 comments on commit 492438f

Please sign in to comment.