Skip to content

Commit

Permalink
Update pre-commit to use ruff (#161)
Browse files Browse the repository at this point in the history
* Update pre-commit

* Apply ruff format

* Apply safe ruff check fixes

* Apply unsafe ruff check fixes

* Update ruff exclude

* Apply manual ruff check fixes

* Ignore ruff lowercase error

* Lower ruff requirement to match janus

* Update docs

* Remove pylint references
  • Loading branch information
ElliottKasoar authored Nov 20, 2024
1 parent c9cf893 commit 2fad7f1
Show file tree
Hide file tree
Showing 39 changed files with 234 additions and 268 deletions.
37 changes: 8 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,15 @@ repos:
- id: trailing-whitespace
- id: check-json

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.7
hooks:
- id: pyupgrade
args: ["--py39-plus"]

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile=black"]

- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
args: [--line-length=88]

- repo: local
hooks:
- id: pylint
language: system
types: [file, python]
name: pylint
description: "This hook runs the pylint static code analyzer"
exclude: &exclude_files >
(?x)^(
docs/.*|
)$
entry: pylint
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/numpy/numpydoc
rev: v1.6.0
Expand Down
4 changes: 1 addition & 3 deletions aiida_mlip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""
Machine learning interatomic potentials aiida plugin.
"""
"""Machine learning interatomic potentials aiida plugin."""

__version__ = "0.2.1"
4 changes: 1 addition & 3 deletions aiida_mlip/calculations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""
Calculations using MLIPs.
"""
"""Calculations using MLIPs."""
5 changes: 1 addition & 4 deletions aiida_mlip/calculations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import shutil

from ase.io import read, write

from aiida.common import InputValidationError, datastructures
import aiida.common.folders
from aiida.engine import CalcJob, CalcJobProcessSpec
import aiida.engine.processes
from aiida.orm import SinglefileData, Str, StructureData
from ase.io import read, write

from aiida_mlip.data.config import JanusConfigfile
from aiida_mlip.data.model import ModelData
Expand Down Expand Up @@ -186,7 +185,6 @@ def define(cls, spec: CalcJobProcessSpec) -> None:
message="Some output files missing or cannot be read",
)

