-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdo
More file actions
executable file
·173 lines (142 loc) · 2.73 KB
/
Copy pathdo
File metadata and controls
executable file
·173 lines (142 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#! /bin/bash
set -euo pipefail;
rootDir() {
cd "$(dirname "${BASH_SOURCE[0]}")" && pwd;
}
hasPython() {
if command -v python >/dev/null 2>&1; then
export PATH="$(command -v python3 | xargs dirname):$PATH";
return 0;
fi
echo "Error: python not found in PATH" >&2;
exit 127;
}
tok() {
local file="${FILE:-.vscode/token.env}";
if [[ ! -f "$file" ]]; then
echo "Error: token file not found: $file" >&2;
exit 1;
fi
cat "$file";
}
build() {
hasPython;
local root;
root="$(rootDir)";
cd "$root";
rm -rf build dist qudit.egg-info;
black ./**/*.py;
python setup.py bdist_wheel sdist;
twine check dist/*;
}
deploy() {
hasPython;
local root;
root="$(rootDir)";
cd "$root";
local tokval;
tokval="$(tok)";
twine upload dist/* -u __token__ -p "$tokval";
rm -rf build dist qudit.egg-info;
}
test() {
hasPython;
local root;
root="$(rootDir)";
cd "$root";
python -m view.lint;
black qudit/**/*.py;
cd "$root/tests";
python circuit_V.py;
python gates.py;
python gd.py;
python ECC.py;
python algo.py;
python circuit_M.py;
python metrics.py;
python primitives.py;
python draw.py;
python channel.py;
python noise.py;
python qubo.py;
python states.py;
python entropy.py;
python tools_extra.py;
python cut.py;
}
bench() {
hasPython;
local root;
root="$(rootDir)";
cd "$root/bench";
conda run -n qudit python run.py "$@";
}
prof() {
hasPython;
local root;
root="$(rootDir)";
cd "$root/tests";
python -m cProfile -o program.prof bench_fast.py;
snakeviz program.prof;
}
head() {
hasPython;
local root;
root="$(rootDir)";
cd "$root";
python ./view/headers.py;
}
docs() {
local root;
root="$(rootDir)";
cd "$root";
local subcmd="${1:-}";
shift || true;
head;
case "$subcmd" in
dev)
npm run dev "$@"
;;
build)
npm run build "$@"
;;
*)
echo "Usage: ./do docs <dev|build> [args...]" >&2
exit 2
;;
esac
}
help() {
cat <<'EOF'
Usage: ./do <command> [args...]
Commands:
build Build sdist/wheel and run twine checks
deploy Upload dist/* to PyPI using token from .vscode/token.env
test Run test scripts in ./tests
bench Run benchmarks and emit JSON (--only circuit|noisy|gd, --out file)
prof Profile bench_fast.py and open snakeviz
headers Run python ./view/headers.py
docs Run docs via npm (subcommands: dev, build)
Examples:
./do build
./do test
./do head
./do docs dev
./do docs build
EOF
}
main() {
local cmd="${1:-help}"
shift || true
case "$cmd" in
build|deploy|test|bench|prof|head|docs|help)
"$cmd" "$@"
;;
*)
echo "Unknown command: $cmd" >&2
help
exit 2
;;
esac
}
main "$@"