oh-my-batch 0.4.0__py3-none-any.whl → 0.4.2__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.
- oh_my_batch/combo.py +29 -7
- {oh_my_batch-0.4.0.dist-info → oh_my_batch-0.4.2.dist-info}/METADATA +2 -3
- {oh_my_batch-0.4.0.dist-info → oh_my_batch-0.4.2.dist-info}/RECORD +6 -6
- {oh_my_batch-0.4.0.dist-info → oh_my_batch-0.4.2.dist-info}/WHEEL +1 -1
- {oh_my_batch-0.4.0.dist-info → oh_my_batch-0.4.2.dist-info}/LICENSE +0 -0
- {oh_my_batch-0.4.0.dist-info → oh_my_batch-0.4.2.dist-info}/entry_points.txt +0 -0
oh_my_batch/combo.py
CHANGED
@@ -4,7 +4,7 @@ import random
|
|
4
4
|
import json
|
5
5
|
import os
|
6
6
|
|
7
|
-
from .util import expand_globs, mode_translate, ensure_dir
|
7
|
+
from .util import expand_globs, mode_translate, ensure_dir, shell_run
|
8
8
|
|
9
9
|
class ComboMaker:
|
10
10
|
|
@@ -85,13 +85,13 @@ class ComboMaker:
|
|
85
85
|
self.add_var(key, *args)
|
86
86
|
return self
|
87
87
|
|
88
|
-
def
|
88
|
+
def add_file_set(self, key: str, *path: str, format=None,
|
89
89
|
sep=' ', abs=False, raise_invalid=False):
|
90
90
|
"""
|
91
91
|
Add a variable with files by glob pattern as one string
|
92
92
|
Unlike add_files, this function joins the files with a delimiter.
|
93
93
|
For example, suppose there are 1.txt, 2.txt, 3.txt in data directory,
|
94
|
-
then calling
|
94
|
+
then calling add_file_set('DATA_FILE', 'data/*.txt') will add string "data/1.txt data/2.txt data/3.txt"
|
95
95
|
to the variable DATA_FILE.
|
96
96
|
|
97
97
|
:param key: Variable name
|
@@ -144,7 +144,7 @@ class ComboMaker:
|
|
144
144
|
else:
|
145
145
|
raise ValueError(f"Variable {key} not found")
|
146
146
|
return self
|
147
|
-
|
147
|
+
|
148
148
|
def set_broadcast(self, *keys: str):
|
149
149
|
"""
|
150
150
|
Specify variables use broadcast strategy instead of cartesian product
|
@@ -215,6 +215,28 @@ class ComboMaker:
|
|
215
215
|
print(out)
|
216
216
|
return self
|
217
217
|
|
218
|
+
def run_cmd(self, cmd: str):
|
219
|
+
"""
|
220
|
+
Run command against each combo
|
221
|
+
|
222
|
+
For example,
|
223
|
+
|
224
|
+
run_cmd "cp {DATA_FIEL} ./path/to/workdir/{i}/data.txt"
|
225
|
+
|
226
|
+
will copy each file in DATA_FILE to ./path/to/workdir/{i}/data.txt
|
227
|
+
|
228
|
+
:param cmd: Command to run, can include format style variables, e.g. {i}, {i:03d}, {TEMP}
|
229
|
+
"""
|
230
|
+
combos = self._make_combos()
|
231
|
+
for i, combo in enumerate(combos):
|
232
|
+
_cmd = cmd.format(i=i, **combo)
|
233
|
+
cp = shell_run(_cmd)
|
234
|
+
if cp.returncode != 0:
|
235
|
+
print(cp.stdout.decode('utf-8'))
|
236
|
+
print(cp.stderr.decode('utf-8'))
|
237
|
+
raise RuntimeError(f"Failed to run command: {_cmd}")
|
238
|
+
return self
|
239
|
+
|
218
240
|
def done(self):
|
219
241
|
"""
|
220
242
|
End of command chain
|
@@ -224,13 +246,13 @@ class ComboMaker:
|
|
224
246
|
def _make_combos(self):
|
225
247
|
if not self._vars:
|
226
248
|
return self._combos
|
227
|
-
|
249
|
+
|
228
250
|
broadcast_vars = {}
|
229
|
-
|
251
|
+
|
230
252
|
for k in self._broadcast_keys:
|
231
253
|
broadcast_vars[k] = self._vars[k]
|
232
254
|
del self._vars[k]
|
233
|
-
|
255
|
+
|
234
256
|
keys = self._vars.keys()
|
235
257
|
values_list = product(*self._vars.values())
|
236
258
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: oh-my-batch
|
3
|
-
Version: 0.4.
|
3
|
+
Version: 0.4.2
|
4
4
|
Summary:
|
5
5
|
License: GPL
|
6
6
|
Author: weihong.xu
|
@@ -13,7 +13,6 @@ Classifier: Programming Language :: Python :: 3.9
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.10
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
16
|
-
Classifier: Programming Language :: Python :: 3.13
|
17
16
|
Requires-Dist: fire (>=0.7.0,<0.8.0)
|
18
17
|
Description-Content-Type: text/markdown
|
19
18
|
|
@@ -86,9 +85,9 @@ omb combo \
|
|
86
85
|
add_files DATA_FILE tmp/*.data - \
|
87
86
|
add_var TEMP 300 400 500 - \
|
88
87
|
add_randint RANDOM -n 3 -a 1 -b 1000 - \
|
88
|
+
set_broadcast RANDOM - \
|
89
89
|
make_files tmp/tasks/{i}-T-{TEMP}/in.lmp --template tmp/in.lmp.tmp - \
|
90
90
|
make_files tmp/tasks/{i}-T-{TEMP}/run.sh --template tmp/run.sh.tmp --mode 755 - \
|
91
|
-
set_broadcast RANDOM - \
|
92
91
|
done
|
93
92
|
```
|
94
93
|
|
@@ -4,12 +4,12 @@ oh_my_batch/assets/__init__.py,sha256=Exub46UbQaz2V2eXpQeiVfnThQpXaNeuyjlGY6gBSZ
|
|
4
4
|
oh_my_batch/assets/functions.sh,sha256=LaiavZBu84D7C1r-dWhf91vPTuHXCMV1DQZUIPVQnjE,1001
|
5
5
|
oh_my_batch/batch.py,sha256=6qnaXEVyA493heGzzbCrdZXCcnYk8zgl7WP0rmo7KlU,3690
|
6
6
|
oh_my_batch/cli.py,sha256=Jyz8q2pUYke3mfJS6F_G9S9hApddgXxQw1BsN6Kfkjc,553
|
7
|
-
oh_my_batch/combo.py,sha256=
|
7
|
+
oh_my_batch/combo.py,sha256=XK1t3rOQozf9oBYPr_CER7jhCMYpqJaZo0ke4ctK7t0,9307
|
8
8
|
oh_my_batch/job.py,sha256=Uk0E-WxnexBu9wuUV3uc1aAwVF_5rWdNdLEOB8Y9B-U,6252
|
9
9
|
oh_my_batch/misc.py,sha256=G_iOovRCrShBJJCc82QLN0CvMqW4adOefEoY1GedEiw,452
|
10
10
|
oh_my_batch/util.py,sha256=5ve2QcviuF0UHFLrsXmjMTj0ogXJ4g05q1y-yWCFuOk,2409
|
11
|
-
oh_my_batch-0.4.
|
12
|
-
oh_my_batch-0.4.
|
13
|
-
oh_my_batch-0.4.
|
14
|
-
oh_my_batch-0.4.
|
15
|
-
oh_my_batch-0.4.
|
11
|
+
oh_my_batch-0.4.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
12
|
+
oh_my_batch-0.4.2.dist-info/METADATA,sha256=VrGmQGhqGB3RGqy8E5sxS4o288Ddd-uNqjTKnZmtAts,5509
|
13
|
+
oh_my_batch-0.4.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
14
|
+
oh_my_batch-0.4.2.dist-info/entry_points.txt,sha256=ZY2GutSoNjjSyJ4qO2pTeseKUFgoTYdvmgkuZZkwi68,77
|
15
|
+
oh_my_batch-0.4.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|