Skip to content

Commit 268646b

Browse files
authored
Merge pull request #233 from astro-informatics/mmg/add-ruff
Set up Ruff for linting and formatting
2 parents 543dfca + 7985214 commit 268646b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1139
-628
lines changed

.github/workflows/linting.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Linting
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
linting:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout source
14+
uses: actions/checkout@v4
15+
16+
- name: Cache pre-commit
17+
uses: actions/cache@v4
18+
with:
19+
path: ~/.cache/pre-commit
20+
key: pre-commit-${{ '{{' }} hashFiles('.pre-commit-config.yaml') {{ '}}' }}
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.x"
26+
cache: pip
27+
cache-dependency-path: pyproject.toml
28+
29+
- name: Install dependencies
30+
run: python -m pip install pre-commit
31+
32+
- name: Run pre-commit
33+
run: pre-commit run --all-files --color always --verbose

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.6.9
4+
hooks:
5+
- id: ruff
6+
- id: ruff-format

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
[![image](https://github.com/astro-informatics/s2fft/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/astro-informatics/s2fft/actions/workflows/tests.yml)
2-
[![image](https://codecov.io/gh/astro-informatics/s2fft/branch/main/graph/badge.svg?token=7QYAFAAWLE)](https://codecov.io/gh/astro-informatics/s2fft)
3-
[![image](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4-
[![image](https://badge.fury.io/py/s2fft.svg)](https://badge.fury.io/py/s2fft)
5-
[![image](http://img.shields.io/badge/arXiv-2311.14670-orange.svg?style=flat)](https://arxiv.org/abs/2311.14670)<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
1+
[![Tests status](https://github.com/astro-informatics/s2fft/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/astro-informatics/s2fft/actions/workflows/tests.yml)
2+
[![Linting status](https://github.com/astro-informatics/s2fft/actions/workflows/linting.yml/badge.svg?branch=main)](https://github.com/astro-informatics/s2fft/actions/workflows/linting.yml)
3+
[![Documentation status](https://github.com/astro-informatics/s2fft/actions/workflows/docs.yml/badge.svg?branch=main)](https://github.com/astro-informatics/s2fft/actions/workflows/docs.yml)
4+
[![Codecov](https://codecov.io/gh/astro-informatics/s2fft/branch/main/graph/badge.svg?token=7QYAFAAWLE)](https://codecov.io/gh/astro-informatics/s2fft)
5+
[![MIT License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6+
[![PyPI package](https://badge.fury.io/py/s2fft.svg)](https://badge.fury.io/py/s2fft)
7+
[![arXiv](http://img.shields.io/badge/arXiv-2311.14670-orange.svg?style=flat)](https://arxiv.org/abs/2311.14670)<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
68
[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors-)
79
<!-- ALL-CONTRIBUTORS-BADGE:END -->
810
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/astro-informatics/s2fft/blob/main/notebooks/spherical_harmonic_transform.ipynb)

benchmarks/benchmarking.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ def mean(x, n):
6060
"""
6161

6262
import argparse
63+
import inspect
64+
import json
65+
import timeit
6366
from ast import literal_eval
6467
from functools import partial
6568
from itertools import product
6669
from pathlib import Path
67-
import json
68-
import timeit
69-
import inspect
7070

7171
try:
7272
import memory_profiler

benchmarks/spherical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import numpy as np
44
import pyssht
5+
from benchmarking import benchmark, parse_args_collect_and_run_benchmarks, skip
6+
57
import s2fft
68
from s2fft.recursions.price_mcewen import generate_precomputes
79
from s2fft.sampling import s2_samples as samples
8-
from benchmarking import benchmark, skip, parse_args_collect_and_run_benchmarks
9-
1010

1111
L_VALUES = [8, 16, 32, 64, 128, 256]
1212
L_LOWER_VALUES = [0]

benchmarks/wigner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Benchmarks for Wigner transforms."""
22

33
import numpy as np
4+
from benchmarking import benchmark, parse_args_collect_and_run_benchmarks, skip
5+
46
import s2fft
57
from s2fft.base_transforms import wigner as base_wigner
68
from s2fft.recursions.price_mcewen import (
79
generate_precomputes_wigner,
810
generate_precomputes_wigner_jax,
911
)
10-
from benchmarking import benchmark, skip, parse_args_collect_and_run_benchmarks
1112

1213
L_VALUES = [16, 32, 64, 128, 256]
1314
N_VALUES = [2]

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Configuration file for the Sphinx documentation builder.
43
#

notebooks/plotting_functions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import pyvista as pv
21
import numpy as np
2+
import pyvista as pv
3+
34
from s2fft.sampling import s2_samples as samples
45

56

@@ -19,7 +20,8 @@ def plot_sphere(
1920
cmap: str = "inferno",
2021
isnotebook: bool = False,
2122
) -> None:
22-
"""Plots signal (f) on the sphere using PyVista.
23+
"""
24+
Plots signal (f) on the sphere using PyVista.
2325
2426
Args:
2527
f (np.ndarray): Signal on the sphere.
@@ -36,8 +38,8 @@ def plot_sphere(
3638
3739
Note:
3840
TODO: Add support for healpix sampling.
39-
"""
4041
42+
"""
4143
phis = samples.phis_equiang(L, sampling)
4244
thetas = samples.thetas(L, sampling)
4345
xx_bounds = _cell_bounds(np.degrees(phis))

pyproject.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,55 @@ filterwarnings = [
9999
"ignore:FutureWarning",
100100
]
101101

102+
[tool.ruff]
103+
fix = true
104+
force-exclude = true
105+
format.exclude = ["*.ipynb"]
106+
lint.exclude = ["*.ipynb"]
107+
lint.ignore = [
108+
"B023", # function-uses-loop-variable
109+
"COM812", # trailing commas (ruff-format recommended)
110+
"D100", # undocumented-public-module
111+
"D104", # undocumented-public-package
112+
"D203", # no-blank-line-before-class
113+
"D205", # blank line between summary and description in docstrings
114+
"D212", # multi-line-summary-first-line
115+
"D401", # non-imperative-mood
116+
"D407", # removed dashes lines under sections
117+
"D417", # argument description in docstring (unreliable)
118+
"ISC001", # simplify implicit str concatenation (ruff-format recommended)
119+
"S101", # assert
120+
]
121+
lint.per-file-ignores = {"benchmarks*" = [
122+
"D", # No docstring checks in benchmarks
123+
], "tests*" = [
124+
"D", # No docstring checks in tests
125+
"INP001", # File is part of an implicit namespace package.
126+
"S101", # Use of `assert` detected
127+
], "__init__.py" = [
128+
"F401" # unused-import
129+
]}
130+
lint.select = [
131+
"B",
132+
"C90",
133+
"D",
134+
"E1",
135+
"E4",
136+
"E7",
137+
"E9",
138+
"F",
139+
"I",
140+
"S",
141+
"UP",
142+
]
143+
lint.isort.known-first-party = [
144+
"s2fft"
145+
]
146+
lint.mccabe.max-complexity = 18
147+
lint.pep8-naming.classmethod-decorators = [
148+
"classmethod",
149+
]
150+
102151
[tool.setuptools]
103152
packages = ["s2fft"]
104153

s2fft/__init__.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1+
import logging
2+
3+
import jax
4+
15
from . import logs
2-
from .transforms import wigner
3-
from .transforms.spherical import *
46
from .recursions.price_mcewen import (
57
generate_precomputes,
68
generate_precomputes_jax,
79
generate_precomputes_wigner,
810
generate_precomputes_wigner_jax,
911
)
10-
from .utils.rotation import rotate_flms, generate_rotate_dls
11-
12-
import logging
13-
import jax
12+
from .transforms import wigner
13+
from .transforms.spherical import (
14+
forward,
15+
forward_jax,
16+
forward_numpy,
17+
inverse,
18+
inverse_jax,
19+
inverse_numpy,
20+
)
21+
from .utils.rotation import generate_rotate_dls, rotate_flms
1422

1523
if jax.config.read("jax_enable_x64") is False:
1624
logger = logging.getLogger("s2fft")

0 commit comments

Comments
 (0)