|
| 1 | +# Copilot Instructions for Pillow |
| 2 | + |
| 3 | +## What this project is |
| 4 | + |
| 5 | +Pillow is the Python Imaging Library fork — a Python 3.10+ library for opening, |
| 6 | +manipulating, and saving many image file formats. It is a mix of Python and C: |
| 7 | +pure Python format plugins live in `src/PIL/`, and eight C extension modules |
| 8 | +(`_imaging`, `_imagingcms`, `_imagingft`, `_imagingmath`, `_imagingmorph`, |
| 9 | +`_imagingtk`, `_avif`, `_webp`) are compiled at install time via `setup.py`. |
| 10 | + |
| 11 | +## Project layout |
| 12 | + |
| 13 | +``` |
| 14 | +src/PIL/ Python source and C extension stubs (.pyi) |
| 15 | +src/thirdparty/ Vendored C libraries (raqm, fribidi-shim, pythoncapi_compat) |
| 16 | +Tests/ pytest test suite; Tests/helper.py has shared utilities |
| 17 | +docs/ Sphinx documentation (RST) |
| 18 | +docs/releasenotes/ Per-release changelog entries |
| 19 | +setup.py C extension build configuration |
| 20 | +_custom_build/ Custom setuptools build backend |
| 21 | +src/PIL/_version.py Version number (PEP 440) |
| 22 | +pyproject.toml Project metadata and optional dependency groups |
| 23 | +.pre-commit-config.yaml All linting and formatting hooks |
| 24 | +``` |
| 25 | + |
| 26 | +## Install |
| 27 | + |
| 28 | +```bash |
| 29 | +python3 -m pip install -e ".[tests]" |
| 30 | +``` |
| 31 | + |
| 32 | +The C extensions are compiled during install. Native libraries (libjpeg, |
| 33 | +libpng, libtiff, libwebp, freetype2, littlecms2, etc.) must already be present |
| 34 | +on the system. |
| 35 | + |
| 36 | +## Test |
| 37 | + |
| 38 | +```bash |
| 39 | +python3 selftest.py # quick sanity check |
| 40 | +python3 -m pytest Tests/ # full test suite |
| 41 | +python3 -m pytest Tests/ -n auto # parallel (requires pytest-xdist) |
| 42 | +``` |
| 43 | + |
| 44 | +Always run `python3 selftest.py` first. New features and bug fixes must include |
| 45 | +tests. Test files follow the naming pattern `Tests/test_*.py`. |
| 46 | + |
| 47 | +## Lint and format |
| 48 | + |
| 49 | +```bash |
| 50 | +make lint # runs tox -e lint → pre-commit (black, ruff, clang-format, |
| 51 | + # bandit, sphinx-lint, pyproject-fmt, and more) |
| 52 | +make lint-fix # auto-fixes black and ruff violations |
| 53 | +``` |
| 54 | + |
| 55 | +Or run pre-commit directly: |
| 56 | + |
| 57 | +```bash |
| 58 | +pre-commit run --all-files |
| 59 | +``` |
| 60 | + |
| 61 | +All hooks must pass before a PR can be merged. Separate reformatting commits |
| 62 | +from functional commits. |
| 63 | + |
| 64 | +## Type checking |
| 65 | + |
| 66 | +```bash |
| 67 | +python3 -m tox -e mypy |
| 68 | +``` |
| 69 | + |
| 70 | +## Documentation |
| 71 | + |
| 72 | +Docs use Sphinx/RST. Build locally with `make docserve`. Release notes go in |
| 73 | +`docs/releasenotes/<version>.rst` using the existing section structure |
| 74 | +(Security, Backwards incompatible changes, Deprecations, API changes, API |
| 75 | +additions, Other changes). Use the `:cve:` RST role for CVE references. |
| 76 | +Include a release note entry for any user-visible change. |
| 77 | + |
| 78 | +## CI checks (must all pass before merge) |
| 79 | + |
| 80 | +GitHub Actions runs: `test.yml` (pytest on Linux/macOS/Windows), `lint.yml` |
| 81 | +(pre-commit), `docs.yml` (Sphinx build), and `wheels.yml` on tag push. |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## Pillow-specific guidance |
| 86 | + |
| 87 | +Use `python3` and `python3 -m pip install` — never `python` or bare `pip`. |
| 88 | + |
| 89 | +`Image.open()` takes a `formats=` argument (list/tuple of format IDs to |
| 90 | +allowlist). There is no `format=` parameter. |
| 91 | + |
| 92 | +`Image.OPEN` is an internal format registry. Do not recommend that users |
| 93 | +mutate it as a security or configuration mechanism. |
| 94 | + |
| 95 | +`pybind11` is a build-time-only dependency used for parallel C compilation, |
| 96 | +not for C++/Python bindings. |
| 97 | + |
| 98 | +Use fully qualified exception names: `Image.DecompressionBombError` and |
| 99 | +`Image.DecompressionBombWarning`, not the bare class names. |
| 100 | + |
| 101 | +Do not embed specific numeric values for thresholds like `MAX_IMAGE_PIXELS` — |
| 102 | +they change across releases. Reference the named constant instead. |
0 commit comments