Skip to content

Commit

Permalink
Replace black with ruff in pre-commit config (#2394)
Browse files Browse the repository at this point in the history
* Replace `black` with `ruff` in pre-commit config

Fixes #2393

Signed-off-by: Oscar <71343264+0scvr@users.noreply.github.com>

* Add myself to CITATION.cff

Signed-off-by: Oscar <71343264+0scvr@users.noreply.github.com>

* Add changelog entry for PR 2394

Signed-off-by: Oscar <71343264+0scvr@users.noreply.github.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update changelog/2394.trivial.rst for reStructuredText

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

* Update .pre-commit-config.yaml

* Remove ruff rules that conflict with formatter

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: Oscar <71343264+0scvr@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>
  • Loading branch information
3 people committed Oct 25, 2023
1 parent 1df1ed8 commit d13e52b
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 69 deletions.
9 changes: 2 additions & 7 deletions .pre-commit-config.yaml
Expand Up @@ -86,10 +86,11 @@ repos:
- tomli

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
rev: v0.1.2
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
Expand All @@ -102,11 +103,6 @@ repos:
types:
- python

- repo: https://github.com/psf/black
rev: 23.10.0
hooks:
- id: black

- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
Expand All @@ -120,7 +116,6 @@ repos:
- id: nbqa-ruff
args: ['--select=A,ARG,B,BLE,C,C4,E,F,FLY,I002,INT,ISC,PERF,PIE,PLC,PLE,PYI,Q003,RET,RSE,SIM,TID,TRY,UP,W', '--ignore=B007,B008,B015,B018,E402,E501,E741,SIM114']
- id: nbqa-isort
- id: nbqa-black

- repo: local
hooks:
Expand Down
3 changes: 3 additions & 0 deletions CITATION.cff
Expand Up @@ -580,3 +580,6 @@ authors:
family-names: Jones
orcid: https://orcid.org/0009-0004-6699-4869
alias: E-W-Jones

- given-names: Oscar
alias: 0scvr
1 change: 1 addition & 0 deletions changelog/2394.trivial.rst
@@ -0,0 +1 @@
Replaced |black| with |ruff| in pre-commit config.
7 changes: 1 addition & 6 deletions plasmapy/diagnostics/langmuir.py
Expand Up @@ -1223,12 +1223,7 @@ def get_ion_density_OML(
ion = Particle(argument=gas)

n_i_OML = np.sqrt(
-slope
* u.mA**2
/ u.V
* np.pi**2
* ion.mass
/ (probe_area**2 * const.e**3 * 2)
-slope * u.mA**2 / u.V * np.pi**2 * ion.mass / (probe_area**2 * const.e**3 * 2)
)

if visualize:
Expand Down
4 changes: 1 addition & 3 deletions plasmapy/diagnostics/tests/test_langmuir.py
Expand Up @@ -294,9 +294,7 @@ def test_negative_area():

with pytest.raises(ValueError):
with pytest.warns(FutureWarning):
langmuir.swept_probe_analysis(
characteristic, -1 * u.cm**2, "Ar-40 1+"
)
langmuir.swept_probe_analysis(characteristic, -1 * u.cm**2, "Ar-40 1+")

@staticmethod
@pytest.mark.parametrize("bimaxwellian", [True, False])
Expand Down
4 changes: 2 additions & 2 deletions plasmapy/diagnostics/thomson.py
Expand Up @@ -229,7 +229,7 @@ def spectral_density_lite(
/ k
/ vT_e[m]
* np.power(np.abs(1 - np.sum(chiE, axis=0) / epsilon), 2)
* np.exp(-xe[m, :] ** 2)
* np.exp(-(xe[m, :] ** 2))
)

icontr = np.zeros([ifract.size, w.size], dtype=np.complex128)
Expand All @@ -241,7 +241,7 @@ def spectral_density_lite(
/ k
/ vT_i[m]
* np.power(np.abs(np.sum(chiE, axis=0) / epsilon), 2)
* np.exp(-xi[m, :] ** 2)
* np.exp(-(xi[m, :] ** 2))
)

# Recast as real: imaginary part is already zero
Expand Down
7 changes: 2 additions & 5 deletions plasmapy/dispersion/analytical/mhd_waves_.py
Expand Up @@ -72,9 +72,7 @@ def __init__(

self._Alfven_speed = Alfven_speed(B, _rho)
self._sound_speed = np.sqrt(gamma * k_B * T / ion.mass).to(u.m / u.s)
self._magnetosonic_speed = np.sqrt(
self._Alfven_speed**2 + self._sound_speed**2
)
self._magnetosonic_speed = np.sqrt(self._Alfven_speed**2 + self._sound_speed**2)
self._beta = beta(T, _n, B)
self._gyrofrequency = gyrofrequency(B, ion)
self._plasma_frequency = plasma_frequency(_n, ion)
Expand Down Expand Up @@ -1009,8 +1007,7 @@ def group_velocity(self, k: u.rad / u.m, theta: u.rad):
* self._sound_speed**2
* np.sin(theta)
* np.cos(theta),
phase_velocity
* (2 * phase_velocity**2 - self._magnetosonic_speed**2),
phase_velocity * (2 * phase_velocity**2 - self._magnetosonic_speed**2),
out=group_velocity,
where=phase_velocity != 0,
)
Expand Down
27 changes: 6 additions & 21 deletions plasmapy/formulary/braginskii.py
Expand Up @@ -1565,9 +1565,7 @@ def _nondim_resist_braginskii(hall, Z, field_orientation):
return alpha_par

if field_orientation in ("perpendicular", "perp"):
alpha_perp = (
1 - (alpha_1_prime[Z_idx] * hall**2 + alpha_0_prime[Z_idx]) / Delta
)
alpha_perp = 1 - (alpha_1_prime[Z_idx] * hall**2 + alpha_0_prime[Z_idx]) / Delta
return alpha_perp

if field_orientation == "cross":
Expand All @@ -1579,9 +1577,7 @@ def _nondim_resist_braginskii(hall, Z, field_orientation):
if field_orientation == "all":
alpha_par = alpha_0

alpha_perp = (
1 - (alpha_1_prime[Z_idx] * hall**2 + alpha_0_prime[Z_idx]) / Delta
)
alpha_perp = 1 - (alpha_1_prime[Z_idx] * hall**2 + alpha_0_prime[Z_idx]) / Delta

alpha_cross = (
alpha_1_doubleprime[Z_idx] * hall**3 + alpha_0_doubleprime[Z_idx] * hall
Expand Down Expand Up @@ -2103,13 +2099,7 @@ def _nondim_tc_i_ji_held(hall, Z, mu, theta, field_orientation, K=3):
Delta_perp_i1 = (
r**6
+ (3.635 + 29.15 * zeta + 83 * zeta**2) * r**4
+ (
1.395
+ 35.64 * zeta
+ 344.9 * zeta**2
+ 1345 * zeta**3
+ 1891 * zeta**4
)
+ (1.395 + 35.64 * zeta + 344.9 * zeta**2 + 1345 * zeta**3 + 1891 * zeta**4)
* r**2
+ 0.09163 * Delta_par_i1**2
)
Expand All @@ -2125,17 +2115,14 @@ def _nondim_tc_i_ji_held(hall, Z, mu, theta, field_orientation, K=3):
+ 0.1693 * Delta_par_i1**2
)
kappa_perp_i = (
(np.sqrt(2) + 15 / 2 * zeta) * r**2
+ 0.1693 * kappa_par_i * Delta_par_i1**2
(np.sqrt(2) + 15 / 2 * zeta) * r**2 + 0.1693 * kappa_par_i * Delta_par_i1**2
) / Delta_perp_i1
if field_orientation in ("perpendicular", "perp"):
return kappa_perp_i / np.sqrt(2)

if K == 2:
kappa_cross_i = (
r
* (5 / 2 * r**2 + 2.323 + 22.73 * zeta + 62.5 * zeta**2)
/ Delta_perp_i1
r * (5 / 2 * r**2 + 2.323 + 22.73 * zeta + 62.5 * zeta**2) / Delta_perp_i1
)
elif K == 3:
kappa_cross_i = (
Expand Down Expand Up @@ -2262,9 +2249,7 @@ def f_eta_4(r, zeta, Delta_perp_i2):
+ (2.023 + 11.68 * zeta + 20 * zeta**2) * r**2
+ 0.5820 * Delta_par_i2**2
)
eta_4_i = (
r * (r**2 + 1.188 + 8.283 * zeta + 16 * zeta**2) / Delta_perp_i2
)
eta_4_i = r * (r**2 + 1.188 + 8.283 * zeta + 16 * zeta**2) / Delta_perp_i2
return eta_4_i

eta_4_i = f_eta_4(r, zeta, Delta_perp_i2_24)
Expand Down
5 changes: 4 additions & 1 deletion plasmapy/formulary/collisions/misc.py
Expand Up @@ -45,7 +45,10 @@ def _process_inputs(T: u.K, species: (particles.Particle, particles.Particle), V

# TODO: Remove redundant mass parameter
def _replace_nan_velocity_with_thermal_velocity(
V, T, m, species=particles.Particle("e-") # noqa: B008
V,
T,
m,
species=particles.Particle("e-"), # noqa: B008
):
"""
Get thermal velocity of system if no velocity is given, for a given
Expand Down
8 changes: 1 addition & 7 deletions plasmapy/formulary/radiation.py
Expand Up @@ -137,13 +137,7 @@ def thermal_bremsstrahlung(
)

Zi = ion.charge_number
c2 = (
np.sqrt(1 - ω_pe**2 / ω**2)
* Zi**2
* n_i
* n_e
/ np.sqrt(const.k_B.si * T_e)
)
c2 = np.sqrt(1 - ω_pe**2 / ω**2) * Zi**2 * n_i * n_e / np.sqrt(const.k_B.si * T_e)

# Dimensionless argument for exponential integral
arg = 0.5 * ω**2 * const.m_e.si / (kmax**2 * const.k_B.si * T_e) / u.rad**2
Expand Down
4 changes: 1 addition & 3 deletions plasmapy/formulary/tests/test_frequencies.py
Expand Up @@ -134,9 +134,7 @@ def test_lower_hybrid_frequency():
assert omega_ce.unit.is_equivalent(u.rad / u.s)
assert omega_lh.unit.is_equivalent(u.rad / u.s)
left_hand_side = omega_lh**-2
right_hand_side = (
1 / (omega_ci**2 + omega_pi**2) + omega_ci**-1 * omega_ce**-1
)
right_hand_side = 1 / (omega_ci**2 + omega_pi**2) + omega_ci**-1 * omega_ce**-1
assert np.isclose(left_hand_side.value, right_hand_side.value)

assert np.isclose(omega_lh_hz.value, 299878691.3223296)
Expand Down
8 changes: 2 additions & 6 deletions plasmapy/formulary/tests/test_lengths.py
Expand Up @@ -371,15 +371,11 @@ def test_inertial_length():

with pytest.warns(u.UnitsWarning):
inertial_length_no_units = inertial_length(1e19, particle="p")
assert inertial_length_no_units == inertial_length(
1e19 * u.m**-3, particle="p"
)
assert inertial_length_no_units == inertial_length(1e19 * u.m**-3, particle="p")

assert inertial_length(n_e, "e-").unit.is_equivalent(u.m)

assert np.isclose(
inertial_length(1 * u.cm**-3, "e-").cgs.value, 5.31e5, rtol=1e-3
)
assert np.isclose(inertial_length(1 * u.cm**-3, "e-").cgs.value, 5.31e5, rtol=1e-3)

with pytest.warns(u.UnitsWarning):
inertial_length(5, "e-")
Expand Down
4 changes: 1 addition & 3 deletions plasmapy/plasma/sources/tests/test_openpmd_hdf5.py
Expand Up @@ -116,9 +116,7 @@ def test_correct_shape_magnetic_field(self, h5_theta):
assert h5_theta.magnetic_field.shape == (3, 3, 51, 201)

def test_has_electric_current_with_units(self, h5_theta):
assert isinstance(
h5_theta.electric_current.to(u.A * u.kg / u.m**3), u.Quantity
)
assert isinstance(h5_theta.electric_current.to(u.A * u.kg / u.m**3), u.Quantity)

def test_correct_shape_electric_current(self, h5_theta):
assert h5_theta.electric_current.shape == (3, 3, 51, 201)
Expand Down
9 changes: 8 additions & 1 deletion plasmapy/utils/decorators/tests/test_converters.py
Expand Up @@ -80,7 +80,14 @@ def test_func(pos_only, /, arg, *args, required_kwarg, optional_kwarg=2, **kwarg

original_signature = inspect.signature(test_func)
expected_signature = inspect.signature(
lambda pos_only, /, arg, *args, required_kwarg, optional_kwarg=2, to_hz=False, **kwargs: None
lambda pos_only,
/,
arg,
*args,
required_kwarg,
optional_kwarg=2,
to_hz=False,
**kwargs: None
)

assert (
Expand Down
4 changes: 1 addition & 3 deletions plasmapy/utils/decorators/tests/test_validators.py
Expand Up @@ -25,9 +25,7 @@ class :class:`~plasmapy.utils.decorators.validators.ValidateQuantities`.
"""

unit_check_defaults = CheckUnits._CheckUnits__check_defaults # type: Dict[str, Any]
value_check_defaults = (
CheckValues._CheckValues__check_defaults
) # type: Dict[str, Any]
value_check_defaults = CheckValues._CheckValues__check_defaults # type: Dict[str, Any]
check_defaults = {**unit_check_defaults, **value_check_defaults}

@staticmethod
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Expand Up @@ -257,7 +257,6 @@ extend-select = [
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"PYI", # flake8-pyi
"Q003", # avoidable-escaped-quote
"RET", # flake8-return
"RSE", # flake8-raise
"RUF005", # collection-literal-concatenation
Expand Down Expand Up @@ -292,11 +291,13 @@ ignore = [
"D200", # fits-on-one-line (incompatible with multiline short summaries)
"D202", # no-blank-line-after-function
"D205", # blank-line-after-summary (incompatible with multiline short summaries)
"D206", # indent-with-spaces (formatter conflict)
"D401", # non-imperative-mood (enable later?)
"E501", # line-too-long
"EM101", # raw-string-in-exception (enable later in focused PR)
"EM102", # f-string-in-exception (enable later in focused PR)
"FIX002", # line-contains-todo
"ISC001", # single-line-implicit-string-concatenation (formatter conflict)
"N802", # invalid-function-name
"N803", # invalid-argument-name
"N806", # non-lowercase-variable-in-function
Expand Down Expand Up @@ -324,6 +325,7 @@ ignore = [
"UP006", # non-pep585-annotation
"UP007", # non-pep604-annotation
"UP025", # unicode-kind-prefix
"W191", # tab-indentation (formatter conflict)
]
extend-exclude = [
"docs/plasmapy_sphinx",
Expand Down

0 comments on commit d13e52b

Please sign in to comment.