Skip to content

Commit

Permalink
Merge pull request #233 from astro-informatics/mmg/add-ruff
Browse files Browse the repository at this point in the history
Set up Ruff for linting and formatting
  • Loading branch information
matt-graham authored Oct 10, 2024
2 parents 543dfca + 7985214 commit 268646b
Show file tree
Hide file tree
Showing 62 changed files with 1,139 additions and 628 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Linting

on:
push:
branches:
- main
pull_request:

jobs:
linting:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Cache pre-commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ '{{' }} hashFiles('.pre-commit-config.yaml') {{ '}}' }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: pip
cache-dependency-path: pyproject.toml

- name: Install dependencies
run: python -m pip install pre-commit

- name: Run pre-commit
run: pre-commit run --all-files --color always --verbose
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
- id: ruff-format
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[![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)
[![image](https://codecov.io/gh/astro-informatics/s2fft/branch/main/graph/badge.svg?token=7QYAFAAWLE)](https://codecov.io/gh/astro-informatics/s2fft)
[![image](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![image](https://badge.fury.io/py/s2fft.svg)](https://badge.fury.io/py/s2fft)
[![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 -->
[![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)
[![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)
[![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)
[![Codecov](https://codecov.io/gh/astro-informatics/s2fft/branch/main/graph/badge.svg?token=7QYAFAAWLE)](https://codecov.io/gh/astro-informatics/s2fft)
[![MIT License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![PyPI package](https://badge.fury.io/py/s2fft.svg)](https://badge.fury.io/py/s2fft)
[![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 -->
[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
[![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)
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/benchmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ def mean(x, n):
"""

import argparse
import inspect
import json
import timeit
from ast import literal_eval
from functools import partial
from itertools import product
from pathlib import Path
import json
import timeit
import inspect

try:
import memory_profiler
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/spherical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import numpy as np
import pyssht
from benchmarking import benchmark, parse_args_collect_and_run_benchmarks, skip

import s2fft
from s2fft.recursions.price_mcewen import generate_precomputes
from s2fft.sampling import s2_samples as samples
from benchmarking import benchmark, skip, parse_args_collect_and_run_benchmarks


L_VALUES = [8, 16, 32, 64, 128, 256]
L_LOWER_VALUES = [0]
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/wigner.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Benchmarks for Wigner transforms."""

import numpy as np
from benchmarking import benchmark, parse_args_collect_and_run_benchmarks, skip

import s2fft
from s2fft.base_transforms import wigner as base_wigner
from s2fft.recursions.price_mcewen import (
generate_precomputes_wigner,
generate_precomputes_wigner_jax,
)
from benchmarking import benchmark, skip, parse_args_collect_and_run_benchmarks

L_VALUES = [16, 32, 64, 128, 256]
N_VALUES = [2]
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand Down
8 changes: 5 additions & 3 deletions notebooks/plotting_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pyvista as pv
import numpy as np
import pyvista as pv

from s2fft.sampling import s2_samples as samples


Expand All @@ -19,7 +20,8 @@ def plot_sphere(
cmap: str = "inferno",
isnotebook: bool = False,
) -> None:
"""Plots signal (f) on the sphere using PyVista.
"""
Plots signal (f) on the sphere using PyVista.
Args:
f (np.ndarray): Signal on the sphere.
Expand All @@ -36,8 +38,8 @@ def plot_sphere(
Note:
TODO: Add support for healpix sampling.
"""
"""
phis = samples.phis_equiang(L, sampling)
thetas = samples.thetas(L, sampling)
xx_bounds = _cell_bounds(np.degrees(phis))
Expand Down
49 changes: 49 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,55 @@ filterwarnings = [
"ignore:FutureWarning",
]

[tool.ruff]
fix = true
force-exclude = true
format.exclude = ["*.ipynb"]
lint.exclude = ["*.ipynb"]
lint.ignore = [
"B023", # function-uses-loop-variable
"COM812", # trailing commas (ruff-format recommended)
"D100", # undocumented-public-module
"D104", # undocumented-public-package
"D203", # no-blank-line-before-class
"D205", # blank line between summary and description in docstrings
"D212", # multi-line-summary-first-line
"D401", # non-imperative-mood
"D407", # removed dashes lines under sections
"D417", # argument description in docstring (unreliable)
"ISC001", # simplify implicit str concatenation (ruff-format recommended)
"S101", # assert
]
lint.per-file-ignores = {"benchmarks*" = [
"D", # No docstring checks in benchmarks
], "tests*" = [
"D", # No docstring checks in tests
"INP001", # File is part of an implicit namespace package.
"S101", # Use of `assert` detected
], "__init__.py" = [
"F401" # unused-import
]}
lint.select = [
"B",
"C90",
"D",
"E1",
"E4",
"E7",
"E9",
"F",
"I",
"S",
"UP",
]
lint.isort.known-first-party = [
"s2fft"
]
lint.mccabe.max-complexity = 18
lint.pep8-naming.classmethod-decorators = [
"classmethod",
]

[tool.setuptools]
packages = ["s2fft"]

Expand Down
20 changes: 14 additions & 6 deletions s2fft/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import logging

import jax

from . import logs
from .transforms import wigner
from .transforms.spherical import *
from .recursions.price_mcewen import (
generate_precomputes,
generate_precomputes_jax,
generate_precomputes_wigner,
generate_precomputes_wigner_jax,
)
from .utils.rotation import rotate_flms, generate_rotate_dls

import logging
import jax
from .transforms import wigner
from .transforms.spherical import (
forward,
forward_jax,
forward_numpy,
inverse,
inverse_jax,
inverse_numpy,
)
from .utils.rotation import generate_rotate_dls, rotate_flms

if jax.config.read("jax_enable_x64") is False:
logger = logging.getLogger("s2fft")
Expand Down
3 changes: 1 addition & 2 deletions s2fft/base_transforms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import spherical
from . import wigner
from . import spherical, wigner
Loading

0 comments on commit 268646b

Please sign in to comment.