Metadata-Version: 2.4
Name: kellerlab-pre-commit-hooks
Version: 0.2.1
Summary: Reusable pre-commit hooks for OpenSCAD projects
Author-email: Patrick Pötz <kellervater@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/kellerlabs/pre-commit-hooks
Project-URL: Repository, https://github.com/kellerlabs/pre-commit-hooks
Project-URL: Issues, https://github.com/kellerlabs/pre-commit-hooks/issues
Project-URL: Changelog, https://github.com/kellerlabs/pre-commit-hooks/blob/main/CHANGELOG.md
Keywords: pre-commit,openscad,image-optimization,scadm
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: scadm>=0.6.0
Requires-Dist: Pillow>=11.0.0
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: license-file

# 🔧 Pre-commit Hooks

Reusable [pre-commit](https://pre-commit.com/) hooks for OpenSCAD projects.

Published on PyPI as [`kellerlab-pre-commit-hooks`](https://pypi.org/project/kellerlab-pre-commit-hooks/).

## 📌 What

Two hooks for OpenSCAD-based 3D printing projects:

| Hook | Description |
|------|-------------|
| `flatten-validate` | Runs `scadm flatten --all` and fails if flattened files have uncommitted changes |
| `optimize-images` | Resizes oversized JPEGs, compresses them, and strips EXIF data (privacy) |

## 🔧 Usage

Add to your `.pre-commit-config.yaml`:

```yaml
- repo: https://github.com/kellerlabs/pre-commit-hooks
  rev: v0.1.0  # use latest tag
  hooks:
    - id: flatten-validate
    - id: optimize-images
```

### `flatten-validate`

Flattens OpenSCAD files via [scadm](https://pypi.org/project/scadm/) and validates that the output is committed. Reads flatten config from `scadm.json` automatically.

```yaml
- id: flatten-validate
  # Override trigger pattern (default: always_run)
  always_run: false
  files: '^(scadm\.json|models/.*\.scad)'
```

**Options:**

| Arg | Default | Description |
|-----|---------|-------------|
| `--flatten-dir` | Read from `scadm.json` | Override flatten output dirs (list of paths/globs) |

### `optimize-images`

Resizes JPEGs exceeding max width, compresses to target quality, and strips EXIF metadata (removes GPS coordinates from real-life photos).

```yaml
- id: optimize-images
  args: [--max-width=1920, --quality=85]
```

**Options:**

| Arg | Default | Description |
|-----|---------|-------------|
| `--max-width` | `1920` | Maximum image width in pixels |
| `--quality` | `85` | JPEG compression quality (1-95) |

Both hooks **fail when files are modified**, printing instructions to `git add` the changes. Re-run `git commit` after staging.

## 🏗️ Used In

- [kellerlabs/homeracker](https://github.com/kellerlabs/homeracker) — HomeRacker Core
- [kellerlabs/homeracker-exclusive](https://github.com/kellerlabs/homeracker-exclusive) — HomeRacker MakerWorld models

## 🤝 Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).

## 📜 License

MIT