# pylint: disable=too-many-locals
def prepare_for_submission(
self, folder: aiida.common.folders.Folder
) -> datastructures.CalcInfo:
Expand All @@ -203,7 +201,6 @@ def prepare_for_submission(
aiida.common.datastructures.CalcInfo
An instance of `aiida.common.datastructures.CalcInfo`.
"""

if "struct" in self.inputs:
structure = self.inputs.struct
elif "config" in self.inputs and "struct" in self.inputs.config.as_dictionary:
Expand Down
1 change: 0 additions & 1 deletion aiida_mlip/calculations/geomopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def prepare_for_submission(
aiida.common.datastructures.CalcInfo
An instance of `aiida.common.datastructures.CalcInfo`.
"""

# Call the parent class method to prepare common inputs
calcinfo = super().prepare_for_submission(folder)
codeinfo = calcinfo.codes_info[0]
Expand Down
1 change: 0 additions & 1 deletion aiida_mlip/calculations/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def prepare_for_submission(
aiida.common.datastructures.CalcInfo
An instance of `aiida.common.datastructures.CalcInfo`.
"""

# Call the parent class method to prepare common inputs
calcinfo = super().prepare_for_submission(folder)
codeinfo = calcinfo.codes_info[0]
Expand Down
1 change: 0 additions & 1 deletion aiida_mlip/calculations/singlepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def define(cls, spec: CalcJobProcessSpec) -> None:
print("defining outputnode")
spec.default_output_node = "results_dict"

# pylint: disable=too-many-locals
def prepare_for_submission(
self, folder: aiida.common.folders.Folder
) -> datastructures.CalcInfo:
Expand Down
1 change: 0 additions & 1 deletion aiida_mlip/calculations/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def define(cls, spec: CalcJobProcessSpec) -> None:
message="Some output files missing or cannot be read",
)

# pylint: disable=too-many-locals
def prepare_for_submission(
self, folder: aiida.common.folders.Folder
) -> datastructures.CalcInfo:
Expand Down
4 changes: 1 addition & 3 deletions aiida_mlip/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""
Data types for MLIPs calculations.
"""
"""Data types for MLIPs calculations."""
3 changes: 1 addition & 2 deletions aiida_mlip/data/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from pathlib import Path
from typing import Any, Optional, Union

import yaml

from aiida.orm import Data, SinglefileData
import yaml

from aiida_mlip.helpers.converters import convert_to_nodes

Expand Down
4 changes: 1 addition & 3 deletions aiida_mlip/data/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def _calculate_hash(file: Union[str, Path]) -> str:
# calculating sha in chunks rather than 1 large pass
while data := f.read(buf_size):
sha256.update(data)
file_hash = sha256.hexdigest()
return file_hash
return sha256.hexdigest()

def __init__(
self,
Expand Down Expand Up @@ -153,7 +152,6 @@ def from_local(
return cls(file=file_path, architecture=architecture, filename=filename)

@classmethod
# pylint: disable=too-many-arguments
def from_uri(
cls,
uri: str,
Expand Down
13 changes: 5 additions & 8 deletions aiida_mlip/helpers/converters.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
"""
Some helpers to convert between different formats.
"""
"""Some helpers to convert between different formats."""

from pathlib import Path
from typing import Union

from aiida.orm import Bool, Dict, Str, StructureData, TrajectoryData, load_code
from ase.io import read
import numpy as np

from aiida.orm import Bool, Dict, Str, StructureData, TrajectoryData, load_code

from aiida_mlip.helpers.help_load import load_model, load_structure


def convert_numpy(dictionary: dict) -> dict:
"""
A function to convert numpy ndarrays in dictionary into lists.
Convert numpy ndarrays in dictionary into lists.
Parameters
----------
Expand All @@ -35,10 +32,10 @@ def convert_numpy(dictionary: dict) -> dict:


def xyz_to_aiida_traj(
traj_file: Union[str, Path]
traj_file: Union[str, Path],
) -> tuple[StructureData, TrajectoryData]:
"""
A function to convert xyz trajectory file to `TrajectoryData` data type.
Convert xyz trajectory file to `TrajectoryData` data type.
Parameters
----------
Expand Down
9 changes: 3 additions & 6 deletions aiida_mlip/helpers/help_load.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
"""
Helper functions for automatically loading models and strucutres as data nodes.
"""
"""Helper functions for automatically loading models and strucutres as data nodes."""

from pathlib import Path
from typing import Optional, Union

from aiida.orm import StructureData, load_node
from ase.build import bulk
import ase.io
import click

from aiida.orm import StructureData, load_node

from aiida_mlip.data.model import ModelData


Expand Down Expand Up @@ -43,7 +40,7 @@ def load_model(
"""
if model is None:
loaded_model = ModelData.from_uri(
"https://github.com/stfc/janus-core/raw/main/tests/models/mace_mp_small.model", # pylint: disable=line-too-long
"https://github.com/stfc/janus-core/raw/main/tests/models/mace_mp_small.model",
architecture,
cache_dir=cache_dir,
)
Expand Down
4 changes: 1 addition & 3 deletions aiida_mlip/parsers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""
Parsers for calculations.
"""
"""Parsers for calculations."""
4 changes: 1 addition & 3 deletions aiida_mlip/parsers/base_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Parsers provided by aiida_mlip.
"""
"""Parsers provided by aiida_mlip."""

from aiida.engine import ExitCode
from aiida.orm import SinglefileData
Expand Down
7 changes: 2 additions & 5 deletions aiida_mlip/parsers/md_parser.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
"""
MD parser.
"""
"""MD parser."""

from pathlib import Path

import yaml

from aiida.common import exceptions
from aiida.engine import ExitCode
from aiida.orm import Dict, SinglefileData
from aiida.orm.nodes.process.process import ProcessNode
from aiida.plugins import CalculationFactory
import yaml

from aiida_mlip.calculations.md import MD
from aiida_mlip.helpers.converters import xyz_to_aiida_traj
Expand Down
8 changes: 3 additions & 5 deletions aiida_mlip/parsers/opt_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Geom optimisation parser.
"""
"""Geom optimisation parser."""

from pathlib import Path

Expand All @@ -13,7 +11,7 @@
from aiida_mlip.helpers.converters import xyz_to_aiida_traj
from aiida_mlip.parsers.sp_parser import SPParser

geomoptCalculation = CalculationFactory("mlip.opt")
GeomoptCalc = CalculationFactory("mlip.opt")


class GeomOptParser(SPParser):
Expand Down Expand Up @@ -54,7 +52,7 @@ def __init__(self, node: ProcessNode):
"""
super().__init__(node)

if not issubclass(node.process_class, geomoptCalculation):
if not issubclass(node.process_class, GeomoptCalc):
raise exceptions.ParsingError("Can only parse `GeomOpt` calculations")

def parse(self, **kwargs) -> ExitCode:
Expand Down
14 changes: 5 additions & 9 deletions aiida_mlip/parsers/sp_parser.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
"""
Parsers provided by aiida_mlip.
"""
"""Parsers provided by aiida_mlip."""

from pathlib import Path

from ase.io import read

from aiida.common import exceptions
from aiida.engine import ExitCode
from aiida.orm import Dict, SinglefileData
from aiida.orm.nodes.process.process import ProcessNode
from aiida.plugins import CalculationFactory
from ase.io import read

from aiida_mlip.helpers.converters import convert_numpy
from aiida_mlip.parsers.base_parser import BaseParser

singlePointCalculation = CalculationFactory("mlip.sp")
SinglepointCalc = CalculationFactory("mlip.sp")


class SPParser(BaseParser):
Expand Down Expand Up @@ -43,7 +40,7 @@ class SPParser(BaseParser):
Raises
------
exceptions.ParsingError
If the ProcessNode being passed was not produced by a singlePointCalculation.
If the ProcessNode being passed was not produced by a SinglepointCalc.
"""

def __init__(self, node: ProcessNode):
Expand All @@ -57,7 +54,7 @@ def __init__(self, node: ProcessNode):
"""
super().__init__(node)

if not issubclass(node.process_class, singlePointCalculation):
if not issubclass(node.process_class, SinglepointCalc):
raise exceptions.ParsingError("Can only parse `Singlepoint` calculations")

def parse(self, **kwargs) -> int:
Expand All @@ -74,7 +71,6 @@ def parse(self, **kwargs) -> int:
int
An exit code.
"""

exit_code = super().parse(**kwargs)

if exit_code != ExitCode(0):
Expand Down
4 changes: 1 addition & 3 deletions aiida_mlip/parsers/train_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Parser for mlip train.
"""
"""Parser for mlip train."""

import json
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
if current_year == copyright_first_year
else f"{copyright_first_year}-{current_year}"
)
# pylint: disable=redefined-builtin
copyright = f"{copyright_year_string}, {copyright_owners}. All rights reserved"

# The version info for the project you're documenting, acts as replacement for
Expand Down
Loading

0 comments on commit 2fad7f1

Please sign in to comment.