Skip to content

Commit

Permalink
Merge pull request #28 from larrybradley/add-ruff
Browse files Browse the repository at this point in the history
Add Ruff to pre-commit checks
  • Loading branch information
larrybradley authored Aug 8, 2024
2 parents dc1f49b + 369b3f1 commit ea05142
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ repos:
- id: python-check-blanket-noqa
# Enforce that all noqa annotations always occur with specific codes.

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.7"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
Expand Down
25 changes: 16 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@
from importlib import metadata
from pathlib import Path

from sphinx.util import logging

if sys.version_info < (3, 11):
import tomli as tomllib
else:
import tomllib

logger = logging.getLogger(__name__)

try:
from sphinx_astropy.conf.v1 import * # noqa: F403
except ImportError:
print('ERROR: the documentation requires the sphinx-astropy package to '
'be installed')
msg = ('The documentation requires the sphinx-astropy package to be '
'installed. Please install the "docs" requirements.')
logger.error(msg)
sys.exit(1)

# Get configuration information from pyproject.toml
Expand All @@ -44,7 +49,8 @@
# needs_sphinx = '3.0'

# Extend astropy intersphinx_mapping with packages we use here
# intersphinx_mapping['skimage'] = ('https://scikit-image.org/docs/stable/', None) noqa: F405
# intersphinx_mapping.update( # nosq: F405
# {'skimage': = ('https://scikit-image.org/docs/stable/', None)})

# Exclude astropy intersphinx_mapping for unused packages
del intersphinx_mapping['h5py'] # noqa: F405
Expand Down Expand Up @@ -159,12 +165,13 @@
# Uncomment the following lines to enable the exceptions:
nitpick_filename = 'nitpick-exceptions.txt'
if os.path.isfile(nitpick_filename):
for line in open(nitpick_filename):
if line.strip() == '' or line.startswith('#'):
continue
dtype, target = line.split(None, 1)
target = target.strip()
nitpick_ignore.append((dtype, target))
with open(nitpick_filename) as fh:
for line in fh:
if line.strip() == '' or line.startswith('#'):
continue
dtype, target = line.split(None, 1)
target = target.strip()
nitpick_ignore.append((dtype, target))

# -- Options for linkcheck output ---------------------------------------------
linkcheck_retry = 5
Expand Down
8 changes: 4 additions & 4 deletions lacosmic/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is used to configure the behavior of pytest when using the Astropy
# test infrastructure. It needs to live inside the package in order for it to
# get picked up when running the tests inside an interpreter using
# packagename.test
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
Configuration file for the pytest test suite.
"""

import numpy as np
from astropy.utils import minversion
Expand Down
8 changes: 4 additions & 4 deletions lacosmic/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def lacosmic(data, contrast, cr_threshold, neighbor_threshold,
that case, try inputing a ``mask`` or increasing the value of
``cr_threshold``.
border_mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional
border_mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, \
optional
The mode in which the array borders are handled during
convolution and median filtering. For 'constant', the fill
value is 0. The default is 'mirror', which matches the original
Expand All @@ -119,9 +120,8 @@ def lacosmic(data, contrast, cr_threshold, neighbor_threshold,
clean_data += background
final_crmask = np.zeros(data.shape, dtype=bool)

if error is not None:
if data.shape != error.shape:
raise ValueError('error and data must have the same shape')
if error is not None and data.shape != error.shape:
raise ValueError('error and data must have the same shape')
clean_error_image = error

ncosmics, ncosmics_tot = 0, 0
Expand Down
10 changes: 6 additions & 4 deletions lacosmic/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from numpy.testing import assert_allclose, assert_array_equal

from ..core import lacosmic
from lacosmic.core import lacosmic

size = 25
npts = 20
Expand Down Expand Up @@ -93,13 +93,15 @@ def test_error_image_size(self):
image.
"""
error = np.zeros((7, 7))
with pytest.raises(ValueError):
match = 'error and data must have the same shape'
with pytest.raises(ValueError, match=match):
lacosmic(CR_IMG, 3, 2, 2, effective_gain=1, readnoise=0,
error=error)

def test_error_inputs(self):
with pytest.raises(ValueError):
match = 'effective_gain and readnoise must be input if error is not'
with pytest.raises(ValueError, match=match):
lacosmic(CR_IMG, 3, 2, 2, effective_gain=1, error=None)

with pytest.raises(ValueError):
with pytest.raises(ValueError, match=match):
lacosmic(CR_IMG, 3, 2, 2, readnoise=0, error=None)
35 changes: 32 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,10 @@ exclude_lines = [
[tool.repo-review]
ignore = [
'MY', # ignore MyPy
'RF', # ignore Ruff
'PC110', # ignore using black or ruff-format in pre-commit
'PC111', # ignore using blacken-docs in pre-commit
'PC140', # ignore using mypy in pre-commit
'PC180', # ignore using prettier in pre-commit
'PC190', # ignore using Ruff in pre-commit
'PC191', # ignore showing Ruff fixes in pre-commit
'PC901', # ignore using custom pre-commit update message
'PY005', # ignore having a tests/ folder
]
Expand Down Expand Up @@ -189,3 +186,35 @@ exclude = [
wrap-summaries = 72
pre-summary-newline = true
make-summary-multi-line = true

[tool.ruff]
line-length = 79

[tool.ruff.lint.pylint]
max-statements = 130

[tool.ruff.lint]
select = ['ALL']
ignore = [
'ANN',
'COM812',
'D102',
'D200',
'D203',
'D205',
'D212',
'D413',
'EM101',
'FBT002',
'FIX002',
'I001',
'PLR0913',
'PTH',
'Q000',
'TRY003',
]

[tool.ruff.lint.per-file-ignores]
'__init__.py' = ['D104', 'I']
'conftest.py' = ['D103']
'docs/conf.py' = ['ERA001', 'INP001', 'TRY400']

0 comments on commit ea05142

Please sign in to comment.