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 5ea7e81 commit 3450bc4
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 46 deletions.
22 changes: 11 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ 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"]
known-third-party = ["torch"]

[tool.ruff.format]
docstring-code-format = true

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

Expand Down
2 changes: 0 additions & 2 deletions python/rascaline/rascaline/systems/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class SystemBase:
...
... def pairs_containing(self, atom):
... raise NotImplementedError("this system does not have a neighbors list")
...
>>> system = SimpleSystem(
... types=np.random.randint(2, size=25, dtype=np.int32),
... positions=6 * np.random.uniform(size=(25, 3)),
Expand All @@ -112,7 +111,6 @@ class SystemBase:
... calculator.compute(system, use_native_system=False)
... except rascaline.RascalError as e:
... raise e.__cause__
...
Traceback (most recent call last):
...
NotImplementedError: this system does not have a neighbors list
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
2 changes: 0 additions & 2 deletions python/rascaline/rascaline/utils/splines/splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ class RadialIntegralFromFunction(RadialIntegralSplinerBase):
>>> def radial_integral(n, ell, r):
... return np.sin(r)
...
and provide this as input to the spline generator
Expand Down Expand Up @@ -686,7 +685,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
25 changes: 7 additions & 18 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -141,35 +141,24 @@ 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
blackdoc
flake8
flake8-bugbear
isort
ruff

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


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


[testenv:build-python]
Expand Down

0 comments on commit 3450bc4

Please sign in to comment.