Skip to content

Commit f68736b

Browse files
authored
Merge pull request #42 from ksunden/ruff_docs
Switch to ruff, fix doc build (pickle of conf.py)
2 parents 0a31b25 + 431399c commit f68736b

File tree

7 files changed

+25
-38
lines changed

7 files changed

+25
-38
lines changed

.github/workflows/flake8.yml renamed to .github/workflows/ruff.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Check Code Style - FLAKE8
1+
name: Check Code Style - ruff
22

33
on: [push, pull_request]
44

@@ -15,7 +15,7 @@ jobs:
1515
# installation problems if out of date.
1616
python -m pip install --upgrade pip setuptools numpy
1717
18-
pip install flake8
19-
- name: Run flake8
18+
pip install ruff
19+
- name: Run ruff
2020
run: |
21-
flake8
21+
ruff check

.pre-commit-config.yaml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
default_language_version:
22
python: python3
33
repos:
4+
- repo: https://github.com/astral-sh/ruff-pre-commit
5+
# Ruff version.
6+
rev: v0.5.1
7+
hooks:
8+
# Run the linter.
9+
- id: ruff
410
- repo: https://github.com/ambv/black
511
rev: 24.2.0
612
hooks:
713
- id: black
8-
- repo: https://github.com/pre-commit/pre-commit-hooks
9-
rev: v2.0.0
10-
hooks:
11-
- id: flake8
1214
- repo: https://github.com/kynan/nbstripout
1315
rev: 0.7.1
1416
hooks:

CONTRIBUTING.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ Ready to contribute? Here's how to set up `data_prototype` for local development
7373

7474
Now you can make your changes locally.
7575

76-
5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox::
76+
5. When you're done making changes, check that your changes pass linting and the tests, including testing other Python versions with tox::
7777

78-
$ flake8 data_prototype tests
78+
$ ruff check
7979
$ python setup.py test
8080
$ tox
8181

data_prototype/image.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
def _interpolate_nearest(image, x, y):
1313
magnification = 1 # TODO
14-
l, r = x
15-
width = int(((round(r) + 0.5) - (round(l) - 0.5)) * magnification)
14+
lef, rig = x
15+
width = int(((round(rig) + 0.5) - (round(lef) - 0.5)) * magnification)
1616

17-
xpix = np.digitize(np.arange(width), np.linspace(0, r - l, image.shape[1]))
17+
xpix = np.digitize(np.arange(width), np.linspace(0, rig - lef, image.shape[1]))
1818

19-
b, t = y
20-
height = int(((round(t) + 0.5) - (round(b) - 0.5)) * magnification)
21-
ypix = np.digitize(np.arange(height), np.linspace(0, t - b, image.shape[0]))
19+
bot, top = y
20+
height = int(((round(top) + 0.5) - (round(bot) - 0.5)) * magnification)
21+
ypix = np.digitize(np.arange(height), np.linspace(0, top - bot, image.shape[0]))
2222

2323
out = np.empty((height, width, 4))
2424

docs/source/conf.py

+3-18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# sys.path.insert(0, os.path.abspath('.'))
2424
from pathlib import Path
2525

26+
import data_prototype
27+
2628
# are we running circle CI?
2729
CIRCLECI = "CIRCLECI" in os.environ
2830

@@ -64,21 +66,6 @@
6466

6567
# Sphinx gallery configuration
6668

67-
68-
def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf, **kwargs):
69-
"""
70-
Reduce srcset when creating a PDF.
71-
72-
Because sphinx-gallery runs *very* early, we cannot modify this even in the
73-
earliest builder-inited signal. Thus we do it at scraping time.
74-
"""
75-
from sphinx_gallery.scrapers import matplotlib_scraper
76-
77-
if gallery_conf["builder_name"] == "latex":
78-
gallery_conf["image_srcset"] = []
79-
return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs)
80-
81-
8269
sphinx_gallery_conf = {
8370
"examples_dirs": [
8471
"../../examples",
@@ -89,11 +76,10 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf, **kwargs):
8976
"reference_url": {
9077
"matplotlib": None,
9178
},
92-
"backreferences_dir": Path("api") / Path("_as_gen"),
79+
"backreferences_dir": Path("api", "_as_gen"),
9380
"remove_config_comments": True,
9481
"min_reported_time": 1,
9582
"thumbnail_size": (320, 224),
96-
"image_scrapers": (matplotlib_reduced_latex_scraper,),
9783
# Compression is a significant effort that we skip for local and CI builds.
9884
"compress_images": ("thumbnails", "images") if is_release_build else (),
9985
"matplotlib_animations": True,
@@ -126,7 +112,6 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf, **kwargs):
126112
# |version| and |release|, also used in various other places throughout the
127113
# built documents.
128114
#
129-
import data_prototype
130115

131116
# The short X.Y version.
132117
version = data_prototype.__version__

examples/mandelbrot.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def mandelbrot_set(X, Y, maxiter, *, horizon=3, power=2):
2727
N = np.zeros_like(C, dtype=int)
2828
Z = np.zeros_like(C)
2929
for n in range(maxiter):
30-
I = abs(Z) < horizon
31-
N += I
32-
Z[I] = Z[I] ** power + C[I]
30+
mask = abs(Z) < horizon
31+
N += mask
32+
Z[mask] = Z[mask] ** power + C[mask]
3333
N[N == maxiter] = -1
3434
return Z, N
3535

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# the documentation) but not necessarily required for _using_ it.
33
codecov
44
coverage
5-
flake8
65
pytest
76
sphinx
87
twine
98
pre-commit
109
black
1110
nbstripout
11+
ruff
1212
# These are dependencies of various sphinx extensions for documentation.
1313
ipython
1414
matplotlib

0 commit comments

Comments
 (0)