|
1 | 1 | # CLAUDE.md |
2 | 2 |
|
3 | | -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 3 | +Guidance for Claude Code working in this repository. |
4 | 4 |
|
5 | | -## What This Project Does |
| 5 | +`portable-python` is a CLI and Python library that compiles portable (statically-linked, relocatable) CPython binaries from source — see [`docs/overview.md`](docs/overview.md) for the full picture. |
6 | 6 |
|
7 | | -portable-python is a CLI tool and Python library for compiling portable CPython binaries from source. Binaries are statically linked so they can be extracted to any folder and used without installation. Supports Linux and macOS (not Windows). |
| 7 | +## Documentation lives in `docs/` |
8 | 8 |
|
9 | | -## Common Commands |
| 9 | +The authoritative, self-contained documentation is the OKF knowledge bundle under **`docs/`** — start at [`docs/index.md`](docs/index.md). **Don't duplicate it in this file — link to it.** When you change behavior, update the matching `docs/` entry and add a line to [`docs/log.md`](docs/log.md). |
10 | 10 |
|
11 | | -```bash |
12 | | -# Run all tests (tox manages envs for py310-314, coverage, docs, style) |
13 | | -tox |
| 11 | +| Looking for… | Go to | |
| 12 | +|--------------|-------| |
| 13 | +| What it does, guiding principles, end-to-end build flow | [`docs/overview.md`](docs/overview.md) | |
| 14 | +| Core classes & how they collaborate | [`docs/architecture/`](docs/architecture/index.md) | |
| 15 | +| Concepts: portability, static linking, telltale detection, folder masking, ppp-marker, build layout | [`docs/concepts/`](docs/concepts/index.md) | |
| 16 | +| CLI commands & options | [`docs/cli/`](docs/cli/index.md) | |
| 17 | +| External modules (the statically-linked C libraries) | [`docs/modules/`](docs/modules/index.md) | |
| 18 | +| Configuration (`portable-python.yml`) | [`docs/configuration/`](docs/configuration/index.md) | |
| 19 | +| Dev setup, tests, code style, debugging, Docker, CI/CD, and common tasks | [`docs/guides/`](docs/guides/index.md) | |
14 | 20 |
|
15 | | -# Run tests for a single Python version |
16 | | -tox -e py313 |
| 21 | +## Working in this repo |
17 | 22 |
|
18 | | -# Run a single test |
19 | | -pytest tests/test_build.py::test_build_rc -vv |
20 | | - |
21 | | -# Lint check / auto-fix |
22 | | -tox -e style |
23 | | -tox -e reformat |
24 | | - |
25 | | -# Run tests directly (from venv) |
26 | | -pytest tests/ |
27 | | - |
28 | | -# CI uses: uvx --with tox-uv tox -e py |
29 | | -``` |
30 | | - |
31 | | -## Architecture |
32 | | - |
33 | | -**Key classes:** |
34 | | - |
35 | | -- `PPG` (versions.py) — Global singleton holding config, target platform, and version families. All modules access shared state through this. |
36 | | -- `BuildSetup` (__init__.py) — Coordinates overall compilation: downloads sources, builds external modules, then CPython. |
37 | | -- `ModuleBuilder` (__init__.py) — Abstract base for anything that gets compiled. Both external C modules and Python itself extend this. |
38 | | -- `PythonBuilder` (__init__.py) — Extends ModuleBuilder for Python implementations. |
39 | | -- `Cpython` (cpython.py) — Concrete PythonBuilder that handles CPython's configure/make/install, optimization, and finalization. |
40 | | -- `Config` (config.py) — Loads and merges YAML configuration (portable-python.yml) with platform-specific overrides. |
41 | | -- `PythonInspector` (inspector.py) — Validates portability of a built Python by checking shared library dependencies and paths. |
42 | | - |
43 | | -**External modules** (external/xcpython.py): `Bdb`, `Bzip2`, `Gdbm`, `LibFFI`, `Mpdec`, `Openssl`, `Readline`, `Sqlite`, `Uuid`, `Xz`, `Zlib`, `Zstd` — each is a ModuleBuilder subclass that compiles a C library statically before CPython is built. |
44 | | - |
45 | | -**Key patterns:** |
46 | | - |
47 | | -- Platform-specific compile logic uses `_do_linux_compile()` / `_do_macos_compile()` method dispatch. |
48 | | -- Environment injection: `xenv_*` methods provide CPATH, LDFLAGS, PATH etc. for compilation. |
49 | | -- On macOS, `/usr/local` is masked with a RAM disk (`FolderMask`) to prevent accidental dynamic linking. |
50 | | -- External modules compile to a shared `build/deps/` prefix; CPython finds them via CPATH/LDFLAGS. |
51 | | -- Telltale detection: modules check for marker files (`m_telltale`) to determine if system already has the library. |
52 | | -- No patches to upstream CPython source — relies solely on configure flags. |
53 | | - |
54 | | -**runez** is the foundational utility library (file ops, system info, CLI decorators, logging, Version/PythonSpec types). Check runez before reimplementing anything. |
55 | | - |
56 | | -**Additional pointers:** |
57 | | - |
58 | | -- `ModuleCollection.selected` contains only the modules chosen for a build — not all candidates. |
59 | | -- Build logs go to `build/logs/NN-modulename.log` (e.g. `01-openssl.log`, `02-cpython.log`). |
60 | | -- YAML config supports platform-specific overrides and path templates — see CONFIGURATION.md. |
61 | | -- See ARCHITECTURE.md for class hierarchy and design patterns, DEVELOP.md for common tasks and dependencies. |
62 | | - |
63 | | -## Testing |
64 | | - |
65 | | -- pytest with 100% code coverage target |
66 | | -- Tests mock `runez.run()` to avoid actual compilation — uses `--dryrun` mode |
67 | | -- `conftest.py` provides a `cli` fixture (from runez) and forbids HTTP calls (`GlobalHttpCalls.forbid()`) |
68 | | -- Sample YAML configs in `tests/sample-config*.yml` for testing configuration parsing |
69 | | - |
70 | | -## Linting |
71 | | - |
72 | | -Ruff handles all linting and formatting. Key settings in pyproject.toml: |
73 | | -- Line length: 140 |
74 | | -- McCabe complexity: max 18 |
75 | | -- Security checks (S rules) disabled in tests |
76 | | -- Numpy-style docstrings |
| 23 | +- Check **runez** before reimplementing file / system / CLI / logging / version helpers — see [`docs/guides/local-development.md`](docs/guides/local-development.md). |
| 24 | +- The docs use the OKF format; keep the bundle conformant (`scripts/check_okf.py docs`) when you edit it. |
0 commit comments