Skip to content

Commit

Permalink
Merge pull request #42 from ksunden/ruff_docs
Browse files Browse the repository at this point in the history
Switch to ruff, fix doc build (pickle of conf.py)
  • Loading branch information
tacaswell authored Jul 11, 2024
2 parents 0a31b25 + 431399c commit f68736b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 38 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/flake8.yml → .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Code Style - FLAKE8
name: Check Code Style - ruff

on: [push, pull_request]

Expand All @@ -15,7 +15,7 @@ jobs:
# installation problems if out of date.
python -m pip install --upgrade pip setuptools numpy
pip install flake8
- name: Run flake8
pip install ruff
- name: Run ruff
run: |
flake8
ruff check
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
default_language_version:
python: python3
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.1
hooks:
# Run the linter.
- id: ruff
- repo: https://github.com/ambv/black
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
hooks:
- id: flake8
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ Ready to contribute? Here's how to set up `data_prototype` for local development

Now you can make your changes locally.

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

$ flake8 data_prototype tests
$ ruff check
$ python setup.py test
$ tox

Expand Down
12 changes: 6 additions & 6 deletions data_prototype/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

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

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

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

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

Expand Down
21 changes: 3 additions & 18 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# sys.path.insert(0, os.path.abspath('.'))
from pathlib import Path

import data_prototype

# are we running circle CI?
CIRCLECI = "CIRCLECI" in os.environ

Expand Down Expand Up @@ -64,21 +66,6 @@

# Sphinx gallery configuration


def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf, **kwargs):
"""
Reduce srcset when creating a PDF.
Because sphinx-gallery runs *very* early, we cannot modify this even in the
earliest builder-inited signal. Thus we do it at scraping time.
"""
from sphinx_gallery.scrapers import matplotlib_scraper

if gallery_conf["builder_name"] == "latex":
gallery_conf["image_srcset"] = []
return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs)


sphinx_gallery_conf = {
"examples_dirs": [
"../../examples",
Expand All @@ -89,11 +76,10 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf, **kwargs):
"reference_url": {
"matplotlib": None,
},
"backreferences_dir": Path("api") / Path("_as_gen"),
"backreferences_dir": Path("api", "_as_gen"),
"remove_config_comments": True,
"min_reported_time": 1,
"thumbnail_size": (320, 224),
"image_scrapers": (matplotlib_reduced_latex_scraper,),
# Compression is a significant effort that we skip for local and CI builds.
"compress_images": ("thumbnails", "images") if is_release_build else (),
"matplotlib_animations": True,
Expand Down Expand Up @@ -126,7 +112,6 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf, **kwargs):
# |version| and |release|, also used in various other places throughout the
# built documents.
#
import data_prototype

# The short X.Y version.
version = data_prototype.__version__
Expand Down
6 changes: 3 additions & 3 deletions examples/mandelbrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def mandelbrot_set(X, Y, maxiter, *, horizon=3, power=2):
N = np.zeros_like(C, dtype=int)
Z = np.zeros_like(C)
for n in range(maxiter):
I = abs(Z) < horizon
N += I
Z[I] = Z[I] ** power + C[I]
mask = abs(Z) < horizon
N += mask
Z[mask] = Z[mask] ** power + C[mask]
N[N == maxiter] = -1
return Z, N

Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# the documentation) but not necessarily required for _using_ it.
codecov
coverage
flake8
pytest
sphinx
twine
pre-commit
black
nbstripout
ruff
# These are dependencies of various sphinx extensions for documentation.
ipython
matplotlib
Expand Down

0 comments on commit f68736b

Please sign in to comment.