Skip to content

Commit 0049945

Browse files
committed
Initial commit
Ported logic from design sprint prototype Bootstrap for packaging / building Basic docs and tests
0 parents  commit 0049945

File tree

19 files changed

+2086
-0
lines changed

19 files changed

+2086
-0
lines changed

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Node / TypeScript
2+
node_modules/
3+
dist/
4+
*.log
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
pnpm-debug.log*
9+
.DS_Store
10+
11+
# Tests / coverage
12+
coverage/
13+
.vitest/
14+
15+
# IDEs / editors
16+
.idea/
17+
.vscode/
18+
*.swp
19+
*.swo
20+
21+
# OS
22+
Thumbs.db
23+
24+
# Optional build artifacts
25+
*.tgz

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
src/
2+
tests/
3+
*.ts
4+
*.test.*
5+
vitest.config.*
6+
tsconfig.json
7+
.tool-versions
8+
README_dev.md

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 24.10.0

LICENSE

Whitespace-only changes.

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Python friendly error messages
2+
3+
- [ ] Add licence file
4+
- [ ] Ensure all strings in `src/` are localised
5+
6+
A small, runtime-agnostic, library that explains Python error messages in a friendlier way, inspired by [p5.js's Friendly Error System](https://p5js.org/contribute/friendly_error_system/).
7+
8+
It can be used in browser-based editors (like RPF's [Code Editor web component](https://github.com/RaspberryPiFoundation/editor-ui)) or any environment that executes Python code through Skulpt or Pyodide.
9+
10+
## Features
11+
12+
- Parses and normalizes errors from Skulpt or Pyodide (via adapters)
13+
- Matches errors against a copydeck (JSON rules and templates)
14+
- Copydeck-based explanations can be localised
15+
- Returns structured explanations or ready-made HTML snippets
16+
- Designed for both integration into browser editors and standalone tools
17+
18+
## Usage
19+
20+
```
21+
import {
22+
loadCopydeckFor,
23+
registerAdapter,
24+
skulptAdapter,
25+
pyodideAdapter,
26+
explain
27+
} from "python-friendly-errors";
28+
29+
await loadCopydeckFor(navigator.language); // falls back to "en"
30+
31+
// register runtimes
32+
registerAdapter("skulpt", skulptAdapter);
33+
registerAdapter("pyodide", pyodideAdapter);
34+
35+
// later, when you have an error string and some code:
36+
const result = explain({
37+
error: rawTracebackString,
38+
code: editorCode,
39+
audience: "beginner",
40+
verbosity: "guided"
41+
});
42+
43+
// result.html is a ready-made snippet
44+
// or use result.title, result.summary, result.steps, result.patch, result.trace
45+
46+
```
47+
48+
## Development
49+
50+
### Prerequisites
51+
52+
- **asdf** for environment management
53+
- **Node.js** (installed via asdf)
54+
- **npm** (bundled with Node)
55+
56+
### Set up
57+
58+
Follow the guide at [asdf-vm.com](https://asdf-vm.com/).
59+
60+
Then install the Node.js plugin:
61+
62+
```bash
63+
asdf plugin add nodejs
64+
asdf install
65+
```
66+
67+
This will read .tool-versions and install Node.js 22.11.0 automatically.
68+
69+
```
70+
npm install
71+
npm run build -- --watch
72+
```
73+
74+
### Tests
75+
76+
```
77+
npm test
78+
```
79+
80+
To continuously watch for file changes:
81+
82+
```
83+
npm run dev:test
84+
```
85+
86+
### Building
87+
88+
Create a clean build for distribution:
89+
90+
```
91+
npm run build
92+
```
93+
94+
Output files will be in dist/:
95+
```
96+
dist/
97+
├─ index.js
98+
├─ index.d.ts
99+
└─ adapters/...
100+
```
101+
102+
You can now import it elsewhere (see Usage notes):
103+
104+
```
105+
import { loadCopydeck, registerAdapter, skulptAdapter, explain } from "python-friendly-error
106+
```

copydecks/en/copydeck.json

Whitespace-only changes.

0 commit comments

Comments
 (0)