|
1 | 1 | # Quick orientation for AI coding agents |
2 | 2 |
|
3 | | -## Key facts an agent must know (short): |
4 | | - |
5 | | -- The runner: `runner.py` dynamically imports every module under `ultimatepython` and runs any callable named `main` with zero parameters. Keep `main()` functions parameterless, idempotent, and side-effect safe for CI. |
6 | | -- Single-file runs are supported: modules are runnable with `python ultimatepython/<category>/<module>.py`. Most modules already include `if __name__ == "__main__": main()`. |
7 | | -- Examples use plain Python stdlib only. Avoid adding new third-party dependencies without updating `requirements.txt` and `pyproject.toml`. |
8 | | -- Assertions are used as the primary verification mechanism inside examples (not pytest tests). Preserve their intent and messages when editing. |
9 | | - |
10 | | -## Patterns and conventions |
11 | | - |
12 | | -- `main()` must be parameterless and not raise exceptions when run. Examples: `ultimatepython/fundamentals/function.py`, `ultimatepython/oop/basic_class.py`. |
13 | | -- Module structure: docstring, helpers, `main()` demonstrating usage via asserts, `if __name__ == "__main__": main()`. |
14 | | -- Avoid long-running or destructive operations. For filesystem interactions, keep them local to ephemeral files and clean up after running. |
15 | | -- Use `ruff` and `isort` (configured in `pyproject.toml`) for consistency with existing modules. |
16 | | - |
17 | | -## Before committing |
18 | | - |
19 | | -- New modules go under the appropriate folder—the runner discovers them automatically. |
20 | | -- If a change requires a new dependency, update `requirements.txt` and `pyproject.toml`. |
21 | | -- When updating `README.md`, consider updating translations or note why they were skipped. |
22 | | - |
23 | | -## Quick reference |
24 | | - |
25 | | -- Run all examples: `python runner.py` |
26 | | -- Run single example: `python ultimatepython/<category>/<module>.py` |
27 | | -- Coverage target: 80% (in `pyproject.toml`) |
28 | | - |
29 | | -## Integration points & CI notes |
30 | | - |
31 | | -- CI expects that running `runner.py` and executing each `main()` will succeed. Avoid adding code that requires network access, long sleeps, or interactive input. |
32 | | -- Do not introduce external services or config files; this repo intentionally uses only the Python standard library. |
33 | | - |
34 | | -## Key files |
35 | | - |
36 | | -- `runner.py` — discovery and execution (pkgutil.walk_packages + `main` lookups) |
37 | | -- `pyproject.toml` — formatting, linting, coverage rules |
38 | | - |
39 | | -## Category Charter |
40 | | - |
41 | | -Helpful guidance on where to place new Python module lessons: |
42 | | - |
43 | | -- `fundamentals/`: Core syntax and structural constructs of the language (variables, expressions, strings, lists, loops, functions, basic comprehensions). |
44 | | -- `oop/`: Object-Oriented Programming concepts (classes, inheritance, encapsulation, abstract base classes, exception handling, custom iterators, mixins, MRO, enum). |
45 | | -- `data_structures/`: Specialized data structures and collection containers (deque, namedtuple, ordereddict, defaultdict, heap). |
46 | | -- `stdlib/`: Python standard library modules (file handling, regular expressions, json/csv formats, date/time manipulation, itertools). |
47 | | -- `advanced/`: Metaprogramming and advanced runtime behaviors (decorators, context managers, metaclasses, weak references, walrus operator, pattern matching). |
48 | | -- `concurrency/`: Multitasking and non-blocking models (threading, async/await, multiprocessing, subinterpreters). |
49 | | -- `engineering/`: Code quality, benchmarking, algorithm utilities, and design patterns (mocking, benchmarking, bitwise, dict union). |
50 | | - |
51 | | - |
| 3 | +## Architecture & Conventions |
| 4 | + |
| 5 | +- **Standard library only**: Lessons in `ultimatepython/` strictly use the Python standard library. No external runtime dependencies, external services, or network calls. |
| 6 | +- **Lesson structure**: Docstring, helper definitions, parameterless idempotent `main()` with assertions for verification, and `if __name__ == "__main__": main()`. |
| 7 | +- **Runner discovery**: `runner.py` dynamically discovers modules under `ultimatepython/` and executes `main()`. |
| 8 | +- **Web UI (`ui/`)**: An Astro + TypeScript application for browsing lessons. Lessons are parsed by `ui/parse_lessons.py`. |
| 9 | + |
| 10 | +## Verification & Commands |
| 11 | + |
| 12 | +Run `./pre-commit.sh` to run the full Python verification suite: |
| 13 | +- **Lint & Format**: `ruff check` and `ruff format` |
| 14 | +- **Type Checking**: `mypy ultimatepython check_readmes.py runner.py` |
| 15 | +- **README Sync**: `python check_readmes.py` (verifies header hierarchy and lesson links) |
| 16 | +- **Tests & Coverage**: `coverage run runner.py` and `coverage report` (target >= 80%) |
| 17 | +- **Single Lesson**: `python ultimatepython/<category>/<module>.py` |
| 18 | +- **UI Checks**: `npm run lint` (`astro check`) and `npm run build` in `ui/` |
0 commit comments