darwin-shell 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.
- darwin_shell/__init__.py +34 -0
- darwin_shell/cli.py +140 -0
- darwin_shell/share/bootstrap.sh +74 -0
- darwin_shell/share/checkpoint.sh +437 -0
- darwin_shell/share/cli.sh +555 -0
- darwin_shell/share/core.sh +214 -0
- darwin_shell/share/datetime.sh +367 -0
- darwin_shell/share/env.sh +322 -0
- darwin_shell/share/file.sh +303 -0
- darwin_shell/share/i18n.sh +181 -0
- darwin_shell/share/json.sh +258 -0
- darwin_shell/share/locale/zh_CN.sh +456 -0
- darwin_shell/share/lock.sh +414 -0
- darwin_shell/share/log.sh +317 -0
- darwin_shell/share/notify.sh +576 -0
- darwin_shell/share/process.sh +394 -0
- darwin_shell/share/sched.sh +360 -0
- darwin_shell/share/stats.sh +540 -0
- darwin_shell/share/terminal.sh +226 -0
- darwin_shell-0.1.0.dist-info/METADATA +208 -0
- darwin_shell-0.1.0.dist-info/RECORD +25 -0
- darwin_shell-0.1.0.dist-info/WHEEL +5 -0
- darwin_shell-0.1.0.dist-info/entry_points.txt +2 -0
- darwin_shell-0.1.0.dist-info/licenses/LICENSE +21 -0
- darwin_shell-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# darwin-shell terminal: color policy, ANSI sequences and single-line output.
|
|
3
|
+
# It owns no timestamps, log levels or files; log.sh owns those. It also never
|
|
4
|
+
# exits on behalf of the caller.
|
|
5
|
+
|
|
6
|
+
# i18n is the only dependency and sits below this module. Load it before the
|
|
7
|
+
# guard so a failed dependency is retryable on the next source attempt.
|
|
8
|
+
if ! declare -F dsh::i18n::t >/dev/null 2>&1; then
|
|
9
|
+
if declare -F dsh::use >/dev/null 2>&1; then
|
|
10
|
+
dsh::use i18n || return $?
|
|
11
|
+
else
|
|
12
|
+
_dsh_private_terminal_self="${BASH_SOURCE[0]}"
|
|
13
|
+
source "${_dsh_private_terminal_self%/*}/i18n.sh" || return $?
|
|
14
|
+
unset _dsh_private_terminal_self
|
|
15
|
+
fi
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
if [[ -n "${_dsh_private_terminal_sourced:-}" ]]; then
|
|
19
|
+
return 0
|
|
20
|
+
fi
|
|
21
|
+
_dsh_private_terminal_sourced=1
|
|
22
|
+
readonly _dsh_private_terminal_sourced
|
|
23
|
+
|
|
24
|
+
# auto: respect NO_COLOR and TTY. always/never: explicit overrides, and per
|
|
25
|
+
# no-color.org an explicit preference may override NO_COLOR.
|
|
26
|
+
: "${DARWIN_SH_COLOR:=auto}"
|
|
27
|
+
|
|
28
|
+
_dsh_private_terminal_code=''
|
|
29
|
+
_dsh_private_terminal_invalid_color_warned=''
|
|
30
|
+
|
|
31
|
+
_dsh_private_terminal_usage_code() {
|
|
32
|
+
printf '%s' "${DSH_RC_USAGE:-2}"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_dsh_private_terminal_help() {
|
|
36
|
+
case "${1:-}" in
|
|
37
|
+
enabled)
|
|
38
|
+
dsh::i18n::t 'Usage: dsh::terminal::enabled [stdout|stderr]'
|
|
39
|
+
printf '\n'
|
|
40
|
+
dsh::i18n::t 'Return 0 when color is enabled for the given stream (default stderr).'
|
|
41
|
+
;;
|
|
42
|
+
code)
|
|
43
|
+
dsh::i18n::t 'Usage: dsh::terminal::code <name> [stdout|stderr]'
|
|
44
|
+
printf '\n'
|
|
45
|
+
dsh::i18n::t 'Print the ANSI sequence for <name>, or nothing when color is disabled.'
|
|
46
|
+
dsh::i18n::t 'Names: reset red green yellow cyan bold dim none.'
|
|
47
|
+
;;
|
|
48
|
+
line)
|
|
49
|
+
dsh::i18n::t 'Usage: dsh::terminal::line <stdout|stderr> <color|none> <text...>'
|
|
50
|
+
printf '\n'
|
|
51
|
+
dsh::i18n::t 'Write one diagnostic line to the chosen stream, styled when color is enabled.'
|
|
52
|
+
;;
|
|
53
|
+
info|warn|error)
|
|
54
|
+
dsh::i18n::t 'Usage: dsh::terminal::%1$s <text...>' "$1"
|
|
55
|
+
printf '\n'
|
|
56
|
+
dsh::i18n::t 'Write a styled diagnostic to stderr; never exits.'
|
|
57
|
+
;;
|
|
58
|
+
*)
|
|
59
|
+
dsh::i18n::t 'dsh::terminal: no help for %1$s' "${1:-<empty>}" >&2
|
|
60
|
+
return "$(_dsh_private_terminal_usage_code)"
|
|
61
|
+
;;
|
|
62
|
+
esac
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_dsh_private_terminal_valid_stream() {
|
|
66
|
+
[[ "${1:-}" == "stdout" || "${1:-}" == "stderr" ]]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
# Policy only: TTY is checked separately by dsh::terminal::enabled.
|
|
70
|
+
_dsh_private_terminal_policy_allows() {
|
|
71
|
+
case "${DARWIN_SH_COLOR:-auto}" in
|
|
72
|
+
always)
|
|
73
|
+
return 0
|
|
74
|
+
;;
|
|
75
|
+
never)
|
|
76
|
+
return 1
|
|
77
|
+
;;
|
|
78
|
+
auto|'')
|
|
79
|
+
[[ -n "${NO_COLOR:-}" ]] && return 1
|
|
80
|
+
return 0
|
|
81
|
+
;;
|
|
82
|
+
*)
|
|
83
|
+
if [[ -z "$_dsh_private_terminal_invalid_color_warned" ]]; then
|
|
84
|
+
_dsh_private_terminal_invalid_color_warned=1
|
|
85
|
+
dsh::i18n::t 'dsh::terminal: invalid DARWIN_SH_COLOR: %1$s; using auto' \
|
|
86
|
+
"${DARWIN_SH_COLOR}" >&2
|
|
87
|
+
fi
|
|
88
|
+
[[ -n "${NO_COLOR:-}" ]] && return 1
|
|
89
|
+
return 0
|
|
90
|
+
;;
|
|
91
|
+
esac
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# Set _dsh_private_terminal_code for one logical color name.
|
|
95
|
+
_dsh_private_terminal_raw_code() {
|
|
96
|
+
case "${1:-}" in
|
|
97
|
+
reset) _dsh_private_terminal_code=$'\033[0m' ;;
|
|
98
|
+
red) _dsh_private_terminal_code=$'\033[0;31m' ;;
|
|
99
|
+
green) _dsh_private_terminal_code=$'\033[0;32m' ;;
|
|
100
|
+
yellow) _dsh_private_terminal_code=$'\033[0;33m' ;;
|
|
101
|
+
cyan) _dsh_private_terminal_code=$'\033[0;36m' ;;
|
|
102
|
+
bold) _dsh_private_terminal_code=$'\033[1m' ;;
|
|
103
|
+
dim) _dsh_private_terminal_code=$'\033[2m' ;;
|
|
104
|
+
none) _dsh_private_terminal_code='' ;;
|
|
105
|
+
*) return 2 ;;
|
|
106
|
+
esac
|
|
107
|
+
return 0
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
# Assign prefix/suffix without a subshell, so warning state is preserved.
|
|
111
|
+
_dsh_private_terminal_codes() {
|
|
112
|
+
local stream="$1" color="$2" prefix_var="$3" suffix_var="$4"
|
|
113
|
+
printf -v "$prefix_var" '%s' ''
|
|
114
|
+
printf -v "$suffix_var" '%s' ''
|
|
115
|
+
# Validate the color even when color is disabled, so bad input is never
|
|
116
|
+
# silently accepted just because the current stream is a pipe.
|
|
117
|
+
_dsh_private_terminal_raw_code "$color" || return 2
|
|
118
|
+
if ! dsh::terminal::enabled "$stream"; then
|
|
119
|
+
return 0
|
|
120
|
+
fi
|
|
121
|
+
printf -v "$prefix_var" '%s' "$_dsh_private_terminal_code"
|
|
122
|
+
# "none" explicitly asks for no styling; do not emit a stray reset.
|
|
123
|
+
[[ "$color" == "none" ]] && return 0
|
|
124
|
+
_dsh_private_terminal_raw_code reset
|
|
125
|
+
printf -v "$suffix_var" '%s' "$_dsh_private_terminal_code"
|
|
126
|
+
return 0
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
# Public: probe whether color is active for a stream. No output.
|
|
130
|
+
dsh::terminal::enabled() {
|
|
131
|
+
if [[ "${1:-}" == "--help" ]]; then
|
|
132
|
+
_dsh_private_terminal_help enabled
|
|
133
|
+
return $?
|
|
134
|
+
fi
|
|
135
|
+
local stream="${1:-stderr}"
|
|
136
|
+
if ! _dsh_private_terminal_valid_stream "$stream"; then
|
|
137
|
+
dsh::i18n::t 'dsh::terminal: invalid stream: %1$s' "$stream" >&2
|
|
138
|
+
return "$(_dsh_private_terminal_usage_code)"
|
|
139
|
+
fi
|
|
140
|
+
_dsh_private_terminal_policy_allows || return 1
|
|
141
|
+
[[ "${DARWIN_SH_COLOR:-auto}" == "always" ]] && return 0
|
|
142
|
+
if [[ "$stream" == "stdout" ]]; then
|
|
143
|
+
[[ -t 1 ]]
|
|
144
|
+
else
|
|
145
|
+
[[ -t 2 ]]
|
|
146
|
+
fi
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
# Public: print one ANSI sequence, or nothing when color is inactive.
|
|
150
|
+
dsh::terminal::code() {
|
|
151
|
+
if [[ "${1:-}" == "--help" ]]; then
|
|
152
|
+
_dsh_private_terminal_help code
|
|
153
|
+
return $?
|
|
154
|
+
fi
|
|
155
|
+
if (( $# < 1 )); then
|
|
156
|
+
dsh::i18n::t 'dsh::terminal::code: name required' >&2
|
|
157
|
+
return "$(_dsh_private_terminal_usage_code)"
|
|
158
|
+
fi
|
|
159
|
+
local name="$1" stream="${2:-stderr}"
|
|
160
|
+
if ! _dsh_private_terminal_valid_stream "$stream"; then
|
|
161
|
+
dsh::i18n::t 'dsh::terminal: invalid stream: %1$s' "$stream" >&2
|
|
162
|
+
return "$(_dsh_private_terminal_usage_code)"
|
|
163
|
+
fi
|
|
164
|
+
if ! _dsh_private_terminal_raw_code "$name"; then
|
|
165
|
+
dsh::i18n::t 'dsh::terminal: invalid color: %1$s' "$name" >&2
|
|
166
|
+
return "$(_dsh_private_terminal_usage_code)"
|
|
167
|
+
fi
|
|
168
|
+
if dsh::terminal::enabled "$stream"; then
|
|
169
|
+
printf '%s' "$_dsh_private_terminal_code"
|
|
170
|
+
fi
|
|
171
|
+
return 0
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
# Public: write one styled diagnostic line. printf is used instead of echo -e
|
|
175
|
+
# so backslashes in caller data are never reinterpreted.
|
|
176
|
+
dsh::terminal::line() {
|
|
177
|
+
if [[ "${1:-}" == "--help" ]]; then
|
|
178
|
+
_dsh_private_terminal_help line
|
|
179
|
+
return $?
|
|
180
|
+
fi
|
|
181
|
+
if (( $# < 2 )); then
|
|
182
|
+
dsh::i18n::t 'dsh::terminal::line: stream and color required' >&2
|
|
183
|
+
return "$(_dsh_private_terminal_usage_code)"
|
|
184
|
+
fi
|
|
185
|
+
local stream="$1" color="$2" prefix suffix
|
|
186
|
+
shift 2
|
|
187
|
+
if ! _dsh_private_terminal_valid_stream "$stream"; then
|
|
188
|
+
dsh::i18n::t 'dsh::terminal: invalid stream: %1$s' "$stream" >&2
|
|
189
|
+
return "$(_dsh_private_terminal_usage_code)"
|
|
190
|
+
fi
|
|
191
|
+
if ! _dsh_private_terminal_codes "$stream" "$color" prefix suffix; then
|
|
192
|
+
dsh::i18n::t 'dsh::terminal: invalid color: %1$s' "$color" >&2
|
|
193
|
+
return "$(_dsh_private_terminal_usage_code)"
|
|
194
|
+
fi
|
|
195
|
+
if [[ "$stream" == "stdout" ]]; then
|
|
196
|
+
printf '%s%s%s\n' "$prefix" "$*" "$suffix"
|
|
197
|
+
else
|
|
198
|
+
printf '%s%s%s\n' "$prefix" "$*" "$suffix" >&2
|
|
199
|
+
fi
|
|
200
|
+
return 0
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
# Public: convenience wrappers. All diagnostics go to stderr by convention.
|
|
204
|
+
dsh::terminal::info() {
|
|
205
|
+
if [[ "${1:-}" == "--help" ]]; then
|
|
206
|
+
_dsh_private_terminal_help info
|
|
207
|
+
return $?
|
|
208
|
+
fi
|
|
209
|
+
dsh::terminal::line stderr green "$@"
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
dsh::terminal::warn() {
|
|
213
|
+
if [[ "${1:-}" == "--help" ]]; then
|
|
214
|
+
_dsh_private_terminal_help warn
|
|
215
|
+
return $?
|
|
216
|
+
fi
|
|
217
|
+
dsh::terminal::line stderr yellow "$@"
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
dsh::terminal::error() {
|
|
221
|
+
if [[ "${1:-}" == "--help" ]]; then
|
|
222
|
+
_dsh_private_terminal_help error
|
|
223
|
+
return $?
|
|
224
|
+
fi
|
|
225
|
+
dsh::terminal::line stderr red "$@"
|
|
226
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: darwin-shell
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reusable Bash mechanics: logging, locking, scheduling, checkpoints and notification plumbing
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Chinese Documentation, https://github.com/darwinalpha/darwin-shell/blob/main/README.cn.md
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Provides-Extra: test
|
|
11
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# darwin-shell
|
|
15
|
+
|
|
16
|
+
English · [简体中文](README.cn.md)
|
|
17
|
+
|
|
18
|
+
**Status: all 15 modules shipped, 177 contract tests passing.**
|
|
19
|
+
|
|
20
|
+
A reusable Bash 4+ function library extracted from the shell orchestration
|
|
21
|
+
layer of `darwin-fetch`. It owns mechanics — loading, errors, i18n, logging,
|
|
22
|
+
CLI parsing, files, JSON, dates, locks, processes, scheduling, checkpoints,
|
|
23
|
+
statistics and notifications — and deliberately knows nothing about business
|
|
24
|
+
domains such as data sources, instruments or trading calendars.
|
|
25
|
+
|
|
26
|
+
## Why this exists
|
|
27
|
+
|
|
28
|
+
`darwin-fetch` accumulated 11,681 lines of shell across 35 files. Three
|
|
29
|
+
schedulers implemented similar limit/failure semantics with different flag
|
|
30
|
+
names; three modules fought over the EXIT trap; a library sourced `set -e` and
|
|
31
|
+
`set -u` into every caller; commands were assembled as strings and executed
|
|
32
|
+
with `eval`. The extraction is worthwhile only if those problems are solved
|
|
33
|
+
rather than relocated.
|
|
34
|
+
|
|
35
|
+
The resulting rules are strict:
|
|
36
|
+
|
|
37
|
+
- the library never calls `exit`, installs a trap, or changes shell options;
|
|
38
|
+
- callers may use `set -euo pipefail` safely;
|
|
39
|
+
- public functions live in `dsh::<module>::<verb>`, private helpers in
|
|
40
|
+
`_dsh_private_<module>_<name>`, configuration in `DARWIN_SH_*`;
|
|
41
|
+
- messages are English msgids rendered through `i18n.sh`, with an optional
|
|
42
|
+
Chinese table and runtime language switching;
|
|
43
|
+
- external tools are resolved at call time and can be injected for tests.
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
### From a wheel or a source checkout
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
uv build
|
|
51
|
+
pip install dist/darwin_shell-0.1.0-py3-none-any.whl
|
|
52
|
+
darwin-sh doctor
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Bootstrap in a shell script
|
|
56
|
+
|
|
57
|
+
`darwin-sh init` prints a sourceable snippet; it does not modify rc files:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
eval "$(darwin-sh init)"
|
|
61
|
+
dsh::use i18n core log cli
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
To copy the modules into a stable directory outside the Python environment:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
eval "$(darwin-sh install --dir ~/.local/share/darwin-shell)"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`darwin-sh lib [module]` prints the library directory or one module path.
|
|
71
|
+
`darwin-sh version` prints the version. `darwin-sh doctor` checks bash, module
|
|
72
|
+
files and the locale table.
|
|
73
|
+
|
|
74
|
+
A repository checkout works without installation:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
export DARWIN_SH_LIB_DIR="$PWD/src/darwin_shell/share"
|
|
78
|
+
source "$DARWIN_SH_LIB_DIR/bootstrap.sh"
|
|
79
|
+
dsh::use core log
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Quick start
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
#!/usr/bin/env bash
|
|
86
|
+
set -euo pipefail
|
|
87
|
+
eval "$(darwin-sh init)"
|
|
88
|
+
|
|
89
|
+
dsh::use i18n core log cli
|
|
90
|
+
dsh::log::configure --name demo --stderr-only --level INFO
|
|
91
|
+
dsh::core::require_cmd bash
|
|
92
|
+
dsh::log::info 'darwin-shell is ready'
|
|
93
|
+
|
|
94
|
+
dsh::cli::spec demo
|
|
95
|
+
dsh::cli::value demo target --into TARGET --required --help 'Target path'
|
|
96
|
+
dsh::cli::run demo --target ./data
|
|
97
|
+
printf 'target=%s\n' "$TARGET"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`dsh::use` is idempotent and whitelist-based. Modules are never loaded by
|
|
101
|
+
implicit side effects, and sourcing them does not create files, directories,
|
|
102
|
+
traps or global counters.
|
|
103
|
+
|
|
104
|
+
## Module reference
|
|
105
|
+
|
|
106
|
+
| Module | Responsibility | Representative APIs |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| `bootstrap.sh` | locate the library and load modules | `dsh::use` |
|
|
109
|
+
| `i18n.sh` | msgid rendering, language detection, locale table | `t`, `set_lang`, `lang` |
|
|
110
|
+
| `core.sh` | exit codes, dependency checks, tool resolution, dry run | `fail`, `have_cmd`, `require_cmd`, `tool`, `warn_once`, `dry_run` |
|
|
111
|
+
| `env.sh` | dotenv parsing and export policy | `parse`, `load`, `get`, `has`, `require` |
|
|
112
|
+
| `terminal.sh` | colour policy and ANSI output | `enabled`, `code`, `line`, `info`, `warn`, `error` |
|
|
113
|
+
| `log.sh` | levels, formatted stderr and deferred file sink | `configure`, `level`, `file`, `debug`, `info`, `warn`, `error` |
|
|
114
|
+
| `cli.sh` | declarative option specs and parser | `spec`, `flag`, `value`, `optional_value`, `mutex`, `help`, `run`, `remaining_append` |
|
|
115
|
+
| `file.sh` | size, count, atomic write, temp dirs, stale cleanup | `size`, `count`, `is_empty`, `atomic_write`, `temp_dir`, `prune_stale` |
|
|
116
|
+
| `json.sh` | jq-backed reads, writes and atomic updates | `jq`, `valid`, `exists`, `get`, `get_raw`, `set` |
|
|
117
|
+
| `datetime.sh` | calendar validation, formatting, arithmetic, month range | `now`, `today`, `valid`, `compare`, `add`, `month_range` |
|
|
118
|
+
| `lock.sh` | inode locks with explicit fd lifecycle | `acquire`, `release`, `with_lock`, `prune_stale` |
|
|
119
|
+
| `process.sh` | timeout, bounded parallel tasks, process lifecycle | `parallel`, `run_timeout`, `spawn`, `alive`, `stop` |
|
|
120
|
+
| `sched.sh` | flat, grouped and nested scheduling | `run --mode ...` |
|
|
121
|
+
| `checkpoint.sh` | four-state markers with configurable layout | `configure`, `path`, `state`, `mark`, `read`, `clear` |
|
|
122
|
+
| `stats.sh` | counters, lists, messages, cross-process merge, JSON export | `init`, `record`, `result`, `flush`, `merge`, `dump_json` |
|
|
123
|
+
| `notify.sh` | data-driven rendering and pluggable transports | `configure`, `render`, `send`, `from_result`, `transport::register` |
|
|
124
|
+
|
|
125
|
+
Full function signatures are available with `dsh::<module>::<verb> --help`.
|
|
126
|
+
|
|
127
|
+
## Key contracts
|
|
128
|
+
|
|
129
|
+
### Errors and exit codes
|
|
130
|
+
|
|
131
|
+
`dsh::core::fail <code> <msgid> [args...]` writes to stderr and returns the
|
|
132
|
+
code without exiting. The shared table is:
|
|
133
|
+
|
|
134
|
+
| Code | Constant | Meaning |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| 0 | `DSH_RC_OK` | success |
|
|
137
|
+
| 1 | `DSH_RC_FAILURE` | generic failure |
|
|
138
|
+
| 2 | `DSH_RC_USAGE` | usage or validation error |
|
|
139
|
+
| 3 | `DSH_RC_TRANSIENT` | required tool unavailable |
|
|
140
|
+
| 4 | `DSH_RC_AUTH` | reserved |
|
|
141
|
+
| 5 | `DSH_RC_SKIP` | skipped work item |
|
|
142
|
+
| 6 | `DSH_RC_EXISTS` | target already exists |
|
|
143
|
+
| 7 | `DSH_RC_LOCK_BUSY` | lock held by another process |
|
|
144
|
+
| 124 | `DSH_RC_TIMEOUT` | timeout expired |
|
|
145
|
+
| 130 | `DSH_RC_INTERRUPT` | interrupted |
|
|
146
|
+
|
|
147
|
+
### Dependency injection
|
|
148
|
+
|
|
149
|
+
Logical tool names are resolved through `dsh::core::tool`. Override them with
|
|
150
|
+
`DARWIN_SH_TOOL_JQ`, `DARWIN_SH_TOOL_FLOCK`, `DARWIN_SH_TOOL_TIMEOUT`, etc.
|
|
151
|
+
Missing tools are explicit failures, never silent degradation.
|
|
152
|
+
|
|
153
|
+
Time and environment are injectable too: `DARWIN_SH_NOW` freezes the clock,
|
|
154
|
+
`DARWIN_SH_TZ` scopes a timezone to one child process, `DARWIN_SH_TMPDIR`
|
|
155
|
+
selects the temp root, and `DARWIN_SH_LANG` selects the language.
|
|
156
|
+
|
|
157
|
+
### State ownership
|
|
158
|
+
|
|
159
|
+
Modules keep state in private associative arrays. `stats::init` and
|
|
160
|
+
`checkpoint::configure` must be called explicitly; nothing is initialised at
|
|
161
|
+
source time. Results are handed back via `--into VAR` namerefs instead of global
|
|
162
|
+
counters or stdout side effects.
|
|
163
|
+
|
|
164
|
+
### Boundaries deliberately kept out
|
|
165
|
+
|
|
166
|
+
- business rc-to-status mapping, `retry_count`, trading calendars;
|
|
167
|
+
- grouped/nested business orchestration beyond `sched.sh`'s generic modes;
|
|
168
|
+
- hard-coded webhook clients — callers register transports in `notify.sh`;
|
|
169
|
+
- a compatibility shim for the original `darwin-fetch` function names;
|
|
170
|
+
- `set -euo pipefail`, traps and `exit` inside library files.
|
|
171
|
+
|
|
172
|
+
## Examples
|
|
173
|
+
|
|
174
|
+
See [examples/README.md](examples/README.md) for seven independent runnable
|
|
175
|
+
scripts, expected output, prerequisites and troubleshooting. They cover
|
|
176
|
+
bootstrap, dotenv + CLI, files + JSON, dates + locks, scheduling, checkpoints +
|
|
177
|
+
stats, and a webhook-shaped notification transport with no network access.
|
|
178
|
+
|
|
179
|
+
## Tests and verification
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
uv run pytest -q # 177 contract tests
|
|
183
|
+
uv run darwin-sh doctor
|
|
184
|
+
for f in examples/*.sh; do bash "$f" || exit 1; done
|
|
185
|
+
uv build
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Tests are fast and independent. Where a host lacks jq or flock, shell stubs
|
|
189
|
+
verify the library's calling contract (argv, exit codes, data flow) rather than
|
|
190
|
+
the external binary itself. BSD `date` branches and a real WeCom webhook are
|
|
191
|
+
best covered in CI on the respective platforms.
|
|
192
|
+
|
|
193
|
+
All shipped text files are UTF-8 with LF line endings; `.gitattributes` and
|
|
194
|
+
`.editorconfig` enforce this, and the test suite checks for CRLF regressions.
|
|
195
|
+
|
|
196
|
+
## Documents
|
|
197
|
+
|
|
198
|
+
- [Design](docs/design.md) — boundaries, API decisions, packaging and migration.
|
|
199
|
+
- [Shell code walkthrough](docs/shell-code-walkthrough.md) — evidence from the
|
|
200
|
+
original code and the twelve issues that must not be copied.
|
|
201
|
+
- [Examples](examples/README.md) — runnable usage guide.
|
|
202
|
+
|
|
203
|
+
Both design and walkthrough documents have Chinese counterparts linked from
|
|
204
|
+
their first line.
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
MIT.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
darwin_shell/__init__.py,sha256=JzX_mp7KcqBX8SIYaJhnAIeVz8eK61D00XGhM2wOUvY,633
|
|
2
|
+
darwin_shell/cli.py,sha256=NOjvqdbz5EEXR-6GvIaGJDBgGWTuc_WfbNIWg4lk0-4,4875
|
|
3
|
+
darwin_shell/share/bootstrap.sh,sha256=LJcVl42q_8fk_q3SeR3eVnElEYcRu6H7rNWE-6Pbf_o,2366
|
|
4
|
+
darwin_shell/share/checkpoint.sh,sha256=0JafUP4Ppq7t5APvZQIZYuvU1S5_sd4WhWr5mpzwA2c,13769
|
|
5
|
+
darwin_shell/share/cli.sh,sha256=K_mDq75MD2f7O7FbtGNX-yc_N-c9D-uScWRj0ZXhP_4,16808
|
|
6
|
+
darwin_shell/share/core.sh,sha256=8VPH9dHve4TFrpXTBtmNSMHJh7MfgSY2bxDQ_xArPY4,6472
|
|
7
|
+
darwin_shell/share/datetime.sh,sha256=7v1Ow3ltB9c767CC37b0nFEZckThJPO35gYK3Dxz5WE,11620
|
|
8
|
+
darwin_shell/share/env.sh,sha256=OSx66wDl3o3dAuB-7GZpk-Ks2wQ4e2M_ovRR44XA0U0,9476
|
|
9
|
+
darwin_shell/share/file.sh,sha256=bPP5ypEB8oyIpS-Q9CVs20gtMFapYXUNGtLYJ_W0lU0,9821
|
|
10
|
+
darwin_shell/share/i18n.sh,sha256=AUcxG6ULlYzcIL6fYwHbCXXNl7HpnQcnGuvw2159fEA,5083
|
|
11
|
+
darwin_shell/share/json.sh,sha256=pI9MVn3XT_z_mrco8AnJYkNk8X4rgVVrJf12qkOJ4xw,7967
|
|
12
|
+
darwin_shell/share/lock.sh,sha256=V3L8xTnATGnXbTmA1Bv8B16HnEqTiv-Shk4z1C45mag,12635
|
|
13
|
+
darwin_shell/share/log.sh,sha256=sAnj4-WPGz4G1YRCBCzr9WUtM-kdOW3SBO7uBZw9b70,8906
|
|
14
|
+
darwin_shell/share/notify.sh,sha256=vIhnueajjMO9e931p_pamwnM0fQaDQ1h-Zv4xheyZ3k,18776
|
|
15
|
+
darwin_shell/share/process.sh,sha256=UZ7GiIuck1ipj8N1lZBkCUgUpE68W_gALYzGLGquhSM,12759
|
|
16
|
+
darwin_shell/share/sched.sh,sha256=BsoEQ4bwolqHZr9-THC6-_pCXmdSsJM13H_kGXGMY8c,14415
|
|
17
|
+
darwin_shell/share/stats.sh,sha256=LWEDq3zGZUyxn8NiGxhzd88ACq8C6cJF7iFS-dQtaGA,16307
|
|
18
|
+
darwin_shell/share/terminal.sh,sha256=cKqabPHJ07FUQWheDOqJQf6QuSJve4t-q5oh3DBBQoU,7232
|
|
19
|
+
darwin_shell/share/locale/zh_CN.sh,sha256=xwkETd8Y4vMh-mLYdku38kL8ZDokWjOpFtn-qc8prGM,44017
|
|
20
|
+
darwin_shell-0.1.0.dist-info/licenses/LICENSE,sha256=Jv2rYe7HuP4ueMkCFHFFWd9J4Cp6zKPZAi9VQWomW74,1068
|
|
21
|
+
darwin_shell-0.1.0.dist-info/METADATA,sha256=0g2jMF97Ek3xBShboZSpQBzS2DLsBAtEVVm510eo9IE,8414
|
|
22
|
+
darwin_shell-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
23
|
+
darwin_shell-0.1.0.dist-info/entry_points.txt,sha256=zXPI-Z4f3lPs029p6Hr8uOLbSGPkDhK7V0Zyp8ilwEs,52
|
|
24
|
+
darwin_shell-0.1.0.dist-info/top_level.txt,sha256=_rSGf8CVLOIQFsPdTJ8qruqKquWn-7trUOJjLU58sks,13
|
|
25
|
+
darwin_shell-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 darwinalpha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
darwin_shell
|