Skip to content
Open
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
94 changes: 94 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CI

on:
push:
branches: [master, main]
pull_request:
branches: [master, main]

jobs:
pre-commit:
name: Pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.14"

- name: Run pre-commit
run: uvx pre-commit run --all-files

test:
name: Test (Python ${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
include:
- os: macos-latest
python-version: "3.14"
- os: windows-latest
python-version: "3.14"

steps:
- uses: actions/checkout@v4

- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --extra testing

- name: Run tests
run: uv run pytest -v

build:
name: Build & verify package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.14"

- name: Build package
run: uv build

- name: Verify wheel installs and works
run: |
# Create a fresh project to test installation
cd /tmp
uv init test-install
cd test-install
uv add ${{ github.workspace }}/dist/*.whl

# Test that it imports and basic functionality works
uv run python -c "
import blurhash
print(f'Version: {blurhash.__version__}')

# Test encode with a simple image
from PIL import Image
img = Image.new('RGB', (100, 100), color='red')
hash = blurhash.encode(img, 4, 3)
print(f'Encoded: {hash}')
assert len(hash) > 0

# Test decode
decoded = blurhash.decode(hash, 50, 50)
assert decoded.size == (50, 50)
print('Decode: OK')

# Test is_valid_blurhash
assert blurhash.is_valid_blurhash(hash)
print('All checks passed!')
"
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-ast
- id: check-added-large-files
- id: check-merge-conflict
- id: check-case-conflict
- id: check-docstring-first
- id: check-json
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude: 'CHANGELOG.md'
- id: trailing-whitespace
- id: mixed-line-ending
- repo: local
hooks:
- id: ruff-format
name: ruff-format
entry: uv run ruff format
require_serial: true
language: system
types: [ python ]
- id: ruff
name: ruff
# Add --fix, in case you want it to autofix when this hook runs
entry: uv run ruff check --force-exclude
require_serial: true
language: system
types: [ python ]
11 changes: 0 additions & 11 deletions Pipfile

This file was deleted.

21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Install blurhash with pip
```
$ pip install blurhash-python
```
or pipenv
or uv
```
$ pipenv install blurhash-python
$ uv add blurhash-python
```

Usage
Expand Down Expand Up @@ -44,18 +44,23 @@ be `>= 1` and `<= 9`.

Development
-----------
Install development requirements and package in editable mode
Install development dependencies and package in editable mode
```
$ pipenv install --dev
$ uv sync
```

Install pre-commit hooks
```
$ uvx pre-commit install
```

Tests
-----
Run test suite with `pytest` in virtual environment
Run test suite with pytest
```
$ pytest
$ uv run pytest
```
Use `tox` to run test suite against all supported python versions
Use tox to run test suite against all supported Python versions (3.10-3.14)
```
$ tox
$ uv run tox
```
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TMPDIST="$(mktemp -d)"
USERBASE="$(mktemp -d)"
trap "rm -rf '$TMPDIST' '$USERBASE'" EXIT

pybins=(/opt/python/cp{38,39,310,311,312}-cp*/bin)
pybins=(/opt/python/cp{310,311,312,313,314}-cp*/bin)

SRCDIST="$(ls -vr dist/blurhash-python-*.tar.gz | head -n1)"

Expand Down
50 changes: 48 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta:__legacy__"
requires = ["setuptools", "wheel", "cffi", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "blurhash-python"
description = "BlurHash encoder implementation for Python"
readme = "README.md"
license = "MIT"
authors = [
{ name = "Atte Lautanala", email = "atte.lautanala@wolt.com" }
]
requires-python = ">=3.10"
dynamic = ["version"]
dependencies = [
"cffi",
"Pillow",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]

[project.urls]
Homepage = "https://blurha.sh"
Repository = "https://github.com/woltapp/blurhash-python"

[project.optional-dependencies]
testing = ["pytest"]

[dependency-groups]
dev = [
"pytest",
"ruff>=0.14.14",
"tox",
]

[tool.setuptools]
package-dir = { "" = "src" }
packages = ["blurhash"]

[tool.setuptools_scm]
write_to = "src/blurhash/_version.py"
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

49 changes: 3 additions & 46 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,8 @@
#!/usr/bin/env python
# Minimal setup.py required for CFFI extension building
# All metadata is in pyproject.toml
from setuptools import setup


with open('README.md', 'r') as readme_file:
long_description = readme_file.read()


tests_require = [
'pytest',
]

setup(
name='blurhash-python',
description='BlurHash encoder implementation for Python',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://blurha.sh',
use_scm_version=dict(
write_to='src/blurhash/_version.py',
),
author='Atte Lautanala',
author_email='atte.lautanala@wolt.com',
packages=['blurhash'],
package_dir={'': 'src'},
install_requires=[
'cffi',
'Pillow',
'six',
],
setup_requires=[
'cffi',
'setuptools-scm',
],
cffi_modules=['src/build_blurhash.py:ffibuilder'],
tests_require=tests_require,
extras_require={
'testing': tests_require,
},
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
cffi_modules=["src/build_blurhash.py:ffibuilder"],
)
Loading