|
1 | 1 | # Claude |
2 | 2 |
|
3 | | -## Commands and tools |
| 3 | +## After making code changes |
4 | 4 |
|
5 | | -- Open a Python shell: `uv run python` |
6 | | -- Run tests on all packages (or specify a package to test): `./scripts/test [package] [pytest options]` |
7 | | -- Lint and format code: `./scripts/fix` |
8 | | -- Make database migrations: `./scripts/makemigrations` |
| 5 | +1. **Format and lint**: `./scripts/fix` (always run this before committing) |
| 6 | +2. **Run tests**: `./scripts/test [package]` |
9 | 7 |
|
10 | | -## Scratch directory |
11 | | - |
12 | | -Use the `scratch` directory for one-off scripts, temporary files, and experimentation. This directory is gitignored. Write temporary files here instead of `/tmp`. |
13 | | - |
14 | | -## Testing changes |
15 | | - |
16 | | -The `example` directory contains a demo app with all Plain packages installed. You can `cd` into `example` and use `uv run plain`. |
17 | | - |
18 | | -## READMEs |
19 | | - |
20 | | -Each top-level package directory (e.g., `plain-api/`) has a `README.md` symlink pointing to the actual README inside the package (e.g., `plain-api/plain/api/README.md`). Only edit the README inside the package itself. |
21 | | - |
22 | | -The README answers: "How do I use this?" It's not a complete API reference. It gets users productive quickly and points them to code for deeper exploration. See [`plain-jobs/plain/jobs/README.md`](plain-jobs/plain/jobs/README.md) as a good example. |
23 | | - |
24 | | -### Structure |
25 | | - |
26 | | -Every README should follow this order: |
27 | | - |
28 | | -1. **h1** with package name |
29 | | -2. **Bold one-liner** describing the package in one sentence |
30 | | -3. **Table of contents** with links to h2s and h3s |
31 | | -4. **Overview** section with basic working examples |
32 | | -5. **Feature sections** as needed |
33 | | -6. **FAQs** section (second to last) using h4s for questions |
34 | | -7. **Installation** section (always last) - gets user from nothing to something working |
35 | | - |
36 | | -### Style |
37 | | - |
38 | | -- **Conversational tone**: "You can..." not "The module provides..." |
39 | | -- **First code example must be copy-paste ready** with imports included |
40 | | -- **Subsequent examples can be minimal**, building on what was shown |
41 | | -- **Link to source for advanced features**: `[ClassName](./file.py#ClassName)` |
42 | | -- **Cross-package references link to READMEs**: `[plain.auth](../../plain-auth/plain/auth/README.md)` |
| 8 | +## Commands |
43 | 9 |
|
44 | | -### What to document |
| 10 | +| Command | Purpose | |
| 11 | +| ---------------------------- | -------------------------- | |
| 12 | +| `./scripts/fix` | Format and lint code | |
| 13 | +| `./scripts/test [package]` | Run tests | |
| 14 | +| `./scripts/makemigrations` | Create database migrations | |
| 15 | +| `./scripts/type-check <dir>` | Type check a directory | |
| 16 | +| `uv run python` | Open Python shell | |
45 | 17 |
|
46 | | -- **If users import it, document it** - that's the bar for what needs docs |
47 | | -- **Mention all public features**, even advanced ones briefly, then link to code |
48 | | -- **Internal APIs stay undocumented** - `_prefix` functions and `@internalcode` decorated items are invisible to docs |
49 | | -- **Don't fully document every parameter** - mention the feature exists, link to code for details |
50 | | - |
51 | | -## Type annotations |
52 | | - |
53 | | -We are gradually adding type annotations to improve IDE/type checker friendliness. We are using Python 3.13+. Use the following workflow: |
54 | | - |
55 | | -1. **Check current coverage**: `uv run plain code annotations <directory> --details` |
56 | | -2. **Add annotations**: Focus on function/method signatures (parameters and return types) |
57 | | -3. **Type check**: `./scripts/type-check <directory>` (uses `uv run ty check`) |
58 | | -4. **Format**: `./scripts/fix` |
59 | | -5. **Test**: `./scripts/test <package>` |
60 | | -6. **Verify improvement**: `uv run plain code annotations <directory>` |
61 | | -7. **Add to validation**: Once a directory reaches 100% coverage, add it to `FULLY_TYPED_PATHS` in `scripts/type-validate` to prevent regressions |
62 | | - |
63 | | -Guidelines: |
64 | | - |
65 | | -- Add `from __future__ import annotations` when necessary |
66 | | -- Focus on public APIs and user-facing methods first |
67 | | -- Don't annotate `__init__` return types (type checkers infer `None`) |
68 | | -- Use explicit `return None` for functions with `-> Type | None` return type |
69 | | -- Some Django-style ORM patterns are inherently difficult to type - that's okay |
70 | | -- Goal is progress, not perfection |
| 18 | +## Scratch directory |
71 | 19 |
|
72 | | -Example workflow: |
| 20 | +Use the `scratch` directory for temporary files and experimentation. This directory is gitignored. |
73 | 21 |
|
74 | | -```bash |
75 | | -# Check coverage |
76 | | -uv run plain code annotations plain/plain/assets --details |
| 22 | +## Testing changes |
77 | 23 |
|
78 | | -# After adding annotations... |
79 | | -./scripts/type-check plain/plain/assets |
80 | | -./scripts/fix |
81 | | -./scripts/test plain |
82 | | -uv run plain code annotations plain/plain/assets # Should show 100% |
83 | | -``` |
| 24 | +The `example` directory contains a demo app. Use `cd example && uv run plain` to test. |
84 | 25 |
|
85 | 26 | ## Coding style |
86 | 27 |
|
87 | | -- Don't include args and returns in docstrings if they are already type annotated. |
88 | | -- CLI command docstrings should be concise, informative, no punctuation at the end. |
89 | | -- Don't use overloaded terms. Where possible, prefer unique, specific, and greppable names. |
90 | | - |
91 | | -## Verifying changes |
92 | | - |
93 | | -Not everything needs a test, but be liberal about using `print()` statements to verify changes and show the before and after effects of your changes. Make sure those print statements are removed before committing your changes. |
94 | | - |
95 | | -## Documentation |
96 | | - |
97 | | -When writing documentation (READMEs, docstrings, etc.), follow the principles from [What Makes Documentation Good](https://github.com/openai/openai-cookbook/blob/main/articles/what_makes_documentation_good.md): |
98 | | - |
99 | | -- Make docs easy to skim |
100 | | - - Split content into sections with titles. |
101 | | - - Prefer titles with informative sentences over abstract nouns. |
102 | | - - Include a table of contents. |
103 | | - - Keep paragraphs short. |
104 | | - - Begin paragraphs and sections with short topic sentences that give a standalone preview. |
105 | | - - Put topic words at the beginning of topic sentences. |
106 | | - - Put the takeaways up front. |
107 | | - - Use bullets and tables. |
108 | | - - Bold important text. |
109 | | -- Write well |
110 | | - - Keep sentences simple. |
111 | | - - Write sentences that can be parsed unambiguously. |
112 | | - - Avoid left-branching sentences. |
113 | | - - Avoid demonstrative pronouns (e.g., "this"), especially across sentences. |
114 | | - - Be consistent. |
115 | | - - Don't tell readers what they think or what to do. |
116 | | -- Be broadly helpful |
117 | | - - Write simply. |
118 | | - - Avoid abbreviations. |
119 | | - - Offer solutions to potential problems. |
120 | | - - Prefer terminology that is specific and accurate. |
121 | | - - Keep code examples general and exportable. |
122 | | - - Prioritize topics by value. |
123 | | - - Don't teach bad habits. |
124 | | - - Introduce topics with a broad opening. |
125 | | -- Break these rules when you have a good reason |
126 | | - - "Documentation is an exercise in empathy." |
| 28 | +- Prefer unique, greppable names over overloaded terms |
| 29 | +- Verify changes with `print()` statements, then remove before committing |
0 commit comments