pll-python 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +114 -0
  2. package/cli.cjs +1711 -0
  3. package/package.json +36 -0
  4. package/worker.cjs +1478 -0
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # pll-python
2
+
3
+ Run Python with [PLL](https://github.com/dbp/pll)'s language levels from the
4
+ command line. Same checks, same error messages, same built-in libraries as
5
+ the **Python Language Levels** VS Code extension — no Python installation
6
+ needed, because it runs on [Pyodide](https://pyodide.org).
7
+
8
+ Needs **Node 22 or newer** (the oldest Node still receiving support).
9
+
10
+ ```bash
11
+ npx pll-python hw.py
12
+ ```
13
+
14
+ Or install it:
15
+
16
+ ```bash
17
+ npm install -g pll-python
18
+ pll hw.py
19
+ ```
20
+
21
+ ## Language levels
22
+
23
+ The level comes from the file's own first line, exactly as in the editor:
24
+
25
+ ```python
26
+ #level beginner
27
+
28
+ greeting = "Hello!"
29
+ print(greeting)
30
+ ```
31
+
32
+ | Line in the file | What it does |
33
+ | --- | --- |
34
+ | `#level raw` | Nothing checked. Plain Python plus PLL's libraries. This is what you get with no line at all. |
35
+ | `#level beginner` | Warns about reassigning a variable, hiding another name (including built-ins like `list`), and `global` / `nonlocal`. Type annotations are checked as the program runs. If it finds a problem, the file does **not** run. |
36
+ | `#level intermediate` | Same, but reassignment is allowed inside a function. |
37
+ | `#level advanced` | No pre-run checks; annotations still checked, by Python's own rules. |
38
+
39
+ There is deliberately **no flag to override the level**. A file behaves the
40
+ same way everywhere, which is the point of putting it in the file.
41
+
42
+ ## Tests
43
+
44
+ `test_*` functions in the same file run before the file does, as they do in
45
+ the editor:
46
+
47
+ ```bash
48
+ pll hw.py # tests, then the program
49
+ pll hw.py --no-tests # just the program
50
+ ```
51
+
52
+ ## Options
53
+
54
+ ```
55
+ --no-tests do not run the file's test_* functions first
56
+ --save-images <dir> write pictures there as .svg
57
+ -q, --quiet only the program's own output
58
+ --no-color never use ANSI colour
59
+ -h, --help
60
+ -v, --version
61
+ ```
62
+
63
+ ## Exit codes
64
+
65
+ | Code | Meaning |
66
+ | --- | --- |
67
+ | 0 | Ran, and any tests passed |
68
+ | 1 | The program raised |
69
+ | 2 | Level checks found problems, so it was not run |
70
+ | 3 | A test failed |
71
+ | 64 | Bad usage, or PLL could not start |
72
+
73
+ Distinct codes so an autograder can tell "the level rejected this" from
74
+ "the tests failed" from "it crashed".
75
+
76
+ ## Piping
77
+
78
+ The program's own stdout is the **only** thing on stdout. Everything
79
+ `pll` says about the run — the level, findings, test results, banners —
80
+ goes to stderr. So this captures exactly what the program printed:
81
+
82
+ ```bash
83
+ pll hw.py > output.txt
84
+ ```
85
+
86
+ `input()` reads stdin, so piping works too:
87
+
88
+ ```bash
89
+ printf 'Ada\n' | pll greet.py
90
+ ```
91
+
92
+ ## What differs from the editor
93
+
94
+ - **Pictures cannot be drawn in a terminal.** Each one prints a note with
95
+ its size; `--save-images` writes them as `.svg` instead.
96
+ - **Reactors (`big_bang`, `animate`) do not run.** They need the editor's
97
+ interactions panel to animate; here they print a note and the rest of the
98
+ program continues. Their logic is still testable — `simulate_trace(n)`
99
+ works fine and needs no clock.
100
+ - **Tables do print**, as text. Their content is already text, so there is
101
+ nothing to lose.
102
+
103
+ Everything else is the same code: the same Pyodide worker, the same Python
104
+ libraries, the same analyzers and the same wording for errors.
105
+
106
+ ## Files next to your program
107
+
108
+ `open("data.csv")` and `pd.read_csv("data.csv")` read files in the same
109
+ folder as the script, and files the program writes appear there afterwards —
110
+ the same as in the editor.
111
+
112
+ ## Licence
113
+
114
+ MIT