Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STY] run isort rules via ruff/pre-commit #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions .github/workflows/test-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@ jobs:
- name: Set up Python "3.10"
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Black setup
shell: bash
run: pip install black ruff
- name: Black Check
shell: bash
run: black . --diff --color
- name: ruff Check
shell: bash
run: ruff check src
python-version: "3.12"
- uses: pre-commit/[email protected]

makedocs:
name: build documentation
Expand All @@ -48,21 +40,9 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install .[optional,doc]

- name: Build API documentation
run: make -C docs html

codespell:
name: Check for spelling errors
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Annotate locations with typos
uses: codespell-project/codespell-problem-matcher@v1
- name: Codespell
uses: codespell-project/actions-codespell@v2

test-suite:
runs-on: ${{ matrix.os }}
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/update_precommit_hooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Update precommit hooks

on:

# Uses the cron schedule for github actions
#
# https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#scheduled-events
#
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
schedule:
# Run first day of the month at midnight UTC
- cron: 0 0 1 * *

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
update_precommit_hooks:

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
allow-prereleases: false
- name: Install pre-commit
run: pip install pre-commit
- name: Update pre-commit hooks
run: pre-commit autoupdate
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
commit-message: pre-commit hooks auto-update
base: main
token: ${{ secrets.GITHUB_TOKEN }}
delete-branch: true
title: '[BOT] update pre-commit hooks'
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

repos:
# Checks for spelling errors
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: [--toml, pyproject.toml]
additional_dependencies: [tomli]

- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
args: [--config, pyproject.toml]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
hooks:
# Run the linter.
- id: ruff
# args: [--statistics]
args: [--fix, --show-fixes]
# Run the formatter.
- id: ruff-format
9 changes: 5 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
list see the documentation:
https://www.sphinx-doc.org/en/master/usage/configuration.html
"""

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -43,7 +44,7 @@
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
# "sphinx_gallery.gen_gallery",
"sphinxarg.ext"
"sphinxarg.ext",
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -75,9 +76,9 @@
sphinx_gallery_conf = {
"examples_dirs": ["../examples/"],
"filename_pattern": "/example_",
'ignore_pattern': 'conftest.py',
'example_extensions': {'.py'},
"gallery_dirs" : ["auto_examples"],
"ignore_pattern": "conftest.py",
"example_extensions": {".py"},
"gallery_dirs": ["auto_examples"],
"reference_url": {
"numpy": "http://docs.scipy.org/doc/numpy-1.9.1",
"scipy": "http://docs.scipy.org/doc/scipy-0.17.0/reference",
Expand Down
4 changes: 3 additions & 1 deletion examples/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Configuration for testing the example scripts."""
from pathlib import Path

import runpy
from pathlib import Path

import pytest


Expand Down
2 changes: 0 additions & 2 deletions examples/example_experimental_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
Experimental Data denoising
===========================
"""


12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ doc = [
"sphinx",
]

dev = ["black", "isort", "ruff"]
dev = ["black", "ruff"]

[project.scripts]
patch-denoise = "patch_denoise.bindings.cli:main"
Expand Down Expand Up @@ -68,14 +68,16 @@ src = ["src", "tests"]
[tool.ruff.lint]
ignore = ["B905"]
exclude = ["examples/", "tests/"]
select = ["E", "F", "B", "Q", "UP", "D"]
select = ["E", "F", "B", "Q", "UP", "D", "I"]

[tool.ruff.lint.per-file-ignores]
"**/{tests}/*" = ["D100", "D103", "D104", "D205", "F841", "E501", "E402", "F401"]
"**/{examples}/*" = ["D400", "D205", "E501"]


[tool.ruff.lint.pydocstyle]
convention="numpy"

[tool.isort]
profile="black"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = [
Expand Down
11 changes: 6 additions & 5 deletions src/patch_denoise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Collection of patch-based denoising methods."""

from patch_denoise.denoise import (
mp_pca,
adaptive_thresholding,
hybrid_pca,
mp_pca,
nordic,
optimal_thresholding,
adaptive_thresholding,
raw_svt,
nordic,
)

from patch_denoise.space_time.lowrank import (
AdaptiveDenoiser,
HybridPCADenoiser,
Expand Down Expand Up @@ -39,9 +39,10 @@
except ImportError:
# -- Source mode --
# use setuptools_scm to get the current version from src using git
from setuptools_scm import get_version as _gv
from os import path as _path

from setuptools_scm import get_version as _gv

try:
__version__ = _gv(_path.join(_path.dirname(__file__), _path.pardir))
except LookupError:
Expand Down
1 change: 0 additions & 1 deletion src/patch_denoise/_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import inspect
from string import Template


docdict = dict(
patch_config="""
patch_shape: tuple
Expand Down
6 changes: 3 additions & 3 deletions src/patch_denoise/bindings/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

import numpy as np

from patch_denoise import __version__

from .utils import (
DENOISER_MAP,
DenoiseParameters,
compute_mask,
load_as_array,
save_array,
load_complex_nifti,
save_array,
)
from patch_denoise import __version__


DENOISER_NAMES = ", ".join(d for d in DENOISER_MAP if d)

Expand Down
2 changes: 1 addition & 1 deletion src/patch_denoise/bindings/nipype.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
)
from nipype.utils.filemanip import split_filename

from .utils import DENOISER_MAP, DenoiseParameters
from ..space_time.utils import estimate_noise
from .utils import DENOISER_MAP, DenoiseParameters


class PatchDenoiseInputSpec(BaseInterfaceInputSpec):
Expand Down
3 changes: 1 addition & 2 deletions src/patch_denoise/bindings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
import numpy as np

from patch_denoise.denoise import (
adaptive_thresholding,
hybrid_pca,
mp_pca,
nordic,
optimal_thresholding,
raw_svt,
adaptive_thresholding,
)


DENOISER_MAP = {
None: None,
"mp-pca": mp_pca,
Expand Down
1 change: 1 addition & 0 deletions src/patch_denoise/denoise.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provides a functional entry point for denoising methods."""

from ._docs import fill_doc
from .space_time.lowrank import (
AdaptiveDenoiser,
Expand Down
1 change: 1 addition & 0 deletions src/patch_denoise/simulation/noise.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to add different source of temporal noise to data."""

import numpy as np
from numpy.random import default_rng

Expand Down
1 change: 1 addition & 0 deletions src/patch_denoise/space_time/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Denoising Operator working on space-time dimension."""

from .base import BaseSpaceTimeDenoiser
from .lowrank import (
HybridPCADenoiser,
Expand Down
16 changes: 10 additions & 6 deletions src/patch_denoise/space_time/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,21 @@ def __init__(

# Calculate the shape and strides of the sliding view
grid_shape = tuple(
((self._arr.shape[i] - self._ps[i]) // step[i] + 1)
if self._ps[i] < self._arr.shape[i]
else 1
(
((self._arr.shape[i] - self._ps[i]) // step[i] + 1)
if self._ps[i] < self._arr.shape[i]
else 1
)
for i in range(dimensions)
)
shape = grid_shape + tuple(self._ps)
strides = (
tuple(
self._arr.strides[i] * step[i]
if self._ps[i] < self._arr.shape[i]
else 0
(
self._arr.strides[i] * step[i]
if self._ps[i] < self._arr.shape[i]
else 0
)
for i in range(dimensions)
)
+ self._arr.strides
Expand Down
Loading
Loading