Skip to content

Commit 94590fa

Browse files
Merge pull request #12 from PlasmaFAIR/upgrade_linting
Upgrade linting
2 parents d5b8b07 + e2b83a0 commit 94590fa

File tree

4 files changed

+45
-36
lines changed

4 files changed

+45
-36
lines changed

.github/workflows/lint.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ jobs:
2020
run: |
2121
python -m pip install --upgrade pip
2222
python -m pip install .[lint]
23-
- name: Run Black
23+
- name: Run ruff formatter
2424
if: always()
2525
run: |
26-
black --check --verbose src tests
27-
- name: Run Ruff
26+
ruff format --check src tests
27+
- name: Run ruff linter
2828
if: always()
2929
run: |
30-
ruff check src
30+
ruff check src tests
3131
- name: Run MyPy
3232
if: always()
3333
run: |

pyproject.toml

+20-8
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ test = [
3333
"pytest-sugar",
3434
]
3535
lint = [
36-
"black",
37-
"isort",
38-
"docformatter",
3936
"ruff",
40-
"refurb",
4137
"mypy",
4238
]
4339

@@ -56,11 +52,27 @@ build-backend = "setuptools.build_meta"
5652
version_file = "src/pyloidal/_version.py"
5753
fallback_version = "0.1.0"
5854

59-
[tool.isort]
60-
profile = "black"
61-
6255
[tool.ruff.lint]
63-
select = ["E", "F", "W", "RUF"]
56+
select = [
57+
"F", # Pyflakes
58+
"E", # pycodestyle error
59+
"W", # pycodestyle warning
60+
"I", # isort
61+
"PT", # flake8-pytest-style
62+
"B", # flake8-bugbear
63+
"A", # flake8-builtins
64+
"C4", # flake8-comprehensions
65+
"EM", # flake8-errmsg
66+
"T10", # flake8-debugger
67+
"PTH", # flake8-use-pathlib
68+
"SIM", # flake8-simplify
69+
"TCH", # flake8-type-checking
70+
"UP", # pyupgrade
71+
"FURB", # refurb
72+
"PERF", # perflint
73+
"RUF", # ruff specific
74+
"NPY", # NumPy specific
75+
]
6476

6577
[tool.coverage.run]
6678
relative_files = true

src/pyloidal/cocos.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
These functions were adapted from OMAS (Copyright MIT License, 2017, Orso Meneghini).
1616
"""
1717

18-
from dataclasses import dataclass
1918
import itertools
20-
from typing import Optional, Tuple
19+
from dataclasses import dataclass
2120

2221
import numpy as np
2322
from numpy.typing import NDArray
@@ -35,15 +34,14 @@ class Sigma:
3534

3635
def __post_init__(self):
3736
if self.B_poloidal not in (-1, 1):
38-
raise ValueError(
39-
f"B_poloidal should be either 1 or -1, found {self.B_poloidal}"
40-
)
37+
msg = f"B_poloidal should be either 1 or -1, found {self.B_poloidal}"
38+
raise ValueError(msg)
4139
if self.r_phi_z not in (-1, 1):
42-
raise ValueError(f"r_phi_z should be either 1 or -1, found {self.r_phi_z}")
40+
msg = f"r_phi_z should be either 1 or -1, found {self.r_phi_z}"
41+
raise ValueError(msg)
4342
if self.r_theta_phi not in (-1, 1):
44-
raise ValueError(
45-
f"r_theta_phi should be either 1 or -1, found {self.r_theta_phi}"
46-
)
43+
msg = f"r_theta_phi should be either 1 or -1, found {self.r_theta_phi}"
44+
raise ValueError(msg)
4745

4846

4947
SIGMA_TO_COCOS = {
@@ -99,9 +97,9 @@ def identify_cocos(
9997
plasma_current: float,
10098
safety_factor: FloatArray,
10199
poloidal_flux: FloatArray,
102-
clockwise_phi: Optional[bool] = None,
103-
minor_radii: Optional[FloatArray] = None,
104-
) -> Tuple[int, ...]:
100+
clockwise_phi: bool | None = None,
101+
minor_radii: FloatArray | None = None,
102+
) -> tuple[int, ...]:
105103
r"""
106104
Determine which COCOS coordinate system is in use. Returns all possible conventions.
107105

tests/test_cocos.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from itertools import product
2-
from typing import Any, Dict, List, Tuple
2+
from typing import Any
33

44
import numpy as np
55
import pytest
66

7-
from pyloidal.cocos import identify_cocos, Transform
8-
7+
from pyloidal.cocos import Transform, identify_cocos
98

109
ALL_COCOS = list(range(1, 9)) + list(range(11, 19))
1110

@@ -15,16 +14,16 @@ def _identify_cocos_inputs(
1514
antiparallel_field_and_current: bool,
1615
use_minor_radii: bool,
1716
use_clockwise_phi: bool,
18-
) -> Tuple[Dict[str, Any], Tuple[int, ...]]:
17+
) -> tuple[dict[str, Any], tuple[int, ...]]:
1918
"""Generates inputs for ``identify_cocos`` for a given COCOS"""
2019
# Set up cocos 1 kwargs and modify accordingly
21-
kwargs: Dict[str, Any] = dict(
22-
b_toroidal=2.5,
23-
plasma_current=1e6,
24-
poloidal_flux=np.linspace(0, 2, 3),
25-
safety_factor=np.linspace(0.5, 1.5, 3),
26-
)
27-
expected: List[int] = [cocos]
20+
kwargs: dict[str, Any] = {
21+
"b_toroidal": 2.5,
22+
"plasma_current": 1e6,
23+
"poloidal_flux": np.linspace(0, 2, 3),
24+
"safety_factor": np.linspace(0.5, 1.5, 3),
25+
}
26+
expected: list[int] = [cocos]
2827

2928
even_cocos = not bool(cocos % 2)
3029
base_cocos = (cocos % 10) - even_cocos
@@ -52,7 +51,7 @@ def _identify_cocos_inputs(
5251

5352

5453
@pytest.mark.parametrize(
55-
"cocos,antiparallel,use_minor_radii,use_clockwise_phi",
54+
("cocos", "antiparallel", "use_minor_radii", "use_clockwise_phi"),
5655
product(ALL_COCOS, *(3 * [[True, False]])),
5756
)
5857
def test_identify_cocos(

0 commit comments

Comments
 (0)