Skip to content
Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
with:
python-version: 3.14
- name: Install dependencies
run: python -m pip install pre-commit
run: python -m pip install prek uv
- name: Cache pre-commit environments
uses: actions/cache@v5
with:
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
path: ~/.cache/pre-commit
key: prek|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
path: ~/.cache/prek
- name: Run pre-commit hooks
run: pre-commit run -a --show-diff-on-failure --color=always
run: prek run -a --show-diff-on-failure --color=always
50 changes: 20 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# priorities:
# 0 - read-only
# 1000 - mutually non-conflicting fixers
# none - other fixers

# exclude vendored files
exclude: '^(api/|demo/openseadragon-scalebar\.js)'

Expand All @@ -6,51 +11,32 @@ repos:
rev: v6.0.0
hooks:
- id: check-added-large-files
priority: 0
- id: check-merge-conflict
priority: 0
- id: check-vcs-permalinks
priority: 0
- id: check-yaml
priority: 0
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.21.2
hooks:
- id: pyupgrade
name: Modernize Python code
args: ["--py313-plus"]

- repo: https://github.com/PyCQA/isort
rev: 8.0.1
hooks:
- id: isort
name: Reorder Python imports with isort

- repo: https://github.com/psf/black
rev: 26.3.1
hooks:
- id: black
name: Format Python code with black

- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa
additional_dependencies: [flake8-bugbear, Flake8-pyproject]

- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.10
hooks:
- id: flake8
name: Lint Python code with flake8
additional_dependencies: [flake8-bugbear, Flake8-pyproject]
- id: ruff-check
types_or: [python, pyproject]
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.20.0
hooks:
- id: mypy
name: Check Python types
priority: 0
additional_dependencies:
- boto3-stubs[s3]
- types-Pillow
Expand All @@ -63,16 +49,20 @@ repos:
hooks:
- id: codespell
name: Check spelling with codespell
priority: 0

- repo: meta
hooks:
- id: check-hooks-apply
priority: 0
- id: check-useless-excludes
priority: 0

- repo: local
hooks:
- id: annotations
name: Require "from __future__ import annotations"
priority: 0
language: pygrep
types: [python]
# Allow files with import statement, or of less than two characters.
Expand Down
2 changes: 1 addition & 1 deletion _testdata/testdata_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def fetch_file(
sha.update(buf)
count += len(buf)
if count != int(r.headers['Content-Length']):
raise OSError(f"Short read fetching {relpath}")
raise OSError(f'Short read fetching {relpath}')
if expected_sha256 is not None and expected_sha256 != sha.hexdigest():
raise OSError(f'Hash mismatch fetching {relpath}')
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions _testdata/testdata_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
)
OPTIONAL_FIELDS = frozenset(('credit',))

