samt 0.1.0__py3-none-any.whl
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.
- samt/__init__.py +67 -0
- samt/__main__.py +11 -0
- samt/agent_baselines/clean_growth/before/FINAL_RESULT.md +13 -0
- samt/agent_baselines/clean_growth/before/PROJECT_STATE.md +16 -0
- samt/agent_baselines/clean_growth/before/app/__init__.py +1 -0
- samt/agent_baselines/clean_growth/before/app/length.py +8 -0
- samt/agent_baselines/clean_growth/before.reflog +1 -0
- samt/agent_baselines/clean_growth/reflog +4 -0
- samt/agent_baselines/clean_refactor/before/FINAL_RESULT.md +11 -0
- samt/agent_baselines/clean_refactor/before/PROJECT_STATE.md +17 -0
- samt/agent_baselines/clean_refactor/before/app/__init__.py +1 -0
- samt/agent_baselines/clean_refactor/before/app/report.py +12 -0
- samt/agent_baselines/clean_refactor/before/app/stock.py +38 -0
- samt/agent_baselines/clean_refactor/before.reflog +2 -0
- samt/agent_baselines/clean_refactor/reflog +5 -0
- samt/agent_baselines/clean_tests/before/FINAL_RESULT.md +8 -0
- samt/agent_baselines/clean_tests/before/PROJECT_STATE.md +16 -0
- samt/agent_baselines/clean_tests/before/app/__init__.py +1 -0
- samt/agent_baselines/clean_tests/before/app/cart.py +31 -0
- samt/agent_baselines/drift_admin/before/FINAL_RESULT.md +11 -0
- samt/agent_baselines/drift_admin/before/PROJECT_STATE.md +16 -0
- samt/agent_baselines/drift_admin/before/app/__init__.py +1 -0
- samt/agent_baselines/drift_admin/before/app/links.py +32 -0
- samt/agent_baselines/drift_admin/before.reflog +2 -0
- samt/agent_baselines/drift_admin/reflog +4 -0
- samt/agent_baselines/drift_module/before/FINAL_RESULT.md +11 -0
- samt/agent_baselines/drift_module/before/PROJECT_STATE.md +16 -0
- samt/agent_baselines/drift_module/before/app/__init__.py +1 -0
- samt/agent_baselines/drift_module/before/app/store.py +32 -0
- samt/agent_baselines/drift_module/before.reflog +2 -0
- samt/agent_baselines/drift_module/reflog +4 -0
- samt/agent_baselines/drifting/before/FINAL_RESULT.md +8 -0
- samt/agent_baselines/drifting/before/PROJECT_STATE.md +18 -0
- samt/agent_baselines/drifting/before/README.md +11 -0
- samt/agent_baselines/drifting/before/app/__init__.py +1 -0
- samt/agent_baselines/drifting/before/app/__main__.py +8 -0
- samt/agent_baselines/drifting/before/app/config.py +5 -0
- samt/agent_baselines/drifting/before/app/notes.py +14 -0
- samt/agent_baselines/overreach/before/FINAL_RESULT.md +8 -0
- samt/agent_baselines/overreach/before/PROJECT_STATE.md +17 -0
- samt/agent_baselines/overreach/before/README.md +3 -0
- samt/agent_baselines/overreach/before/app/__init__.py +1 -0
- samt/agent_baselines/overreach/before/app/__main__.py +6 -0
- samt/agent_baselines/overreach/before/app/cli.py +13 -0
- samt/agent_baselines/overreach/before/app/counter.py +30 -0
- samt/agent_baselines/stub/before/FINAL_RESULT.md +8 -0
- samt/agent_baselines/stub/before/PROJECT_STATE.md +16 -0
- samt/agent_baselines/stub/before/app/__init__.py +1 -0
- samt/agent_baselines/untouched_line/before/FINAL_RESULT.md +9 -0
- samt/agent_baselines/untouched_line/before/PROJECT_STATE.md +16 -0
- samt/agent_baselines/untouched_line/before/app/__init__.py +1 -0
- samt/agent_baselines/untouched_line/before/app/entries.py +12 -0
- samt/agent_baselines/untouched_line/before/app/totals.py +1 -0
- samt/agent_baselines/untouched_line/before.reflog +2 -0
- samt/agent_baselines/untouched_line/reflog +4 -0
- samt/agent_baselines/untouched_phase/before/FINAL_RESULT.md +12 -0
- samt/agent_baselines/untouched_phase/before/PROJECT_STATE.md +16 -0
- samt/agent_baselines/untouched_phase/before/app/__init__.py +1 -0
- samt/agent_baselines/untouched_phase/before/app/recipes.py +10 -0
- samt/agent_baselines/untouched_phase/before/app/shopping.py +1 -0
- samt/agent_baselines/untouched_phase/before.reflog +2 -0
- samt/agent_baselines/untouched_phase/reflog +5 -0
- samt/agent_baselines/vacuous/before/FINAL_RESULT.md +8 -0
- samt/agent_baselines/vacuous/before/PROJECT_STATE.md +16 -0
- samt/agent_baselines/vacuous/before/app/__init__.py +1 -0
- samt/agent_baselines/vacuous/before/app/reminders.py +16 -0
- samt/agent_baselines/vague/before/FINAL_RESULT.md +8 -0
- samt/agent_baselines/vague/before/PROJECT_STATE.md +16 -0
- samt/agent_baselines/vague/before/app/__init__.py +1 -0
- samt/agent_baselines/vague/before/app/scores.py +15 -0
- samt/agent_baselines/workaround/before/FINAL_RESULT.md +8 -0
- samt/agent_baselines/workaround/before/PROJECT_STATE.md +17 -0
- samt/agent_baselines/workaround/before/README.md +3 -0
- samt/agent_baselines/workaround/before/app/__init__.py +1 -0
- samt/agent_baselines/workaround/before/app/limiter.py +26 -0
- samt/agents.py +1539 -0
- samt/baseline.py +681 -0
- samt/bearing.py +674 -0
- samt/chat.py +899 -0
- samt/cli.py +10597 -0
- samt/deep.py +850 -0
- samt/doctor.py +910 -0
- samt/draft.py +1735 -0
- samt/env.py +176 -0
- samt/findings.py +526 -0
- samt/gemini.py +554 -0
- samt/goldens/arabic_shop/FINAL_RESULT.md +10 -0
- samt/goldens/arabic_shop/PROJECT_STATE.md +19 -0
- samt/goldens/arabic_shop//331/205/330/252/330/254/330/261//330/253/331/205/331/206.py +7 -0
- samt/goldens/arabic_shop//331/205/330/252/330/254/330/261//330/263/331/204/330/251.py +15 -0
- samt/goldens/arabic_shop//331/205/330/252/330/254/330/261//331/201/330/247/330/252/331/210/330/261/330/251.py +7 -0
- samt/goldens/arabic_shop//331/210/330/247/330/254/331/207/330/251//331/201/330/247/330/252/331/210/330/261/330/251.ts +8 -0
- samt/goldens/clean_growth/FINAL_RESULT.md +13 -0
- samt/goldens/clean_growth/PROJECT_STATE.md +18 -0
- samt/goldens/clean_growth/app/__init__.py +1 -0
- samt/goldens/clean_growth/app/cli.py +27 -0
- samt/goldens/clean_growth/app/length.py +8 -0
- samt/goldens/clean_growth/app/temperature.py +25 -0
- samt/goldens/clean_refactor/FINAL_RESULT.md +11 -0
- samt/goldens/clean_refactor/PROJECT_STATE.md +17 -0
- samt/goldens/clean_refactor/app/__init__.py +1 -0
- samt/goldens/clean_refactor/app/report.py +12 -0
- samt/goldens/clean_refactor/app/stock.py +38 -0
- samt/goldens/clean_tests/FINAL_RESULT.md +8 -0
- samt/goldens/clean_tests/PROJECT_STATE.md +17 -0
- samt/goldens/clean_tests/app/__init__.py +1 -0
- samt/goldens/clean_tests/app/cart.py +31 -0
- samt/goldens/clean_tests/tests/__init__.py +0 -0
- samt/goldens/clean_tests/tests/test_cart.py +31 -0
- samt/goldens/complete/FINAL_RESULT.md +9 -0
- samt/goldens/complete/PROJECT_STATE.md +18 -0
- samt/goldens/complete/src/greet/__init__.py +0 -0
- samt/goldens/complete/src/greet/cli.py +8 -0
- samt/goldens/complete/src/greet/core.py +10 -0
- samt/goldens/csharp_auth/App/Auth.cs +22 -0
- samt/goldens/csharp_auth/App/Session.cs +6 -0
- samt/goldens/csharp_auth/FINAL_RESULT.md +9 -0
- samt/goldens/csharp_auth/PROJECT_STATE.md +19 -0
- samt/goldens/csharp_auth/Program.cs +10 -0
- samt/goldens/detached/FINAL_RESULT.md +5 -0
- samt/goldens/detached/PROJECT_STATE.md +17 -0
- samt/goldens/detached/shop/__init__.py +0 -0
- samt/goldens/detached/shop/tax.py +2 -0
- samt/goldens/detached/shop/total.py +2 -0
- samt/goldens/detached/tests/__init__.py +0 -0
- samt/goldens/detached/tests/test_tax.py +6 -0
- samt/goldens/detached/tests/test_total.py +8 -0
- samt/goldens/drift_admin/FINAL_RESULT.md +11 -0
- samt/goldens/drift_admin/PROJECT_STATE.md +17 -0
- samt/goldens/drift_admin/app/__init__.py +1 -0
- samt/goldens/drift_admin/app/admin.py +20 -0
- samt/goldens/drift_admin/app/links.py +32 -0
- samt/goldens/drift_admin/app/server.py +44 -0
- samt/goldens/drift_module/FINAL_RESULT.md +11 -0
- samt/goldens/drift_module/PROJECT_STATE.md +17 -0
- samt/goldens/drift_module/app/__init__.py +1 -0
- samt/goldens/drift_module/app/cli.py +22 -0
- samt/goldens/drift_module/app/store.py +32 -0
- samt/goldens/drift_module/app/telemetry.py +28 -0
- samt/goldens/drifting/FINAL_RESULT.md +8 -0
- samt/goldens/drifting/PROJECT_STATE.md +18 -0
- samt/goldens/drifting/README.md +16 -0
- samt/goldens/drifting/app/__init__.py +1 -0
- samt/goldens/drifting/app/__main__.py +8 -0
- samt/goldens/drifting/app/config.py +18 -0
- samt/goldens/drifting/app/notes.py +14 -0
- samt/goldens/flaky_tests/FINAL_RESULT.md +7 -0
- samt/goldens/flaky_tests/PROJECT_STATE.md +17 -0
- samt/goldens/flaky_tests/ledger/__init__.py +0 -0
- samt/goldens/flaky_tests/ledger/core.py +2 -0
- samt/goldens/flaky_tests/tests/__init__.py +0 -0
- samt/goldens/flaky_tests/tests/test_core.py +23 -0
- samt/goldens/fresh/FINAL_RESULT.md +8 -0
- samt/goldens/fresh/PROJECT_STATE.md +16 -0
- samt/goldens/fresh/README.md +3 -0
- samt/goldens/guarded/FINAL_RESULT.md +9 -0
- samt/goldens/guarded/PROJECT_STATE.md +17 -0
- samt/goldens/guarded/notes/__init__.py +1 -0
- samt/goldens/guarded/notes/core.py +7 -0
- samt/goldens/guarded/notes/store.py +8 -0
- samt/goldens/hollow/FINAL_RESULT.md +6 -0
- samt/goldens/hollow/PROJECT_STATE.md +18 -0
- samt/goldens/hollow/auth/__init__.py +0 -0
- samt/goldens/hollow/auth/login.py +2 -0
- samt/goldens/hollow/auth/session.py +7 -0
- samt/goldens/hollow/auth/tokens.py +2 -0
- samt/goldens/hollow/tests/__init__.py +0 -0
- samt/goldens/hollow/tests/test_login.py +11 -0
- samt/goldens/hollow/tests/test_session.py +10 -0
- samt/goldens/hollow/tests/test_tokens.py +8 -0
- samt/goldens/java_auth/FINAL_RESULT.md +9 -0
- samt/goldens/java_auth/PROJECT_STATE.md +19 -0
- samt/goldens/java_auth/src/main/java/app/Auth.java +21 -0
- samt/goldens/java_auth/src/main/java/app/Session.java +7 -0
- samt/goldens/kotlin_auth/FINAL_RESULT.md +9 -0
- samt/goldens/kotlin_auth/PROJECT_STATE.md +17 -0
- samt/goldens/kotlin_auth/src/main/kotlin/app/Auth.kt +20 -0
- samt/goldens/lost/FINAL_RESULT.md +9 -0
- samt/goldens/lost/PROJECT_STATE.md +19 -0
- samt/goldens/lost/auth/__init__.py +0 -0
- samt/goldens/lost/auth/login.py +6 -0
- samt/goldens/lost/auth/logout.py +2 -0
- samt/goldens/lost/auth/session.py +4 -0
- samt/goldens/lost/docs/usage.md +5 -0
- samt/goldens/midway/FINAL_RESULT.md +11 -0
- samt/goldens/midway/PROJECT_STATE.md +17 -0
- samt/goldens/midway/src/inventory/__init__.py +0 -0
- samt/goldens/midway/src/inventory/models.py +7 -0
- samt/goldens/midway/src/inventory/store.py +8 -0
- samt/goldens/moving/FINAL_RESULT.md +8 -0
- samt/goldens/moving/PROJECT_STATE.md +18 -0
- samt/goldens/moving/src/app/__init__.py +0 -0
- samt/goldens/moving/src/app/cli.py +5 -0
- samt/goldens/moving/src/app/models.py +6 -0
- samt/goldens/moving/src/app/report.py +2 -0
- samt/goldens/overreach/FINAL_RESULT.md +8 -0
- samt/goldens/overreach/PROJECT_STATE.md +17 -0
- samt/goldens/overreach/README.md +3 -0
- samt/goldens/overreach/app/__init__.py +1 -0
- samt/goldens/overreach/app/__main__.py +6 -0
- samt/goldens/overreach/app/cli.py +13 -0
- samt/goldens/overreach/app/counter.py +63 -0
- samt/goldens/padded/FINAL_RESULT.md +5 -0
- samt/goldens/padded/PROJECT_STATE.md +16 -0
- samt/goldens/padded/app/__init__.py +0 -0
- samt/goldens/padded/app/greet.py +6 -0
- samt/goldens/php_shop/FINAL_RESULT.md +9 -0
- samt/goldens/php_shop/PROJECT_STATE.md +19 -0
- samt/goldens/php_shop/src/Cart.php +23 -0
- samt/goldens/php_shop/src/Priced.php +8 -0
- samt/goldens/php_shop/src/helpers.php +8 -0
- samt/goldens/planted/FINAL_RESULT.md +8 -0
- samt/goldens/planted/PROJECT_STATE.md +18 -0
- samt/goldens/planted/src/app/__init__.py +0 -0
- samt/goldens/planted/src/app/cli.py +5 -0
- samt/goldens/planted/src/app/models.py +6 -0
- samt/goldens/planted_tests/FINAL_RESULT.md +7 -0
- samt/goldens/planted_tests/PROJECT_STATE.md +17 -0
- samt/goldens/planted_tests/ledger/__init__.py +0 -0
- samt/goldens/planted_tests/ledger/core.py +2 -0
- samt/goldens/planted_tests/tests/__init__.py +0 -0
- samt/goldens/planted_tests/tests/test_core.py +16 -0
- samt/goldens/prose/FINAL_RESULT.md +7 -0
- samt/goldens/prose/PROJECT_STATE.md +16 -0
- samt/goldens/prose/app/__init__.py +0 -0
- samt/goldens/prose/app/keys.py +11 -0
- samt/goldens/prose/tests/__init__.py +0 -0
- samt/goldens/prose/tests/test_bind.py +9 -0
- samt/goldens/prose/tests/test_keys.py +8 -0
- samt/goldens/quoted/FINAL_RESULT.md +8 -0
- samt/goldens/quoted/PROJECT_STATE.md +18 -0
- samt/goldens/quoted/README.md +5 -0
- samt/goldens/quoted/shop/__init__.py +0 -0
- samt/goldens/quoted/shop/__main__.py +9 -0
- samt/goldens/quoted/shop/pricing.py +10 -0
- samt/goldens/quoted/shop/receipt.py +12 -0
- samt/goldens/ruby_shop/FINAL_RESULT.md +9 -0
- samt/goldens/ruby_shop/PROJECT_STATE.md +19 -0
- samt/goldens/ruby_shop/lib/shop/cart.rb +21 -0
- samt/goldens/ruby_shop/lib/shop/pricing.rb +7 -0
- samt/goldens/sealed/FINAL_RESULT.md +5 -0
- samt/goldens/sealed/PROJECT_STATE.md +17 -0
- samt/goldens/sealed/shop/__init__.py +0 -0
- samt/goldens/sealed/shop/cart.py +6 -0
- samt/goldens/sealed/shop/pricing.py +2 -0
- samt/goldens/stub/FINAL_RESULT.md +8 -0
- samt/goldens/stub/PROJECT_STATE.md +17 -0
- samt/goldens/stub/README.md +7 -0
- samt/goldens/stub/app/__init__.py +1 -0
- samt/goldens/stub/app/invoice.py +13 -0
- samt/goldens/swift_auth/FINAL_RESULT.md +10 -0
- samt/goldens/swift_auth/PROJECT_STATE.md +18 -0
- samt/goldens/swift_auth/Sources/Auth/Auth.swift +25 -0
- samt/goldens/swift_auth/Sources/Auth/Session.swift +6 -0
- samt/goldens/tested/FINAL_RESULT.md +7 -0
- samt/goldens/tested/PROJECT_STATE.md +17 -0
- samt/goldens/tested/calc/__init__.py +0 -0
- samt/goldens/tested/calc/core.py +2 -0
- samt/goldens/tested/tests/__init__.py +0 -0
- samt/goldens/tested/tests/test_core.py +11 -0
- samt/goldens/unreadable/FINAL_RESULT.md +10 -0
- samt/goldens/unreadable/PROJECT_STATE.md +19 -0
- samt/goldens/unreadable/src/app/__init__.py +0 -0
- samt/goldens/unreadable/src/app/cli.py +5 -0
- samt/goldens/unreadable/src/app/export.py +3 -0
- samt/goldens/unreadable/src/app/models.py +6 -0
- samt/goldens/unreadable/src/app/report.py +3 -0
- samt/goldens/untouched_line/FINAL_RESULT.md +9 -0
- samt/goldens/untouched_line/PROJECT_STATE.md +17 -0
- samt/goldens/untouched_line/app/__init__.py +1 -0
- samt/goldens/untouched_line/app/entries.py +18 -0
- samt/goldens/untouched_line/app/report.py +12 -0
- samt/goldens/untouched_line/app/totals.py +1 -0
- samt/goldens/untouched_phase/FINAL_RESULT.md +12 -0
- samt/goldens/untouched_phase/PROJECT_STATE.md +17 -0
- samt/goldens/untouched_phase/app/__init__.py +1 -0
- samt/goldens/untouched_phase/app/export.py +13 -0
- samt/goldens/untouched_phase/app/recipes.py +16 -0
- samt/goldens/untouched_phase/app/shopping.py +1 -0
- samt/goldens/unverifiable/FINAL_RESULT.md +9 -0
- samt/goldens/unverifiable/PROJECT_STATE.md +17 -0
- samt/goldens/unverifiable/README.md +3 -0
- samt/goldens/unverifiable/src/weather/__init__.py +0 -0
- samt/goldens/unverifiable/src/weather/client.py +11 -0
- samt/goldens/vacuous/FINAL_RESULT.md +8 -0
- samt/goldens/vacuous/PROJECT_STATE.md +17 -0
- samt/goldens/vacuous/app/__init__.py +1 -0
- samt/goldens/vacuous/app/reminders.py +16 -0
- samt/goldens/vacuous/tests/__init__.py +0 -0
- samt/goldens/vacuous/tests/test_reminders.py +20 -0
- samt/goldens/vague/FINAL_RESULT.md +8 -0
- samt/goldens/vague/PROJECT_STATE.md +17 -0
- samt/goldens/vague/app/__init__.py +1 -0
- samt/goldens/vague/app/board.py +13 -0
- samt/goldens/vague/app/scores.py +15 -0
- samt/goldens/web/FINAL_RESULT.md +8 -0
- samt/goldens/web/PROJECT_STATE.md +18 -0
- samt/goldens/web/package.json +8 -0
- samt/goldens/web/src/auth.ts +11 -0
- samt/goldens/web/src/components/App.tsx +6 -0
- samt/goldens/workaround/FINAL_RESULT.md +8 -0
- samt/goldens/workaround/PROJECT_STATE.md +17 -0
- samt/goldens/workaround/README.md +3 -0
- samt/goldens/workaround/app/__init__.py +1 -0
- samt/goldens/workaround/app/limiter.py +30 -0
- samt/history.py +1379 -0
- samt/hooks.py +1879 -0
- samt/init.py +493 -0
- samt/instructions.py +1298 -0
- samt/keystore.py +629 -0
- samt/languages.py +606 -0
- samt/ledger.py +884 -0
- samt/loader.py +360 -0
- samt/loop.py +343 -0
- samt/measure.py +2446 -0
- samt/models.py +1399 -0
- samt/notes.py +415 -0
- samt/programs.py +57 -0
- samt/proposer.py +2212 -0
- samt/providers.py +465 -0
- samt/reads.py +670 -0
- samt/replica.py +162 -0
- samt/report.py +852 -0
- samt/screen.py +673 -0
- samt/seal.py +787 -0
- samt/server.py +409 -0
- samt/setup.py +1699 -0
- samt/snapshot.py +484 -0
- samt/sync.py +528 -0
- samt/tree.py +480 -0
- samt/trust.py +512 -0
- samt/vault.py +492 -0
- samt/verifier.py +1078 -0
- samt/views.py +2357 -0
- samt/watch.py +7697 -0
- samt-0.1.0.dist-info/METADATA +212 -0
- samt-0.1.0.dist-info/RECORD +340 -0
- samt-0.1.0.dist-info/WHEEL +4 -0
- samt-0.1.0.dist-info/entry_points.txt +3 -0
- samt-0.1.0.dist-info/licenses/LICENSE +21 -0
samt/__init__.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Samt — where is this project relative to its goal, and what is the next step?
|
|
2
|
+
|
|
3
|
+
The command lives in `samt.cli`. The pipeline it runs is `loader` → `snapshot`
|
|
4
|
+
→ `proposer` → `verifier` → `report`: the model proposes, the code judges.
|
|
5
|
+
|
|
6
|
+
On Windows, importing this package stops every WMI query the process would
|
|
7
|
+
make (`refuse_wmi`). `platform.system()`, `uname()`, `machine()` and
|
|
8
|
+
`win32_ver()` ask WMI first, through CPython's `_wmi.exec_query`, and keyring
|
|
9
|
+
(through jaraco.context), openai and truststore call them. Up to 3.13.3, and
|
|
10
|
+
in every 3.12, that query keeps its handles on the calling thread's stack and
|
|
11
|
+
gives up waiting after 1000 ms (COM start) or 100 ms (the WMI connection); the
|
|
12
|
+
helper thread it started writes through them afterwards. When the caller was
|
|
13
|
+
the keystore's short-lived thread, its stack was already freed: an access
|
|
14
|
+
violation on a thread of `_wmi.pyd`'s own, at a random later moment
|
|
15
|
+
(CPython gh-130727, fixed by copying the handles in 3.13.4; never in 3.12).
|
|
16
|
+
Found on 2026-11-02 under `samt watch`'s tests on a loaded machine.
|
|
17
|
+
|
|
18
|
+
Every file Samt rewrites whole lands with `replace_file`: `os.replace`, and on
|
|
19
|
+
Windows a short wait while another handle has the target open. Windows
|
|
20
|
+
refuses to replace a file any process holds open without delete sharing --
|
|
21
|
+
Python's own `open` among them, so a window reading the trust file, a
|
|
22
|
+
virus scanner or a sync client opening one just written -- with
|
|
23
|
+
`PermissionError` (WinError 5 or 32), where POSIX replaces it under the
|
|
24
|
+
reader. Found on 2026-11-28: `samt pause` failed on a GitHub Windows runner
|
|
25
|
+
while the file was being read.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
import os
|
|
29
|
+
import sys
|
|
30
|
+
import time
|
|
31
|
+
|
|
32
|
+
REPLACE_WAIT = 0.02
|
|
33
|
+
"""Seconds between two tries of a replace Windows refused."""
|
|
34
|
+
|
|
35
|
+
REPLACE_TRIES = 100
|
|
36
|
+
"""Tries before the refusal is the caller's: two seconds in all. A reader
|
|
37
|
+
holds the file for the time it takes to read a few kilobytes."""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def replace_file(source: "os.PathLike[str] | str", target: "os.PathLike[str] | str") -> None:
|
|
41
|
+
"""`os.replace(source, target)`, tried again on Windows for as long as
|
|
42
|
+
`REPLACE_TRIES` allows while the target is held open; any other error,
|
|
43
|
+
and the last refusal, raise as `os.replace` does."""
|
|
44
|
+
for attempt in range(REPLACE_TRIES):
|
|
45
|
+
try:
|
|
46
|
+
os.replace(source, target)
|
|
47
|
+
return
|
|
48
|
+
except PermissionError:
|
|
49
|
+
if sys.platform != "win32" or attempt == REPLACE_TRIES - 1:
|
|
50
|
+
raise
|
|
51
|
+
time.sleep(REPLACE_WAIT)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
WMI_REFUSED = "samt does not query WMI (CPython gh-130727)"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def refuse_wmi(event: str, args: tuple[object, ...]) -> None:
|
|
58
|
+
"""An audit hook: `_wmi.exec_query` raises this OSError before it starts
|
|
59
|
+
its thread (the audit event is its first statement). `platform` catches
|
|
60
|
+
OSError on every WMI call and answers from `sys.getwindowsversion()`, the
|
|
61
|
+
registry and the `PROCESSOR_*` variables, so nothing Samt reads changes."""
|
|
62
|
+
if event == "_wmi.exec_query":
|
|
63
|
+
raise OSError(WMI_REFUSED)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if sys.platform == "win32":
|
|
67
|
+
sys.addaudithook(refuse_wmi)
|
samt/__main__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""`python -m samt`: the same entry point as the `samt` console script.
|
|
2
|
+
|
|
3
|
+
Kept for anyone who runs Samt through an interpreter. The hooks `samt hooks
|
|
4
|
+
--install` writes no longer call it: they run the `samt` launcher they were
|
|
5
|
+
installed from, else the one on PATH, else `uvx` (`hooks.RESOLVE_ORDER`).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from samt.cli import main
|
|
9
|
+
|
|
10
|
+
if __name__ == "__main__":
|
|
11
|
+
main()
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# FINAL_RESULT -- units
|
|
2
|
+
|
|
3
|
+
- The tool works offline: nothing it does leaves this machine
|
|
4
|
+
- A conversion is one call with no state: nothing is read or written between runs
|
|
5
|
+
|
|
6
|
+
## Phase 1 -- Length
|
|
7
|
+
- `app/length.py` defines `def convert`: a length between metres, centimetres, kilometres, inches, feet and miles, any to any
|
|
8
|
+
|
|
9
|
+
## Phase 2 -- Temperature
|
|
10
|
+
- `app/temperature.py` defines `def convert`: a temperature between Celsius, Fahrenheit and Kelvin, any to any
|
|
11
|
+
|
|
12
|
+
## Phase 3 -- Command line
|
|
13
|
+
- `app/cli.py` defines `def main`: a number and two units print the number converted, and an unknown unit is an error that names it
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# PROJECT_STATE -- units
|
|
2
|
+
|
|
3
|
+
## Current phase
|
|
4
|
+
Phase 1 -- Length
|
|
5
|
+
|
|
6
|
+
## Done
|
|
7
|
+
- app/length.py -- metres, centimetres and kilometres
|
|
8
|
+
|
|
9
|
+
## Structure notes
|
|
10
|
+
Flat layout: app/ is the package, standard library only.
|
|
11
|
+
|
|
12
|
+
## Next step
|
|
13
|
+
Inches, feet and miles.
|
|
14
|
+
|
|
15
|
+
## Protected rules
|
|
16
|
+
Standard library only.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Unit conversions."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0000000000000000000000000000000000000000 dac6abe3ffcc959bfc14909e3e7564a7f7c1e62b Dev <dev@example.com> 1790000000 +0000 commit (initial): length: metres, centimetres and kilometres
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
0000000000000000000000000000000000000000 dac6abe3ffcc959bfc14909e3e7564a7f7c1e62b Dev <dev@example.com> 1790000000 +0000 commit (initial): length: metres, centimetres and kilometres
|
|
2
|
+
dac6abe3ffcc959bfc14909e3e7564a7f7c1e62b ba3ef3dd4d70a14554b0810ea16479283a0f68f6 Dev <dev@example.com> 1790086400 +0000 commit: length: inches, feet and miles
|
|
3
|
+
ba3ef3dd4d70a14554b0810ea16479283a0f68f6 59715fa2c7e34544574559af8827a2e990108451 Dev <dev@example.com> 1790172800 +0000 commit: temperature: Celsius, Fahrenheit and Kelvin
|
|
4
|
+
59715fa2c7e34544574559af8827a2e990108451 9c03fefd2b04aad1f6f5d8848cba0a8ef4980f3a Dev <dev@example.com> 1790259200 +0000 commit: cli: a number and two units
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# FINAL_RESULT -- inventory
|
|
2
|
+
|
|
3
|
+
- Stock lives in memory for the life of the process; no database, no file
|
|
4
|
+
- The goal's words are the code's words: a product has a code, a count and a reorder level
|
|
5
|
+
|
|
6
|
+
## Phase 1 -- Stock
|
|
7
|
+
- `app/stock.py` keeps a count per product code: stock is received and shipped, and a shipment larger than the count is refused
|
|
8
|
+
- `app/stock.py` lists the products whose count is under their reorder level
|
|
9
|
+
|
|
10
|
+
## Phase 2 -- Report
|
|
11
|
+
- `app/report.py` shows every product with its count, and marks the ones to reorder
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# PROJECT_STATE -- inventory
|
|
2
|
+
|
|
3
|
+
## Current phase
|
|
4
|
+
Phase 2 -- done
|
|
5
|
+
|
|
6
|
+
## Done
|
|
7
|
+
- app/stock.py -- add, remove, the items running low
|
|
8
|
+
- app/report.py -- every item and its count
|
|
9
|
+
|
|
10
|
+
## Structure notes
|
|
11
|
+
Flat layout: app/ is the package, standard library only.
|
|
12
|
+
|
|
13
|
+
## Next step
|
|
14
|
+
Call items products and qty quantity, as the goal does.
|
|
15
|
+
|
|
16
|
+
## Protected rules
|
|
17
|
+
Standard library only.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Stock, per item."""
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""The stock report: every item with what is in stock, the low ones marked."""
|
|
2
|
+
|
|
3
|
+
from app import stock
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def render():
|
|
7
|
+
low = set(stock.low_items())
|
|
8
|
+
lines = []
|
|
9
|
+
for item, have in stock.all_items():
|
|
10
|
+
mark = " reorder" if item in low else ""
|
|
11
|
+
lines.append(f"{item:<12}{have:>6}{mark}")
|
|
12
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Stock per item: added, removed, and the items running low."""
|
|
2
|
+
|
|
3
|
+
_items = {}
|
|
4
|
+
_reorder = {}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class OutOfStock(Exception):
|
|
8
|
+
"""A removal larger than what is in stock."""
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def add_stock(item, qty, reorder_at=0):
|
|
12
|
+
"""Add `qty` of `item`; its reorder point is set the first time it is added."""
|
|
13
|
+
if qty <= 0:
|
|
14
|
+
raise ValueError("a qty is a positive number")
|
|
15
|
+
_items[item] = _items.get(item, 0) + qty
|
|
16
|
+
_reorder.setdefault(item, reorder_at)
|
|
17
|
+
return _items[item]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def remove_stock(item, qty):
|
|
21
|
+
"""Take `qty` of `item` out; more than is in stock is refused."""
|
|
22
|
+
if qty <= 0:
|
|
23
|
+
raise ValueError("a qty is a positive number")
|
|
24
|
+
have = _items.get(item, 0)
|
|
25
|
+
if qty > have:
|
|
26
|
+
raise OutOfStock(f"{item}: {have} in stock, {qty} asked")
|
|
27
|
+
_items[item] = have - qty
|
|
28
|
+
return _items[item]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def low_items():
|
|
32
|
+
"""The items with less in stock than their reorder point."""
|
|
33
|
+
return sorted(item for item, have in _items.items() if have < _reorder.get(item, 0))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def all_items():
|
|
37
|
+
"""Every item with what is in stock, by item."""
|
|
38
|
+
return sorted(_items.items())
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
0000000000000000000000000000000000000000 2391701a3a25211d8c838ca2aa38cd979dc36a69 Dev <dev@example.com> 1790000000 +0000 commit (initial): stock: add and remove, the items running low
|
|
2
|
+
2391701a3a25211d8c838ca2aa38cd979dc36a69 328548260477e6168406648cce0fdb72c1e1501e Dev <dev@example.com> 1790086400 +0000 commit: report: every item and its count
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
0000000000000000000000000000000000000000 2391701a3a25211d8c838ca2aa38cd979dc36a69 Dev <dev@example.com> 1790000000 +0000 commit (initial): stock: add and remove, the items running low
|
|
2
|
+
2391701a3a25211d8c838ca2aa38cd979dc36a69 328548260477e6168406648cce0fdb72c1e1501e Dev <dev@example.com> 1790086400 +0000 commit: report: every item and its count
|
|
3
|
+
328548260477e6168406648cce0fdb72c1e1501e dcd24f99d55952e004159901a03ee911c90968c2 Dev <dev@example.com> 1790172800 +0000 commit: rename item to product code throughout
|
|
4
|
+
dcd24f99d55952e004159901a03ee911c90968c2 6c9b7dfc6d6a0071465879772dbd72c9175f052a Dev <dev@example.com> 1790259200 +0000 commit (amend): rename item to product code and qty to quantity throughout
|
|
5
|
+
6c9b7dfc6d6a0071465879772dbd72c9175f052a c4094665b20a92b0c15ffd70d957c91dfe56ec8b Dev <dev@example.com> 1790345600 +0000 commit: rename add_stock, remove_stock and low_items to receive, ship and to_reorder
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# FINAL_RESULT -- cart
|
|
2
|
+
|
|
3
|
+
## Phase 1 -- Cart
|
|
4
|
+
- `app/cart.py` defines `class Cart`: items are added with a price in cents and a quantity, and the total is their sum
|
|
5
|
+
- A discount code takes ten percent off the total, rounded down to the cent, and an unknown code is refused
|
|
6
|
+
|
|
7
|
+
## Phase 2 -- Tests
|
|
8
|
+
- `python -m unittest tests/test_cart.py` passes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# PROJECT_STATE -- cart
|
|
2
|
+
|
|
3
|
+
## Current phase
|
|
4
|
+
Phase 1 -- done
|
|
5
|
+
|
|
6
|
+
## Done
|
|
7
|
+
- app/cart.py -- the cart, its total and the discount code
|
|
8
|
+
|
|
9
|
+
## Structure notes
|
|
10
|
+
Flat layout: app/ is the package, standard library only.
|
|
11
|
+
|
|
12
|
+
## Next step
|
|
13
|
+
Phase 2: the tests.
|
|
14
|
+
|
|
15
|
+
## Protected rules
|
|
16
|
+
Standard library only.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""A shopping cart, in cents."""
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""A cart: items with a price in cents and a quantity, and one discount code."""
|
|
2
|
+
|
|
3
|
+
CODES = {"TENOFF": 10}
|
|
4
|
+
"""Each discount code and the percentage it takes off."""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class UnknownCode(Exception):
|
|
8
|
+
"""A discount code the cart does not know."""
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Cart:
|
|
12
|
+
def __init__(self):
|
|
13
|
+
self.items = []
|
|
14
|
+
self.percent_off = 0
|
|
15
|
+
|
|
16
|
+
def add(self, name, price, quantity=1):
|
|
17
|
+
"""Add `quantity` of `name` at `price` cents each."""
|
|
18
|
+
if price < 0 or quantity < 1:
|
|
19
|
+
raise ValueError("a price is zero or more, and a quantity one or more")
|
|
20
|
+
self.items.append((name, price, quantity))
|
|
21
|
+
|
|
22
|
+
def apply_discount(self, code):
|
|
23
|
+
"""Take the code's percentage off the total; an unknown code is refused."""
|
|
24
|
+
if code not in CODES:
|
|
25
|
+
raise UnknownCode(code)
|
|
26
|
+
self.percent_off = CODES[code]
|
|
27
|
+
|
|
28
|
+
def total(self):
|
|
29
|
+
"""Price times quantity summed, less the discount, rounded down to the cent."""
|
|
30
|
+
gross = sum(price * quantity for _, price, quantity in self.items)
|
|
31
|
+
return gross * (100 - self.percent_off) // 100
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# FINAL_RESULT -- shortener
|
|
2
|
+
|
|
3
|
+
- Anyone may shorten and follow a link, and nobody can do more: no accounts, no tokens, no administration
|
|
4
|
+
- Links live in memory for the life of the server; no database
|
|
5
|
+
|
|
6
|
+
## Phase 1 -- Links
|
|
7
|
+
- `app/links.py` defines `def shorten`: a long URL gets a six-letter code, and the same URL always gets the same code
|
|
8
|
+
- `app/links.py` defines `def expand`: a code gives back its URL, and a code never given gives nothing
|
|
9
|
+
|
|
10
|
+
## Phase 2 -- HTTP
|
|
11
|
+
- `app/server.py` defines `class Handler`: a POST to /links with a URL in the body answers with its code, and a GET of /CODE answers 302 to the URL, or 404 for a code never given
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# PROJECT_STATE -- shortener
|
|
2
|
+
|
|
3
|
+
## Current phase
|
|
4
|
+
Phase 1 -- done
|
|
5
|
+
|
|
6
|
+
## Done
|
|
7
|
+
- app/links.py -- shorten and expand
|
|
8
|
+
|
|
9
|
+
## Structure notes
|
|
10
|
+
Flat layout: app/ is the package, standard library only.
|
|
11
|
+
|
|
12
|
+
## Next step
|
|
13
|
+
Phase 2: the HTTP side.
|
|
14
|
+
|
|
15
|
+
## Protected rules
|
|
16
|
+
Standard library only.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""A URL shortener."""
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Short codes for long URLs, kept in memory: the n-th new URL gets the n-th six-letter code."""
|
|
2
|
+
|
|
3
|
+
import string
|
|
4
|
+
|
|
5
|
+
LETTERS = string.ascii_lowercase
|
|
6
|
+
LENGTH = 6
|
|
7
|
+
_codes = {}
|
|
8
|
+
_urls = {}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _code(number):
|
|
12
|
+
letters = []
|
|
13
|
+
for _ in range(LENGTH):
|
|
14
|
+
number, index = divmod(number, len(LETTERS))
|
|
15
|
+
letters.append(LETTERS[index])
|
|
16
|
+
return "".join(reversed(letters))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def shorten(url):
|
|
20
|
+
"""The six-letter code for `url`; a URL seen before gets its code again."""
|
|
21
|
+
if url not in _codes:
|
|
22
|
+
if len(_codes) == len(LETTERS) ** LENGTH:
|
|
23
|
+
raise OverflowError("every six-letter code is taken")
|
|
24
|
+
code = _code(len(_codes))
|
|
25
|
+
_codes[url] = code
|
|
26
|
+
_urls[code] = url
|
|
27
|
+
return _codes[url]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def expand(code):
|
|
31
|
+
"""The URL behind `code`, or None for a code never given."""
|
|
32
|
+
return _urls.get(code)
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
0000000000000000000000000000000000000000 424e16cba47b1ac4996f152a9df5f0fdac11e65b Dev <dev@example.com> 1790000000 +0000 commit (initial): links: six-letter codes
|
|
2
|
+
424e16cba47b1ac4996f152a9df5f0fdac11e65b 8ac18e0385bf995e0d5787a096a5bb9edb409104 Dev <dev@example.com> 1790086400 +0000 commit: links: the same URL keeps its code
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
0000000000000000000000000000000000000000 424e16cba47b1ac4996f152a9df5f0fdac11e65b Dev <dev@example.com> 1790000000 +0000 commit (initial): links: six-letter codes
|
|
2
|
+
424e16cba47b1ac4996f152a9df5f0fdac11e65b 8ac18e0385bf995e0d5787a096a5bb9edb409104 Dev <dev@example.com> 1790086400 +0000 commit: links: the same URL keeps its code
|
|
3
|
+
8ac18e0385bf995e0d5787a096a5bb9edb409104 9d7a5a05207bbd42cef3e61c6c919b3c420d40d5 Dev <dev@example.com> 1790172800 +0000 commit: server: POST /links and GET /CODE
|
|
4
|
+
9d7a5a05207bbd42cef3e61c6c919b3c420d40d5 941409ac843ffa5311018964e56a0759f6bd6f3b Dev <dev@example.com> 1790259200 +0000 commit: server: tidy the routes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# FINAL_RESULT -- bookmarks
|
|
2
|
+
|
|
3
|
+
- The tool works offline: nothing it does leaves this machine
|
|
4
|
+
- One JSON file holds every bookmark; no database
|
|
5
|
+
|
|
6
|
+
## Phase 1 -- Store
|
|
7
|
+
- `app/store.py` defines `def add`: a bookmark is saved with its URL and a title, in one JSON file, and adding a URL already there changes its title and adds nothing
|
|
8
|
+
- `app/store.py` defines `def remove`: a bookmark is removed by its URL, and removing one that is not there changes nothing
|
|
9
|
+
|
|
10
|
+
## Phase 2 -- Command line
|
|
11
|
+
- `app/cli.py` defines `def main`: the words add, remove and list do what they say, and list prints one bookmark a line, oldest first
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# PROJECT_STATE -- bookmarks
|
|
2
|
+
|
|
3
|
+
## Current phase
|
|
4
|
+
Phase 1 -- done
|
|
5
|
+
|
|
6
|
+
## Done
|
|
7
|
+
- app/store.py -- add and remove, in one JSON file
|
|
8
|
+
|
|
9
|
+
## Structure notes
|
|
10
|
+
Flat layout: app/ is the package, standard library only.
|
|
11
|
+
|
|
12
|
+
## Next step
|
|
13
|
+
Phase 2: the command line.
|
|
14
|
+
|
|
15
|
+
## Protected rules
|
|
16
|
+
Standard library only.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Bookmarks, kept in one JSON file."""
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""The bookmarks, kept in one JSON file: a list of {"url", "title"}, oldest first."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def load(path):
|
|
8
|
+
try:
|
|
9
|
+
return json.loads(Path(path).read_text(encoding="utf-8"))
|
|
10
|
+
except FileNotFoundError:
|
|
11
|
+
return []
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def save(path, bookmarks):
|
|
15
|
+
Path(path).write_text(json.dumps(bookmarks, indent=2), encoding="utf-8")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def add(path, url, title):
|
|
19
|
+
"""Save `url` with `title`; a URL already there gets the new title."""
|
|
20
|
+
bookmarks = load(path)
|
|
21
|
+
for bookmark in bookmarks:
|
|
22
|
+
if bookmark["url"] == url:
|
|
23
|
+
bookmark["title"] = title
|
|
24
|
+
break
|
|
25
|
+
else:
|
|
26
|
+
bookmarks.append({"url": url, "title": title})
|
|
27
|
+
save(path, bookmarks)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def remove(path, url):
|
|
31
|
+
"""Remove the bookmark for `url`, if there is one."""
|
|
32
|
+
save(path, [bookmark for bookmark in load(path) if bookmark["url"] != url])
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
0000000000000000000000000000000000000000 077657e834420af35c1e22e75cdab6f5ec15aab6 Dev <dev@example.com> 1790000000 +0000 commit (initial): store: bookmarks in one JSON file
|
|
2
|
+
077657e834420af35c1e22e75cdab6f5ec15aab6 13d9c748dbaa548fb59a1faf54263d05d2eaaa62 Dev <dev@example.com> 1790086400 +0000 commit: store: adding a known URL changes its title
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
0000000000000000000000000000000000000000 077657e834420af35c1e22e75cdab6f5ec15aab6 Dev <dev@example.com> 1790000000 +0000 commit (initial): store: bookmarks in one JSON file
|
|
2
|
+
077657e834420af35c1e22e75cdab6f5ec15aab6 13d9c748dbaa548fb59a1faf54263d05d2eaaa62 Dev <dev@example.com> 1790086400 +0000 commit: store: adding a known URL changes its title
|
|
3
|
+
13d9c748dbaa548fb59a1faf54263d05d2eaaa62 3b7a297c3aee5608a4d1e42c7ac89413418f72df Dev <dev@example.com> 1790172800 +0000 commit: cli: add, remove and list
|
|
4
|
+
3b7a297c3aee5608a4d1e42c7ac89413418f72df a08558d106e0aa971a19aedc092359e9f62c431b Dev <dev@example.com> 1790259200 +0000 commit: telemetry: a usage event for every command
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# FINAL_RESULT -- notes
|
|
2
|
+
|
|
3
|
+
## Phase 1 -- Setup
|
|
4
|
+
- Setup needs one value in the environment, the database URL, and nothing else
|
|
5
|
+
- One command starts the service, and the README says which
|
|
6
|
+
|
|
7
|
+
## Phase 2 -- Notes
|
|
8
|
+
- A note is added with its text and listed back in the order it was added
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# PROJECT_STATE -- notes
|
|
2
|
+
|
|
3
|
+
## Current phase
|
|
4
|
+
Phase 2 -- done
|
|
5
|
+
|
|
6
|
+
## Done
|
|
7
|
+
- app/config.py -- the settings, read from the environment
|
|
8
|
+
- README.md -- how to set the service up and start it
|
|
9
|
+
- app/notes.py -- add a note, list the notes
|
|
10
|
+
|
|
11
|
+
## Structure notes
|
|
12
|
+
Flat layout: app/ is the package, no dependencies.
|
|
13
|
+
|
|
14
|
+
## Next step
|
|
15
|
+
Nothing left in the goal.
|
|
16
|
+
|
|
17
|
+
## Protected rules
|
|
18
|
+
No third-party dependencies.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""A small notes service."""
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Notes: add one, list them in the order they were added."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def open_store(url):
|
|
5
|
+
return {"url": url, "notes": []}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def add(store, text):
|
|
9
|
+
store["notes"].append(text)
|
|
10
|
+
return len(store["notes"])
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def list_notes(store):
|
|
14
|
+
return list(store["notes"])
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# FINAL_RESULT -- counter
|
|
2
|
+
|
|
3
|
+
## Phase 1 -- Counting
|
|
4
|
+
- A counter that adds one and reads its value back, and does nothing else
|
|
5
|
+
- The value survives a restart: it is written to a file and read back on start
|
|
6
|
+
|
|
7
|
+
## Phase 2 -- Command line
|
|
8
|
+
- Run with no argument the program prints the value, and with the word add it adds one
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# PROJECT_STATE -- counter
|
|
2
|
+
|
|
3
|
+
## Current phase
|
|
4
|
+
Phase 2 -- done
|
|
5
|
+
|
|
6
|
+
## Done
|
|
7
|
+
- app/counter.py -- the counter, saved to a file
|
|
8
|
+
- app/cli.py -- print the value, add one
|
|
9
|
+
|
|
10
|
+
## Structure notes
|
|
11
|
+
Flat layout: app/ is the package, standard library only.
|
|
12
|
+
|
|
13
|
+
## Next step
|
|
14
|
+
Nothing left in the goal.
|
|
15
|
+
|
|
16
|
+
## Protected rules
|
|
17
|
+
Standard library only.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""A counter."""
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""The counter: adds one, reads the value back, and keeps it in a file."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Counter:
|
|
7
|
+
"""Adds one and reads the value back; every change is saved."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, path):
|
|
10
|
+
self.path = Path(path)
|
|
11
|
+
self.value = load(self.path)
|
|
12
|
+
|
|
13
|
+
def increment(self):
|
|
14
|
+
self.value += 1
|
|
15
|
+
save(self.path, self.value)
|
|
16
|
+
return self.value
|
|
17
|
+
|
|
18
|
+
def read(self):
|
|
19
|
+
return self.value
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def load(path):
|
|
23
|
+
try:
|
|
24
|
+
return int(path.read_text(encoding="utf-8"))
|
|
25
|
+
except FileNotFoundError:
|
|
26
|
+
return 0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def save(path, value):
|
|
30
|
+
path.write_text(str(value), encoding="utf-8")
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# FINAL_RESULT -- invoice
|
|
2
|
+
|
|
3
|
+
## Phase 1 -- Amounts
|
|
4
|
+
- The total of an invoice is the sum of each line's price times its quantity, in cents
|
|
5
|
+
- An invoice renders as text, one line per item, the total last
|
|
6
|
+
|
|
7
|
+
## Phase 2 -- Docs
|
|
8
|
+
- The README shows an example invoice and its total
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# PROJECT_STATE -- invoice
|
|
2
|
+
|
|
3
|
+
## Current phase
|
|
4
|
+
Phase 1 -- not started
|
|
5
|
+
|
|
6
|
+
## Done
|
|
7
|
+
Nothing yet.
|
|
8
|
+
|
|
9
|
+
## Structure notes
|
|
10
|
+
Flat layout: app/ is the package, no dependencies.
|
|
11
|
+
|
|
12
|
+
## Next step
|
|
13
|
+
The invoice total, in cents.
|
|
14
|
+
|
|
15
|
+
## Protected rules
|
|
16
|
+
Amounts are integers in cents, never floats.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Invoices, in cents."""
|