ppkit 0.1.0__tar.gz
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.
- ppkit-0.1.0/.pp.toml +9 -0
- ppkit-0.1.0/CHANGELOG.md +20 -0
- ppkit-0.1.0/CONTRIBUTING.md +392 -0
- ppkit-0.1.0/LICENSE +202 -0
- ppkit-0.1.0/PKG-INFO +330 -0
- ppkit-0.1.0/README.md +308 -0
- ppkit-0.1.0/bin/pp +17 -0
- ppkit-0.1.0/ci/check +35 -0
- ppkit-0.1.0/ci/package +45 -0
- ppkit-0.1.0/pp/__init__.py +4 -0
- ppkit-0.1.0/pp/__main__.py +5 -0
- ppkit-0.1.0/pp/cli.py +363 -0
- ppkit-0.1.0/pp/commands/__init__.py +1 -0
- ppkit-0.1.0/pp/commands/batch.py +848 -0
- ppkit-0.1.0/pp/commands/cmd.py +545 -0
- ppkit-0.1.0/pp/commands/completion.py +55 -0
- ppkit-0.1.0/pp/commands/http.py +1499 -0
- ppkit-0.1.0/pp/commands/kill.py +293 -0
- ppkit-0.1.0/pp/commands/promote.py +945 -0
- ppkit-0.1.0/pp/commands/queue.py +243 -0
- ppkit-0.1.0/pp/lib/__init__.py +1 -0
- ppkit-0.1.0/pp/lib/config.py +110 -0
- ppkit-0.1.0/pp/lib/jobq.py +3106 -0
- ppkit-0.1.0/pp/lib/lock.py +338 -0
- ppkit-0.1.0/pp/lib/paths.py +163 -0
- ppkit-0.1.0/pp/lib/proc.py +706 -0
- ppkit-0.1.0/pp/lib/session.py +31 -0
- ppkit-0.1.0/pp/lib/ui.py +189 -0
- ppkit-0.1.0/pyproject.toml +38 -0
- ppkit-0.1.0/tests/journey.py +408 -0
- ppkit-0.1.0/tests/sandbox.py +284 -0
- ppkit-0.1.0/tests/test_batch.py +564 -0
- ppkit-0.1.0/tests/test_cli.py +166 -0
- ppkit-0.1.0/tests/test_cmd.py +228 -0
- ppkit-0.1.0/tests/test_constructs.py +1191 -0
- ppkit-0.1.0/tests/test_http.py +601 -0
- ppkit-0.1.0/tests/test_journey_batch.py +186 -0
- ppkit-0.1.0/tests/test_journey_cli.py +414 -0
- ppkit-0.1.0/tests/test_journey_cmd.py +259 -0
- ppkit-0.1.0/tests/test_journey_http.py +341 -0
- ppkit-0.1.0/tests/test_journey_kill.py +188 -0
- ppkit-0.1.0/tests/test_journey_promote.py +363 -0
- ppkit-0.1.0/tests/test_journey_queue.py +637 -0
- ppkit-0.1.0/tests/test_kill.py +228 -0
- ppkit-0.1.0/tests/test_lock.py +328 -0
- ppkit-0.1.0/tests/test_paths.py +142 -0
- ppkit-0.1.0/tests/test_proc.py +439 -0
- ppkit-0.1.0/tests/test_promote.py +679 -0
- ppkit-0.1.0/tests/test_queue.py +3280 -0
- ppkit-0.1.0/tests/test_session.py +24 -0
- ppkit-0.1.0/tests/test_ui.py +107 -0
ppkit-0.1.0/.pp.toml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# pp's own project config. `pp promote -n` previews, `pp promote` releases pp itself.
|
|
2
|
+
name = "pp"
|
|
3
|
+
|
|
4
|
+
[promote]
|
|
5
|
+
source = "git"
|
|
6
|
+
check = "ci/check" # runs inside the release: the exact bytes `pp` will run
|
|
7
|
+
links = { "~/.local/bin/pp" = "bin/pp" } # prod: always a promoted release
|
|
8
|
+
dev_links = { "~/.local/bin/ppd" = "bin/pp" } # dev: this working tree
|
|
9
|
+
keep = 5
|
ppkit-0.1.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## v0.1.0
|
|
4
|
+
|
|
5
|
+
The first release.
|
|
6
|
+
|
|
7
|
+
- `pp queue` runs commands later, in named queues, when the GPU memory,
|
|
8
|
+
CPUs, RAM or counters they ask for are free. Jobs have timeouts, retries
|
|
9
|
+
for the failures you name, and hooks. Tags and ranges select groups of
|
|
10
|
+
jobs. A project's `.pp.toml` can run its jobs through a runner, such as a
|
|
11
|
+
container.
|
|
12
|
+
- `pp queue wait`, `watch` and `wait --mine` tell a person or an agent how
|
|
13
|
+
jobs ended, with the end of the log for a failure.
|
|
14
|
+
- `pp promote` releases a project from a git commit when its check passes
|
|
15
|
+
on that copy, and rolls back.
|
|
16
|
+
- `pp kill`, `pp batch` and `pp http` stop processes, rename or convert
|
|
17
|
+
files, and show project folders in a browser.
|
|
18
|
+
- `pp cmd` writes commands, and adds other people's from git, pinned to the
|
|
19
|
+
commit you read.
|
|
20
|
+
- Completion for zsh and bash.
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Issues and pull requests
|
|
4
|
+
|
|
5
|
+
- Report a bug with what you ran, what it printed, `pp --version` and your
|
|
6
|
+
Python version.
|
|
7
|
+
- Open an issue before a pull request that changes behaviour, so the change
|
|
8
|
+
is agreed first. A typo or a small fix can go straight to a pull request.
|
|
9
|
+
- Keep a pull request to one change.
|
|
10
|
+
|
|
11
|
+
## Code written with AI
|
|
12
|
+
|
|
13
|
+
Code written with an AI assistant is welcome, if you have read and
|
|
14
|
+
understood all of it. Issues, pull request descriptions and your answers
|
|
15
|
+
to comments are written by you, not by an agent: you must be able to
|
|
16
|
+
explain why the change is right. A pull request that looks generated, and
|
|
17
|
+
not understood, is closed.
|
|
18
|
+
|
|
19
|
+
## Running pp from a clone
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
git clone https://github.com/xflash96/pp ~/src/pp
|
|
23
|
+
mkdir -p ~/.local/bin && ln -s ~/src/pp/bin/pp ~/.local/bin/pp
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If you installed pp as a tool, `uv tool uninstall ppkit` (or
|
|
27
|
+
`pipx uninstall ppkit`) first: it uses the same `~/.local/bin/pp`.
|
|
28
|
+
|
|
29
|
+
## Building and testing
|
|
30
|
+
|
|
31
|
+
You need Python 3.11 or later, git, sh and bash. The tests that need zsh
|
|
32
|
+
skip without it. `ci/check` uses [uv](https://docs.astral.sh/uv/)
|
|
33
|
+
for the linter and for other Python versions.
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
ci/check the linter, then every test, on python3
|
|
37
|
+
ci/check 3.11 the same on Python 3.11, which uv installs the first time
|
|
38
|
+
ci/check --cpus 2 3.11 the same on 2 CPUs, like a CI runner
|
|
39
|
+
python3 -m unittest discover -s tests the tests alone
|
|
40
|
+
ci/package build ppkit into dist/, install it fresh, and try it
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
CI runs `ci/check 3.11`, `ci/check 3.14` and `ci/package` on every push to
|
|
44
|
+
main and every pull request. The whole suite takes a few minutes. Most of
|
|
45
|
+
that is the journeys (`tests/test_journey_*.py`), which run the real
|
|
46
|
+
`bin/pp` once per step in a throwaway home directory.
|
|
47
|
+
|
|
48
|
+
A test that fails only sometimes has a race in it. Fix the race rather
|
|
49
|
+
than running the test again (see Tests). `ci/check --cpus 2` runs the
|
|
50
|
+
suite on 2 CPUs, with a process table of its own (`unshare`). A test
|
|
51
|
+
that passes only because a worker or a server always gets a CPU at once
|
|
52
|
+
fails there, as it would on a CI runner. So does one that passes only
|
|
53
|
+
because a scan of `/proc` is slow: a scan of the thousand or so processes
|
|
54
|
+
on a developer's machine takes tens of milliseconds, and a runner's few
|
|
55
|
+
hundred take a few. The test that needs another user's process is skipped
|
|
56
|
+
there.
|
|
57
|
+
|
|
58
|
+
A uv-managed CPython has no `os.pidfd_open`, so `ci/check 3.11`, `ci/check
|
|
59
|
+
3.14` and CI run `pp/lib/proc.py`'s ctypes syscall path, while the distro
|
|
60
|
+
`python3` of a plain `ci/check` runs the wrapped calls. Both are tested only
|
|
61
|
+
by running both.
|
|
62
|
+
|
|
63
|
+
## The code
|
|
64
|
+
|
|
65
|
+
- `bin/pp` finds the tree it lives in, wherever it is linked from, and runs
|
|
66
|
+
`pp.cli`.
|
|
67
|
+
- `pp/cli.py` finds the commands, runs one, and prints help and completion.
|
|
68
|
+
It knows no command by name.
|
|
69
|
+
- `pp/lib/` holds what commands share. "How pp works" below lists those
|
|
70
|
+
modules and what each one owns.
|
|
71
|
+
- `pp/commands/NAME.py` is one command.
|
|
72
|
+
- `tests/` has the unit tests, and the journeys with their harness,
|
|
73
|
+
`tests/journey.py`.
|
|
74
|
+
- `ci/check` and `ci/package` are what CI runs; `.github/workflows/ci.yml`
|
|
75
|
+
runs them, and `release.yml` publishes a tagged version.
|
|
76
|
+
- `pyproject.toml` builds the ppkit package, and `.pp.toml` lets
|
|
77
|
+
`pp promote` release pp itself.
|
|
78
|
+
|
|
79
|
+
## Adding a command
|
|
80
|
+
|
|
81
|
+
`pp cmd new NAME` writes `pp/commands/NAME.py`, `tests/test_NAME.py` and
|
|
82
|
+
`tests/test_journey_NAME.py`. A command file has:
|
|
83
|
+
|
|
84
|
+
1. A docstring. Its first line is the summary that `pp` lists, in about 60
|
|
85
|
+
characters or fewer. The whole docstring is what `pp help NAME` prints,
|
|
86
|
+
so put examples in it.
|
|
87
|
+
2. `def main(argv: list[str]) -> int`, which builds its parser with
|
|
88
|
+
`ui.parser("NAME", __doc__)`.
|
|
89
|
+
3. If you want short names for it, `ALIASES = ["x"]`, written as a literal
|
|
90
|
+
list.
|
|
91
|
+
|
|
92
|
+
These rules keep pp working as commands come and go:
|
|
93
|
+
|
|
94
|
+
- Import only the standard library at the top of the file. A third-party
|
|
95
|
+
import goes inside the function that needs it, with a clear message when
|
|
96
|
+
it is missing. `tests/test_cli.py` checks this.
|
|
97
|
+
- Commands do not import each other. Shared code goes in `pp/lib/`. Any
|
|
98
|
+
command file can be deleted and the rest keep working.
|
|
99
|
+
- State goes under `paths.state_dir("NAME")`. Settings come from
|
|
100
|
+
`config.load("NAME")`, the `[NAME]` table of `~/.config/pp/config.toml`,
|
|
101
|
+
and for a project from the nearest `.pp.toml` (`config.find_project()`).
|
|
102
|
+
- Settings are checked. An unknown key or a bad value raises
|
|
103
|
+
`config.ConfigError` with its name (`config.check_keys`,
|
|
104
|
+
`config.parse_duration`), and pp prints it and exits 1. The docstring of
|
|
105
|
+
`pp/lib/config.py` says which command owns each table.
|
|
106
|
+
- A command that changes or deletes things shows its plan first, unless the
|
|
107
|
+
user named each thing exactly (a pid, a job id): those are acted on at
|
|
108
|
+
once. `-n` shows the plan only, and `-y` goes ahead without asking.
|
|
109
|
+
Otherwise it asks with `ui.confirm()`, which refuses when there is no
|
|
110
|
+
terminal. Agents run without one, so they pass `-n` to look and then `-y`
|
|
111
|
+
to act.
|
|
112
|
+
- Anything that lists or reports status has `--json`. Agents read it, so a
|
|
113
|
+
change to a field goes in `CHANGELOG.md`.
|
|
114
|
+
- Exit statuses follow the table under "Exit status" below. Errors go
|
|
115
|
+
through `ui.die(msg, code)`.
|
|
116
|
+
- Text from elsewhere (another program's command line, a plugin's file,
|
|
117
|
+
git's output) goes through `ui.printable()` before it is printed, so an
|
|
118
|
+
escape sequence in it cannot redraw the terminal.
|
|
119
|
+
- Anything two things could do at once goes through its construct: start a
|
|
120
|
+
process with `proc.spawn`, signal one through `proc.Handle`, lock with
|
|
121
|
+
`lock.locked`, read-modify-write a record with `paths.json_txn`. "The
|
|
122
|
+
constructs" below is the list, and `tests/test_constructs.py` fails on a
|
|
123
|
+
call that does one of those jobs itself.
|
|
124
|
+
- A process pattern must not match the caller or the processes that started
|
|
125
|
+
it (`proc.ancestors()`). `pkill -f PAT` kills the shell that runs it,
|
|
126
|
+
because PAT is in that shell's command line.
|
|
127
|
+
- Long work goes through `pp queue`, and the caller finds out how it ended
|
|
128
|
+
with `pp queue wait` or `pp queue watch`. pp does not type into terminals
|
|
129
|
+
to report back.
|
|
130
|
+
- Completion reads the docstring. TAB offers the verbs of its `pp NAME VERB`
|
|
131
|
+
example lines and the flags argparse knows, so give every verb an example.
|
|
132
|
+
|
|
133
|
+
## Tests
|
|
134
|
+
|
|
135
|
+
- Unit tests go in `tests/test_NAME.py` and enter `tests/sandbox.py`'s
|
|
136
|
+
scope: `self.sb = sandbox.enter(self)`, first in `setUp`. The docstring of
|
|
137
|
+
`tests/sandbox.py` says what that scope owns and in what order it gives it
|
|
138
|
+
back, so a test reads and writes a tree of its own and never yours. `pp
|
|
139
|
+
cmd new` writes a test that enters it.
|
|
140
|
+
- Journeys go in `tests/test_journey_NAME.py` and use `journey.Journey`.
|
|
141
|
+
The docstring of `tests/journey.py` says what its sandbox keeps away from
|
|
142
|
+
your machine. Every example in a command's docstring runs in its journey,
|
|
143
|
+
mistakes included. The help text is the spec: `tests/test_journey_cli.py`
|
|
144
|
+
fails when an example's verb does not appear in its journey file. pp
|
|
145
|
+
itself and `completion` are walked in that file.
|
|
146
|
+
- A journey step that uses a command other than its own is guarded with
|
|
147
|
+
`has()` or `needs()`, so a tree with some commands removed still passes.
|
|
148
|
+
- Two things that touch the same job, file or port at once (a worker and a
|
|
149
|
+
command, two workers, a signal and a write) go through a construct that
|
|
150
|
+
is written once. "The constructs" below is the list of them, and a check
|
|
151
|
+
added at one call site is not a fix.
|
|
152
|
+
- A test of a construct checks what the construct promises. A test that
|
|
153
|
+
runs a second actor at an exact step keeps one fix from coming back
|
|
154
|
+
(`TestTwoAtOnce` in `tests/test_queue.py`). That step goes through
|
|
155
|
+
`journey.Gate`, never a flag of the test's own, so the condition and the
|
|
156
|
+
step are one move; `Gate`'s docstring is the contract.
|
|
157
|
+
- A test waits for the state it needs (`journey.until`, or a file the job
|
|
158
|
+
waits for), never for a while. A sleep that is long enough on this
|
|
159
|
+
machine is not long enough on a CI runner: 2 CPUs, a few hundred other
|
|
160
|
+
processes, and tens of milliseconds before a worker that was just started
|
|
161
|
+
gets one.
|
|
162
|
+
- A process a test starts beside itself (a server, a victim, a worker)
|
|
163
|
+
comes from `journey.start` or `Journey.child`, and nothing acts on it
|
|
164
|
+
before it says it is up: the `ready` line those wait for, or a state a
|
|
165
|
+
bounded `until` waits for. It has exec'd by then, but a handler it
|
|
166
|
+
installs is not installed, a port it binds is not bound, and its command
|
|
167
|
+
line may still read empty.
|
|
168
|
+
|
|
169
|
+
## Exit status
|
|
170
|
+
|
|
171
|
+
| status | meaning |
|
|
172
|
+
|---|---|
|
|
173
|
+
| 0 | it worked |
|
|
174
|
+
| 1 | it failed, or a config file is wrong (pp names the file and the key) |
|
|
175
|
+
| 2 | a usage error, or a refusal: something it checks first is wrong, or it will not act without asking |
|
|
176
|
+
| 3 | `pp queue wait` or `watch` gave up at its `--timeout` |
|
|
177
|
+
| 130 | interrupted (Ctrl-C) |
|
|
178
|
+
|
|
179
|
+
A `pp-NAME` program's own exit status passes through unchanged.
|
|
180
|
+
|
|
181
|
+
## How pp works
|
|
182
|
+
|
|
183
|
+
Each module's docstring is the reference for its part, and this is the one
|
|
184
|
+
list of the parts:
|
|
185
|
+
|
|
186
|
+
- `pp/cli.py`: finding commands, the order of their origins, help and
|
|
187
|
+
completion.
|
|
188
|
+
- `pp/lib/jobq.py`: queues, workers, resources, and the files a job lives
|
|
189
|
+
in; `pp help queue` is the user's view of the same.
|
|
190
|
+
- `pp/commands/promote.py`: releases. `pp/commands/cmd.py`: plugins.
|
|
191
|
+
`pp/commands/http.py`: serving a folder to a browser, with its cache and
|
|
192
|
+
its server. `pp/commands/batch.py`: bulk file changes, and the journal
|
|
193
|
+
that undoes them.
|
|
194
|
+
- `pp/lib/session.py`: agent sessions. `pp/lib/paths.py`: where pp keeps
|
|
195
|
+
things, and the transaction a record goes through. `pp/lib/config.py`:
|
|
196
|
+
settings, and who owns each table.
|
|
197
|
+
- `pp/lib/proc.py`: what `/proc` says about a process, the handle every
|
|
198
|
+
signal goes through, and the spawn every process start goes through.
|
|
199
|
+
- `pp/lib/lock.py`: the lock two processes go through, what a scope that
|
|
200
|
+
holds a signal back promises, and the claim that says who is alive.
|
|
201
|
+
- `pp/lib/ui.py`: parsers, questions, tables, and the escaping every piece
|
|
202
|
+
of text from elsewhere goes through.
|
|
203
|
+
|
|
204
|
+
### The constructs
|
|
205
|
+
|
|
206
|
+
`tests/test_constructs.py` reads the source and fails on a call that does a
|
|
207
|
+
construct's job anywhere else, named by file and function. Its `RULES` is
|
|
208
|
+
this table, and each rule's own docstring is its contract.
|
|
209
|
+
|
|
210
|
+
| rule | what it forbids elsewhere | the construct | its home |
|
|
211
|
+
|---|---|---|---|
|
|
212
|
+
| `signal` | signalling a process | `Handle`, `signal_pid`, `signal_group`, `signal_and_wait` | `pp/lib/proc.py` |
|
|
213
|
+
| `spawn` | starting a process | `spawn`, `run`, `git`, `exec_replace` | `pp/lib/proc.py`, `tests/journey.py` |
|
|
214
|
+
| `alive` | judging a process alive by its pid | a claim's holder, or `Handle` | `pp/lib/proc.py` |
|
|
215
|
+
| `lock` | taking a lock | `locked`, and `deferring` for a scope with no lock | `pp/lib/lock.py` |
|
|
216
|
+
| `claim` | opening a claim's file | `Claim` | `pp/lib/lock.py` |
|
|
217
|
+
| `job` | reading or writing a job's file | `txn`, `listing`, `find` | `pp/lib/jobq.py` |
|
|
218
|
+
| `worker-claim` | taking a queue's worker claim, or reading its holder | `worker`, `worker_now`, `work` | `pp/lib/jobq.py` |
|
|
219
|
+
| `job-process` | signalling or reaping a job's processes | the `Worker` class, `cmd_worker`, `work` | `pp/lib/jobq.py`, `pp/lib/proc.py`, `pp/commands/kill.py` |
|
|
220
|
+
| `by-name` | deciding on a served file by its name | act on the open file | `pp/commands/http.py` |
|
|
221
|
+
| `sleep` | sleeping in a test | `until` | `tests/journey.py` |
|
|
222
|
+
| `once` | a once-flag of a test's own | `Gate` | `tests/journey.py` |
|
|
223
|
+
| `environ` | changing `os.environ` in a test | the scope | `tests/sandbox.py` |
|
|
224
|
+
|
|
225
|
+
`KNOWN` in that file is the exceptions a rule allows, each with its reason
|
|
226
|
+
beside it. An exception that no longer does the thing fails too, so it is
|
|
227
|
+
taken off rather than left standing. The only ones are two `TestStore` tests
|
|
228
|
+
that write a half-finished name and a foreign layout on purpose.
|
|
229
|
+
|
|
230
|
+
Two more have no rule, so a command author follows them from here: a
|
|
231
|
+
read-modify-write of a JSON record goes through `paths.json_txn`, and
|
|
232
|
+
replacing a whole file in one step goes through `paths.write_json`.
|
|
233
|
+
|
|
234
|
+
### Three ways pp runs
|
|
235
|
+
|
|
236
|
+
- **From a clone.** `bin/pp` puts the clone on `sys.path`, and `pp cmd new`
|
|
237
|
+
writes into the clone.
|
|
238
|
+
- **From a release made by `pp promote`.** The same, from a copy that holds
|
|
239
|
+
`.pp-release.json`. `pp cmd new` writes into the tree that release came
|
|
240
|
+
from, since the copy is replaced at the next promote.
|
|
241
|
+
- **From an installed package** (`uv tool install ppkit`). There is no
|
|
242
|
+
`bin/pp`, so a queue's worker starts as `python -P -m pp`, and
|
|
243
|
+
`pp cmd new` writes only with `--user`.
|
|
244
|
+
|
|
245
|
+
`paths.self_cmd` and `cmd._source_tree` tell the three apart.
|
|
246
|
+
`tests/test_cmd.py` and `ci/package` keep the installed case working, and
|
|
247
|
+
the journeys in `tests/test_journey_cmd.py` the other two.
|
|
248
|
+
|
|
249
|
+
### Where a queue's jobs live, and how one says it is alive
|
|
250
|
+
|
|
251
|
+
The docstring of `pp/lib/jobq.py` is the reference: the files a queue is made
|
|
252
|
+
of, how a worker and a job say they are alive, and the one actor that ends a
|
|
253
|
+
job. Each mechanism inside it has one owner, and these are they:
|
|
254
|
+
|
|
255
|
+
- the store: `Txn`, `txn`, `listing` and `find`. `open_queue` is where a
|
|
256
|
+
queue's `FORMAT` is checked, and `Txn.add` is where an id and the record
|
|
257
|
+
that holds it land together.
|
|
258
|
+
- being alive: `lock.Claim`. A claim is held for as long as its holder lives,
|
|
259
|
+
so nothing is cleaned up after a holder that was killed and no record is
|
|
260
|
+
ever read as a live holder. A queue's worker holds one on `worker.lock`,
|
|
261
|
+
one run of a job on `jobs/<id>.run`, a probe and a `wait` lease likewise.
|
|
262
|
+
- whether a queue's worker is up: the block comment above `worker_up`, for
|
|
263
|
+
the two things that can be true of that claim and the first moment that is
|
|
264
|
+
neither.
|
|
265
|
+
- how a job ends: `decide` and `merge_stop`, which are pure, and
|
|
266
|
+
`Worker.carry_out`, the one pass that gathers the facts and carries the
|
|
267
|
+
action out.
|
|
268
|
+
- what a stop carries: `public()`, where every field of a job record that
|
|
269
|
+
others rely on is named.
|
|
270
|
+
|
|
271
|
+
### Who stops a job
|
|
272
|
+
|
|
273
|
+
A queue's worker signals that queue's jobs, and nothing else does. Only a
|
|
274
|
+
worker ever holds the queue's worker claim, and `work()` is the one place
|
|
275
|
+
that takes it. So the worker is the one owner of a stop, whoever asked for
|
|
276
|
+
it: a verb writes the stop on the job in one transaction, makes sure the
|
|
277
|
+
queue has a worker, and waits for the record of how the job ended. Two kills
|
|
278
|
+
of one queue, a kill and a timeout, and a kill with no worker up all come to
|
|
279
|
+
the same place.
|
|
280
|
+
|
|
281
|
+
A kill, pass by pass:
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
kill: txn(merge_stop) -> worker_up(wake=True) -> SIGUSR1 to the worker
|
|
285
|
+
worker: carry_out: the facts -> decide = TERM -> signal the group,
|
|
286
|
+
then txn marks `sent` -> (the grace) -> decide = KILL9 -> signal
|
|
287
|
+
-> the wrapper ends, so the job's run claim is free
|
|
288
|
+
-> decide = ENDED_AS -> _finish records the outcome and the hook it owes
|
|
289
|
+
-> fire
|
|
290
|
+
kill: _await_stop reads done or failed, and prints it
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
A job's states are `queued` or `held`, then `running`, then `done` or
|
|
294
|
+
`failed`; a retry takes it from `running` back to `queued`. Every pass of the
|
|
295
|
+
kill's wait wakes the worker again, so what the kill waits out is the job's
|
|
296
|
+
own exit time and not the queue's poll period.
|
|
297
|
+
|
|
298
|
+
The rules the worker follows are the ones `pp help queue` states under "How a
|
|
299
|
+
job ends, whatever reached it", and that help text is their one statement.
|
|
300
|
+
One more is for contributors: which of the two a stop is comes from the
|
|
301
|
+
`timeout` field a worker writes on the stop it wrote itself, never from the
|
|
302
|
+
name of whoever asked.
|
|
303
|
+
|
|
304
|
+
`TestTheDecision` in `tests/test_queue.py` is a table over every combination
|
|
305
|
+
of those facts. Each row carries the rule from that help as its own label,
|
|
306
|
+
and the table checks that every label is a sentence of the help and that
|
|
307
|
+
their order there is the order the rules are tried in. A combination no rule
|
|
308
|
+
covers fails, and the table needs no process, thread or clock. What stays
|
|
309
|
+
process-level is that the facts are gathered right (the claim, the exit code
|
|
310
|
+
file, the child's status) and that the actions are applied (the signal
|
|
311
|
+
reaches the group, one transaction records the outcome, the hook fires once).
|
|
312
|
+
|
|
313
|
+
### How an agent hears about its job
|
|
314
|
+
|
|
315
|
+
1. `pp queue add` records the calling session as the job's owner, and
|
|
316
|
+
starts the queue's worker if none is running.
|
|
317
|
+
2. The worker starts the job when what it needs is free, in its own process
|
|
318
|
+
group, inside an `sh` that holds the job's run and writes the attempt's
|
|
319
|
+
exit code when the command ends.
|
|
320
|
+
3. That `sh` writes the exit code, so any worker can tell how it ended, even
|
|
321
|
+
one started after it. Each attempt writes to a file of its own, so no
|
|
322
|
+
attempt reads another's code.
|
|
323
|
+
4. The worker records the job as done or failed, retries it if asked, and
|
|
324
|
+
runs its hook on the final outcome.
|
|
325
|
+
5. A `pp queue wait` or `watch` holds a lease on the job while it runs,
|
|
326
|
+
prints the outcome, and stamps the job as reported to its session.
|
|
327
|
+
6. `pp queue wait --mine` takes the session's jobs that are live, or that
|
|
328
|
+
ended with no stamp from that session.
|
|
329
|
+
|
|
330
|
+
### Choices, and why
|
|
331
|
+
|
|
332
|
+
- pp does not type into an agent's terminal to report back. A paste can
|
|
333
|
+
race a person typing, or answer a prompt. The agent runs
|
|
334
|
+
`pp queue wait` in the background and is told when it exits.
|
|
335
|
+
- A plugin is a git clone pinned to a commit, not a package from an index.
|
|
336
|
+
Its code runs as you, so you read the exact commit before it runs, and
|
|
337
|
+
only `pp cmd update` moves it, after showing the diff.
|
|
338
|
+
- Each queue has its own worker, started by the first `add` and stopped
|
|
339
|
+
after a while with nothing to do. There is no daemon to install.
|
|
340
|
+
- A kill never takes the worker claim, even where no worker is up: it starts
|
|
341
|
+
one. A second kind of holder would be a second actor that signals the
|
|
342
|
+
queue's jobs, and every stop would then have to be handed between the two.
|
|
343
|
+
- One store lock covers every queue, not one lock per queue. Job ids are
|
|
344
|
+
machine-wide, and a shared pool is counted against every queue's running
|
|
345
|
+
jobs, so a launch reads other queues' records.
|
|
346
|
+
- `pp queue worker stop` is not a pause: the next command that needs a
|
|
347
|
+
worker starts one. A durable pause would be a record the worker obeys, and
|
|
348
|
+
then a stopped worker and a paused queue would be two states to tell
|
|
349
|
+
apart.
|
|
350
|
+
- A pidfd stands for a process only while pp holds that child. A record on
|
|
351
|
+
disk names a process by pid, start time and boot id instead, since a pidfd
|
|
352
|
+
closes with the process that opened it and says nothing to the next pp.
|
|
353
|
+
- A queue starts jobs strictly in priority order unless `backfill` is on,
|
|
354
|
+
so a big job is not starved by small ones.
|
|
355
|
+
- `wait --mine` keeps no cursor per session: the stamps on the jobs say
|
|
356
|
+
what a session has heard. A session's first `--mine` lists every outcome
|
|
357
|
+
it never heard.
|
|
358
|
+
- `wait` and `watch` exit 3 on a timeout, so a script can tell "still
|
|
359
|
+
running" from "failed".
|
|
360
|
+
- Options between several positional targets, as in `pp kill 1 -n 2`, are
|
|
361
|
+
left to argparse, which rejects them. Put options first or last.
|
|
362
|
+
|
|
363
|
+
## Running your changes
|
|
364
|
+
|
|
365
|
+
`pp promote` in your clone copies HEAD into
|
|
366
|
+
`~/.local/share/pp/releases/pp/STAMP/`, runs `ci/check` inside that copy,
|
|
367
|
+
then points `current` at it. `~/.local/bin/pp` then links to that release,
|
|
368
|
+
in place of the link to the clone, and `~/.local/bin/ppd` links to the
|
|
369
|
+
clone. So `pp` runs code that passed its tests, and `ppd` runs what you are
|
|
370
|
+
editing. `pp promote rollback pp` goes back to the release before.
|
|
371
|
+
|
|
372
|
+
## Releases
|
|
373
|
+
|
|
374
|
+
pp is published on PyPI as ppkit. Before 1.0, the middle number goes up
|
|
375
|
+
only for a change that breaks a config or a command line that worked
|
|
376
|
+
before. Anything else, new features too, raises the last number.
|
|
377
|
+
|
|
378
|
+
Changes collect in `CHANGELOG.md` under `## Unreleased`. A maintainer sets
|
|
379
|
+
the version in `pp/__init__.py` and `pyproject.toml`, renames that heading
|
|
380
|
+
to the tag, such as `## v0.1.1`, and pushes the tag. The release job runs
|
|
381
|
+
CI, builds and tries the package, publishes it to PyPI, and makes a GitHub
|
|
382
|
+
release with that section as its notes. `tests/test_cli.py` checks that the
|
|
383
|
+
two version strings agree and that `CHANGELOG.md` has a section for them.
|
|
384
|
+
|
|
385
|
+
PyPI trusts this repository's `.github/workflows/release.yml` running in
|
|
386
|
+
its `pypi` environment (Trusted Publishing), and no token is stored.
|
|
387
|
+
Renaming either needs the same change on PyPI.
|
|
388
|
+
|
|
389
|
+
The tools are pinned, and move together: uv in both workflows and in
|
|
390
|
+
`pyproject.toml`'s `uv_build` range, ruff in `ci/check`, and the GitHub
|
|
391
|
+
actions by commit. After changing a workflow, run
|
|
392
|
+
`go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12 .github/workflows/*.yml`.
|
ppkit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|