Skip to content

Commit 60bde11

Browse files
authored
Add python-skill and improve simulation mechanics skill (#111)
* Add python-skill and improve simulation mechanics skill - Add python-skill: uv + Python 3.13 standards, venv conflict resolution - Expand simulation-mechanics-skill with correct import paths, venv setup, UK dataset loading (EFRS paths, ensure_datasets pattern), confirmed household variable reference (tenure_type values, domestic_energy_consumption), and direct data analysis example for decile/groupby/percentile work - Register python-skill in country-models, analysis-tools, data-science, complete plugins * Clarify ensure_datasets returns a dict and document key format * Fix dataset loading: datasets is an exported module, not a pre-built dict * Add US dataset loading pattern (same as UK) * Simplify dataset loading: just import datasets dict, delete ./data to force regen * Strengthen skill descriptions with ALWAYS LOAD and dense trigger phrases * Replace partial variable list with pattern for inspecting variables at runtime
1 parent 3e4fa0c commit 60bde11

File tree

5 files changed

+365
-1
lines changed

5 files changed

+365
-1
lines changed

.claude-plugin/marketplace.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"./skills/technical-patterns/policyengine-code-style-skill",
8989
"./skills/technical-patterns/policyengine-code-organization-skill",
9090
"./skills/technical-patterns/policyengine-reform-patterns-skill",
91+
"./skills/technical-patterns/python-skill",
9192
"./skills/documentation/policyengine-standards-skill",
9293
"./skills/documentation/policyengine-writing-skill"
9394
]
@@ -183,6 +184,7 @@
183184
"./skills/domain-knowledge/policyengine-uk-skill",
184185
"./skills/domain-knowledge/policyengine-healthcare-skill",
185186
"./skills/analysis/policyengine-analysis-skill",
187+
"./skills/technical-patterns/python-skill",
186188
"./skills/analysis/policyengine-district-analysis-skill",
187189
"./skills/data-science/microdf-skill",
188190
"./skills/documentation/policyengine-design-skill",
@@ -213,6 +215,7 @@
213215
"./skills/domain-knowledge/policyengine-us-skill",
214216
"./skills/domain-knowledge/policyengine-uk-skill",
215217
"./skills/domain-knowledge/policyengine-healthcare-skill",
218+
"./skills/technical-patterns/python-skill",
216219
"./skills/documentation/policyengine-design-skill",
217220
"./skills/documentation/policyengine-standards-skill",
218221
"./skills/documentation/policyengine-writing-skill"
@@ -329,6 +332,7 @@
329332
"./skills/technical-patterns/policyengine-code-style-skill",
330333
"./skills/technical-patterns/policyengine-code-organization-skill",
331334
"./skills/technical-patterns/policyengine-reform-patterns-skill",
335+
"./skills/technical-patterns/python-skill",
332336
"./skills/data-science/microdf-skill",
333337
"./skills/data-science/microimpute-skill",
334338
"./skills/data-science/microcalibrate-skill",

changelog.d/python-skill.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add python-skill: uv + Python 3.13 environment setup and package management standards
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Expand policyengine-simulation-mechanics-skill with correct import paths, venv setup, UK dataset loading patterns, EFRS variable reference, and direct data analysis example; update python-skill with venv conflict resolution
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
name: python
3+
description: |
4+
ALWAYS LOAD THIS SKILL before setting up any Python environment or installing packages.
5+
Defines the standard: uv, Python 3.13, uv pip install, .venv at project root.
6+
Triggers: "set up python", "install python", "create a venv", "virtual environment",
7+
"pip install", "install packages", "uv pip", "uv venv", "python version",
8+
"VIRTUAL_ENV", "venv conflict", "which python", "activate", "deactivate",
9+
"run the script", "run with uv", "uv run", "pyproject.toml", "install dependencies",
10+
"install requirements", "install the package", "editable install", "pip install -e".
11+
---
12+
13+
# Python Environment — PolicyEngine Standard
14+
15+
All PolicyEngine Python work uses **uv** with **Python 3.13** and a local `.venv`.
16+
17+
## Required tools
18+
19+
- [`uv`](https://docs.astral.sh/uv/) — fast Python package and project manager
20+
- Python 3.13 (installed/managed via uv)
21+
22+
Install uv if not present:
23+
24+
```bash
25+
curl -LsSf https://astral.sh/uv/install.sh | sh
26+
```
27+
28+
---
29+
30+
## Creating a new environment
31+
32+
Always create a `.venv` at the project root using Python 3.13:
33+
34+
```bash
35+
uv venv --python 3.13
36+
source .venv/bin/activate
37+
```
38+
39+
On Windows:
40+
41+
```bash
42+
uv venv --python 3.13
43+
.venv\Scripts\activate
44+
```
45+
46+
---
47+
48+
## Installing packages
49+
50+
Always use `uv pip install`, never bare `pip install`:
51+
52+
```bash
53+
# Install a package
54+
uv pip install policyengine
55+
56+
# Install from requirements file
57+
uv pip install -r requirements.txt
58+
59+
# Install the current project in editable mode
60+
uv pip install -e .
61+
62+
# Install with extras
63+
uv pip install -e ".[dev]"
64+
```
65+
66+
---
67+
68+
## Running Python
69+
70+
After activating the venv, run Python normally:
71+
72+
```bash
73+
python script.py
74+
python -m pytest
75+
```
76+
77+
Or run without activating using uv:
78+
79+
```bash
80+
uv run python script.py
81+
uv run pytest
82+
```
83+
84+
---
85+
86+
## Checking the environment
87+
88+
```bash
89+
# Confirm Python version (should be 3.13.x)
90+
python --version
91+
92+
# Confirm uv is being used
93+
which pip # should point to .venv
94+
uv pip list
95+
```
96+
97+
---
98+
99+
## Common patterns
100+
101+
### New repo setup
102+
103+
```bash
104+
uv venv --python 3.13
105+
source .venv/bin/activate
106+
uv pip install -e ".[dev]"
107+
```
108+
109+
### Adding a dependency to pyproject.toml, then syncing
110+
111+
```bash
112+
# Edit pyproject.toml to add the dependency, then:
113+
uv pip install -e .
114+
```
115+
116+
### Running tests
117+
118+
```bash
119+
uv run pytest
120+
# or after activating:
121+
pytest
122+
```
123+
124+
---
125+
126+
## Resolving venv conflicts
127+
128+
If you see a warning like:
129+
```
130+
warning: `VIRTUAL_ENV=/Users/.../.venv` does not match the project environment path `.venv` and will be ignored
131+
```
132+
133+
This means a *different* venv is active (e.g. a global one at `~/.venv`). Fix with:
134+
135+
```bash
136+
# Option 1: Deactivate and use uv run
137+
deactivate
138+
uv run python script.py
139+
140+
# Option 2: Use --active flag to force uv to use the active env
141+
uv run --active python script.py
142+
143+
# Option 3: Activate the correct project venv explicitly
144+
source /path/to/project/.venv/bin/activate
145+
python script.py
146+
```
147+
148+
**Do not** mix venvs between projects. Each project should have its own `.venv` at the repo root.
149+
150+
## Rules
151+
152+
- **Never** use `python -m venv` — always `uv venv`
153+
- **Never** use bare `pip install` — always `uv pip install`
154+
- **Always** target Python 3.13 (`--python 3.13`)
155+
- **Always** create the venv at the project root as `.venv`
156+
- Use `uv run <cmd>` as an alternative to activating the venv manually
157+
- If a venv conflict warning appears, use `deactivate` then `uv run`

0 commit comments

Comments
 (0)