INDEX_TEMPLATE = '''<!doctype html>
INDEX_TEMPLATE = """<!doctype html>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<style type="text/css">
table {
Expand Down Expand Up @@ -129,7 +129,7 @@
extra.size|file_size_units, extra.description) }}
{% endfor %}
</table>
''' # noqa: E501
"""


class ValidationError(Exception):
Expand Down
26 changes: 12 additions & 14 deletions demo/_synctiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
from zipfile import ZipFile
import zlib

from PIL import ImageCms
from PIL.Image import Image
from PIL.ImageCms import ImageCmsProfile
import boto3
import openslide
from openslide import (
Expand All @@ -52,6 +49,9 @@
OpenSlideError,
)
from openslide.deepzoom import DeepZoomGenerator
from PIL import ImageCms
from PIL.Image import Image
from PIL.ImageCms import ImageCmsProfile
import requests

if TYPE_CHECKING:
Expand Down Expand Up @@ -221,9 +221,7 @@ def _get_transform(image: AbstractSlide) -> Callable[[Image], None]:
"""Return a function that transforms an image to sRGB in place."""
if image.color_profile is None:
return lambda img: None
intent: int = ImageCms.getDefaultIntent(
image.color_profile
) # type: ignore[no-untyped-call]
intent: int = ImageCms.getDefaultIntent(image.color_profile) # type: ignore[no-untyped-call]
transform = ImageCms.buildTransform(
image.color_profile, SRGB_PROFILE, 'RGB', 'RGB', intent, 0
)
Expand Down Expand Up @@ -344,8 +342,8 @@ def sync_image(

def progress() -> None:
print(
f"Tiling {slide_relpath} {associated_slug}: "
f"{count}/{total} tiles\r",
f'Tiling {slide_relpath} {associated_slug}: '
f'{count}/{total} tiles\r',
end='',
)
sys.stdout.flush()
Expand Down Expand Up @@ -462,7 +460,7 @@ def sync_slide(
# slide will be None if we can't read it

# Enumerate existing keys
print(f"Enumerating keys for {slide_relpath}...")
print(f'Enumerating keys for {slide_relpath}...')
key_md5sums = {}
for obj in storage.bucket.objects.filter(
Prefix=key_basepath.as_posix() + '/'
Expand Down Expand Up @@ -536,8 +534,8 @@ def do_tile(
for name in metadata_key_name, properties_key_name:
key_md5sums.pop(name, None)
if key_md5sums:
to_delete = [k for k in key_md5sums]
print(f"Pruning {len(to_delete)} keys for {slide_relpath}...")
to_delete = list(key_md5sums)
print(f'Pruning {len(to_delete)} keys for {slide_relpath}...')
while to_delete:
cur_delete, to_delete = to_delete[0:1000], to_delete[1000:]
delete_result = storage.bucket.delete_objects(
Expand Down Expand Up @@ -602,7 +600,7 @@ def start_retile(
storage = S3Storage(bucket_name)

# Set bucket configuration
print("Configuring bucket...")
print('Configuring bucket...')
storage.bucket.Cors().put(
CORSConfiguration={
'CORSRules': [
Expand All @@ -615,7 +613,7 @@ def start_retile(
)

# Store static files
print("Storing static files...")
print('Storing static files...')
for relpath, opts in BUCKET_STATIC.items():
storage.object(relpath).put(
Body=opts.get('data', '').encode(),
Expand All @@ -638,7 +636,7 @@ def start_retile(
json.dump(context, ctxfile)
with matrixfile:
matrix: Matrix = {
"slide": sorted(slides.keys()),
'slide': sorted(slides.keys()),
}
json.dump(matrix, matrixfile)

Expand Down
8 changes: 4 additions & 4 deletions docs/devguide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ addressing feedback from code review, edit your existing commits with `git
rebase -i` and update the branch with `git push -f`, rather than appending
fixup commits to the branch.

OpenSlide uses Git hooks and the [pre-commit][pre-commit] framework to
OpenSlide uses Git hooks and the [prek][prek] framework to
check coding style when you commit. To configure the hooks, install
pre-commit from your package manager or with `pip install pre-commit`, then
run `pre-commit install` in your OpenSlide checkout. The pre-commit checks
prek from your package manager or with `pip install prek`, then
run `prek install` in your OpenSlide checkout. The pre-commit checks
are also rerun as part of OpenSlide's CI.

Please discuss your changes on the [openslide-users][users-subscribe]
Expand All @@ -52,7 +52,7 @@ license. See the [submission form][submit-sample] for more details.

[rjones]: https://people.redhat.com/~rjones/how-to-supply-code-to-open-source-projects/
[rjones-splitting-commits]: https://people.redhat.com/~rjones/how-to-supply-code-to-open-source-projects/#split_patches
[pre-commit]: https://pre-commit.com/
[prek]: https://prek.j178.dev/
[cc0]: https://creativecommons.org/publicdomain/zero/1.0/legalcode


Expand Down
27 changes: 13 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
[tool.black]
line-length = 79
skip-string-normalization = true
target-version = ["py313", "py314"]

# Ref: https://github.com/codespell-project/codespell#using-a-config-file
[tool.codespell]
check-hidden = true
# ignore-regex = ""
ignore-words-list = "subtile"

# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
# requires Flake8-pyproject
[tool.flake8]
extend-ignore = ["E203"]

[tool.isort]
profile = "black"
force_sort_within_sections = true

[tool.mypy]
namespace_packages = false
python_version = "3.13"
strict = true

[tool.ruff]
line-length = 79
target-version = "py313"

[tool.ruff.format]
quote-style = "single"

[tool.ruff.lint]
extend-select = ["B", "C4", "FLY", "I", "RUF", "UP"]

[tool.ruff.lint.isort]
force-sort-within-sections = true