Skip to content

Commit a002d16

Browse files
authored
Merge pull request #79 from codrsquad/added-okf-docs
Added docs in OKF format
2 parents fab0b9d + e26fe5b commit a002d16

45 files changed

Lines changed: 1341 additions & 313 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(.venv/bin/portable-python:*)",
5+
"Bash(.venv/bin/pytest:*)",
6+
"Bash(.venv/bin/python scripts/check_okf.py:*)",
7+
"Bash(tox:*)"
8+
]
9+
}
10+
}

ARCHITECTURE.md

Lines changed: 0 additions & 74 deletions
This file was deleted.

CLAUDE.md

Lines changed: 16 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,24 @@
11
# CLAUDE.md
22

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.
44

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.
66

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/`
88

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).
1010

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) |
1420

15-
# Run tests for a single Python version
16-
tox -e py313
21+
## Working in this repo
1722

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.

CONFIGURATION.md

Lines changed: 0 additions & 53 deletions
This file was deleted.

DEVELOP.md

Lines changed: 0 additions & 111 deletions
This file was deleted.

docs/architecture/build-setup.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
type: Class
3+
title: BuildSetup
4+
description: Orchestrates a build end to end — resolves the spec, builds external modules then CPython, validates, and compresses the result.
5+
tags: [class, build, coordinator]
6+
timestamp: 2026-06-23T00:00:00Z
7+
---
8+
9+
# BuildSetup
10+
11+
The build orchestrator (`__init__.py`). The [`build`](/cli/build.md) command — and library users — construct one from a python spec and call `compile()`:
12+
13+
```python
14+
from portable_python import BuildSetup
15+
16+
BuildSetup("cpython:3.13.2").compile()
17+
```
18+
19+
## Mental model
20+
21+
A conductor: it compiles nothing itself, it sequences the pieces. `compile()` is the spine — it cleans the [build folders](/concepts/build-layout.md), enters a [`BuildContext`](/concepts/folder-masking.md) (macOS isolation), builds the [external modules](/modules/index.md) into `build/deps/`, then builds CPython through its [`PythonBuilder`](/architecture/python-builder.md) (a [`Cpython`](/architecture/cpython.md)), and finally compresses the install into `dist/`. **External libraries first, CPython last.**
22+
23+
It owns the [`Folders`](/architecture/config.md) (resolved paths) and the python builder; shared config, target platform, and version family come from [`PPG`](/architecture/ppg.md).
24+
25+
## Worth knowing
26+
27+
- **Start reading at `compile()`** — it calls everything else in order.
28+
- A `--prefix` makes the build **non-portable**; without it the result is relocatable (see [ppp-marker](/concepts/ppp-marker.md) and [portability](/concepts/portability.md)).
29+
- It requires a full `X.Y.Z` spec — a bare `3.13` is rejected; `"latest"` (or empty) resolves to the newest known version.

0 commit comments

Comments
 (0)