Skip to content

Commit

Permalink
Switch to ruff for linting & formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Luthaf committed Nov 5, 2024
1 parent 5326b6e commit 82465c7
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 43 deletions.
19 changes: 8 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,15 @@ namespaces = false

### ======================================================================== ###

[tool.black]
extend-exclude = """
/python/rascaline/rascaline/_c_api\\.py
"""

[tool.isort]
profile = "black"
line_length = 88
indent = 4
include_trailing_comma = true
lines_after_imports = 2
known_first_party = ["rascaline", "save_data"]
[tool.ruff.lint]
select = ["E", "F", "B", "I"]
ignore = ["B018", "B904"]

[tool.ruff.lint.isort]
lines-after-imports = 2
known-first-party = ["rascaline"]


### ======================================================================== ###

Expand Down
2 changes: 1 addition & 1 deletion python/rascaline-torch/rascaline/torch/_c_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from collections import namedtuple

import metatensor.torch
import torch

import rascaline
import torch

from ._build_versions import BUILD_RASCALINE_VERSION, BUILD_TORCH_VERSION

Expand Down
3 changes: 2 additions & 1 deletion python/rascaline-torch/rascaline/torch/calculator_base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import List, Optional, Union

import torch
from metatensor.torch import Labels, TensorMap
from metatensor.torch.atomistic import NeighborListOptions

import torch

from .system import System


Expand Down
2 changes: 1 addition & 1 deletion python/rascaline-torch/rascaline/torch/system.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import List, Optional, Sequence, overload

import numpy as np
import torch
from metatensor.torch.atomistic import System
from packaging import version

import rascaline
import torch


@overload
Expand Down
2 changes: 1 addition & 1 deletion python/rascaline-torch/rascaline/torch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from typing import Any

import metatensor.torch
import torch

import rascaline.utils
import torch

from .calculator_base import CalculatorModule
from .system import System
Expand Down
1 change: 0 additions & 1 deletion python/rascaline/rascaline/utils/_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class TorchTensor:
pass

class TorchModule:

def __call__(self, *arg, **kwargs):
return self.forward(*arg, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ def _build_dense_cg_coeff_dict(
for o3_lambda in range(
max(l1, l2) - min(l1, l2), min(lambda_max, (l1 + l2)) + 1
):

complex_cg = _dispatch.to(
wigners.clebsch_gordan_array(l1, l2, o3_lambda),
backend=arrays_backend,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ def _density_correlations(
# Perform iterative CG tensor products
new_lambda_names: List[str] = []
for i_correlation in range(self._n_correlations):

# Increment the density property dimension names
density = _increment_property_names(density, 1)

Expand Down
2 changes: 0 additions & 2 deletions python/rascaline/rascaline/utils/clebsch_gordan/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def _compute_output_keys(
combinations: List[Tuple[int, int]] = []
for key_1_i in range(len(keys_1)):
for key_2_i in range(len(keys_2)):

# Get the keys
key_1 = keys_1.entry(key_1_i)
key_2 = keys_2.entry(key_2_i)
Expand All @@ -131,7 +130,6 @@ def _compute_output_keys(
for o3_lambda in range(
abs(o3_lambda_1 - o3_lambda_2), abs(o3_lambda_1 + o3_lambda_2) + 1
):

# Calculate new sigma
o3_sigma = int(
o3_sigma_1
Expand Down
1 change: 0 additions & 1 deletion python/rascaline/rascaline/utils/splines/splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,6 @@ def integrand(
def _radial_integral_custom(
self, n: int, ell: int, positions: np.ndarray, derivative: bool = False
) -> np.ndarray:

P_ell = legendre(ell)

if derivative:
Expand Down
9 changes: 1 addition & 8 deletions python/rascaline/tests/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@

# Try to import some modules
ase = pytest.importorskip("ase")
import ase.io # noqa: E402
import ase.io # noqa: E402,F811


try:
import torch # noqa: F401

HAS_TORCH = True
except ImportError:
HAS_TORCH = False

try:
import metatensor.operations

Expand Down
21 changes: 7 additions & 14 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -141,35 +141,28 @@ commands =


[testenv:lint]
description =
lint the Python code with flake8 (code linter), black (code formatter), and isort
(sorting of imports)
description = Run linters and formatter
package = skip
deps =
black
ruff
blackdoc
flake8
flake8-bugbear
isort

commands =
flake8 {[testenv]lint-folders}
black --check --diff {[testenv]lint-folders}
ruff format --diff {[testenv]lint-folders}
ruff check {[testenv]lint-folders}
blackdoc --check --diff {[testenv]lint-folders}
isort --check-only --diff {[testenv]lint-folders}


[testenv:format]
description = Abuse tox to do actual formatting on all files.
package = skip
deps =
black
ruff
blackdoc
isort
commands =
black {[testenv]lint-folders}
ruff format {[testenv]lint-folders}
ruff check --fix-only {[testenv]lint-folders}
blackdoc {[testenv]lint-folders}
isort {[testenv]lint-folders}


[testenv:build-python]
Expand Down

0 comments on commit 82465c7

Please sign in to comment.