Skip to content

Commit

Permalink
Update to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
rytheranderson committed Mar 30, 2024
1 parent 7d2cae3 commit af6a137
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 1,050 deletions.
20 changes: 5 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,17 @@ repos:
- id: check-added-large-files
- id: check-merge-conflict

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

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
additional_dependencies: [toml]

- repo: https://github.com/Lucas-C/pre-commit-hooks-markup
rev: v1.0.1
hooks:
- id: rst-linter

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings, flake8-bugbear]
- id: ruff
args: [ --fix ]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
Expand Down
1,316 changes: 319 additions & 997 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyfracgen/buddhabrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def _buddhabrot_paint(
sequence.extend(trial_sequence)
break
z = update_func(z, c)
for c in sequence:
indx = int((c.real - xmin) / (xmax - xmin) * width)
indy = int((c.imag - ymin) / (ymax - ymin) * height)
for sval in sequence:
indx = int((sval.real - xmin) / (xmax - xmin) * width)
indy = int((sval.imag - ymin) / (ymax - ymin) * height)
if (indx < 0 or indx >= width) or (indy < 0 or indy >= height):
continue
lattice[indy, indx] += 1
Expand Down
1 change: 1 addition & 0 deletions pyfracgen/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utility objects and methods used across the library."""

from __future__ import annotations

import pickle
Expand Down
6 changes: 3 additions & 3 deletions pyfracgen/images/images.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
from typing import Sequence

import matplotlib.animation as animation
from matplotlib import animation
import numpy as np
from matplotlib import colormaps, colors
from matplotlib import pyplot as plt
Expand Down Expand Up @@ -78,13 +78,13 @@ def markus_lyapunov_image(
fig, ax0 = plt.subplots(figsize=figaspect(res.image_array), dpi=res.dpi)
fig.subplots_adjust(0, 0, 1, 1)
ax0.imshow(
np.ma.masked_where(res.image_array > 0.0, res.image_array), # type: ignore[no-untyped-call] # noqa: E501
np.ma.masked_where(res.image_array > 0.0, res.image_array), # type: ignore[no-untyped-call]
cmap=cmap_neg,
origin="lower",
norm=colors.PowerNorm(gammas[0]),
)
ax0.imshow(
np.ma.masked_where(res.image_array < 0.0, res.image_array), # type: ignore[no-untyped-call] # noqa: E501
np.ma.masked_where(res.image_array < 0.0, res.image_array), # type: ignore[no-untyped-call]
cmap=cmap_pos,
origin="lower",
norm=colors.PowerNorm(gammas[1]),
Expand Down
36 changes: 16 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,33 @@ numpy = "^1.26.2"
nptyping = "^2.5.0"

[tool.poetry.group.dev.dependencies]
black = ">=23.3,<25.0"
cruft = "^2.15.0"
flake8 = ">=6.1,<8.0"
flake8-docstrings = "^1.7.0"
flake8-bugbear = ">=23.5.9,<25.0.0"
hypothesis = "^6.75.6"
isort = "^5.12.0"
mypy = "^1.7.1"
pre-commit = "^3.3.2"
pytest = ">=7.3.1,<9.0.0"
pytest-cov = "^4.1.0"
pytest-mock = "^3.10.0"
ruff = "^0.3.4"
tbump = "^6.10.0"
tox = "^3.24"
tox-gh-actions = "^2.8"
tox-poetry-installer = "^0.10.0"

[tool.black]
line-length = 88
experimental_string_processing = true
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.mypy_cache
| \.tox
| \.venv
| build
| dist
)/
'''
[tool.ruff.lint]
# B = flake8-bugbear
# C9 = mccabe complexity
# E = pycodestyle error
# F = pyflakes
# N = pep8-naming
# PL = pylint
# Q = flake8-quotes
# RUF = ruf
# W = pycodestyle warning
select = ["B", "C9", "D", "E", "F", "N", "PL", "Q", "RUF", "W"]
ignore = ["D10", "PLR0913"]

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

[tool.tbump.version]
current = "0.2.0"
Expand Down
8 changes: 0 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ omit = tests/*
[tool:pytest]
addopts = -s -vv --cov=pyfracgen --cov-config=setup.cfg --cov-report=term-missing

[flake8]
exclude = .git,__pycache__,doc/*,build,dist,.tox
extend_ignore =
W503
D # ignore all docstring things for now
max-complexity = 12
max-line-length = 88

[mypy]
check_untyped_defs = True
disallow_untyped_defs = True
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fixtures for testing pyfracgen."""

from pathlib import Path

import pytest
Expand Down
6 changes: 4 additions & 2 deletions tests/test_julia.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_julia_paint_colors_correctly(
Args:
x: The point x-value (real part).
y: The point y-value (imaginary part).
c: The c-value for the Julia set.
expected_color: The expected color for the point (x, y).
"""
lattice = np.zeros((1, 1), dtype=np.float64)
Expand All @@ -72,10 +73,11 @@ def test_single_point_escape(z: complex, c: complex) -> None:
"""Test that a single point escapes or does not escape as expected.
If any Q(z) > max(2, abs(c)), where Q is the orbit of z, then z escapes.
https://www.marksmath.org/classes/Spring2019ComplexDynamics/text/section-filled_julia_set.html # noqa: E501
https://www.marksmath.org/classes/Spring2019ComplexDynamics/text/section-filled_julia_set.html
Args:
c: The single point to test.
z: The single point to test escape for.
c: The c-value for the Julia set.
"""
res = Julia(1, 1, 1, (z.real, z.real), (z.imag, z.imag))
res.paint(c, power, MAXITER, 2.0**40, False)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_mandelbrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@


def point_escapes(c: complex) -> bool:
if abs(c) > 2:
threshold = 2
if abs(c) > threshold:
return True
z = c
for _ in range(MAXITER):
z = power(z, c)
if abs(z) > 2:
if abs(z) > threshold:
return True
return False

Expand Down

0 comments on commit af6a137

Please sign in to comment.