cmd-queue 0.2.0__py3-none-any.whl → 0.2.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.
Potentially problematic release.
This version of cmd-queue might be problematic. Click here for more details.
- cmd_queue/__init__.py +1 -1
- cmd_queue/serial_queue.py +55 -59
- cmd_queue/slurm_queue.py +353 -44
- cmd_queue/slurmify.py +116 -0
- cmd_queue/tmux_queue.py +15 -2
- cmd_queue/util/util_bash.py +52 -0
- cmd_queue/util/util_tmux.py +76 -0
- {cmd_queue-0.2.0.dist-info → cmd_queue-0.2.2.dist-info}/METADATA +213 -175
- {cmd_queue-0.2.0.dist-info → cmd_queue-0.2.2.dist-info}/RECORD +13 -11
- {cmd_queue-0.2.0.dist-info → cmd_queue-0.2.2.dist-info}/WHEEL +1 -1
- {cmd_queue-0.2.0.dist-info → cmd_queue-0.2.2.dist-info}/LICENSE +0 -0
- {cmd_queue-0.2.0.dist-info → cmd_queue-0.2.2.dist-info}/entry_points.txt +0 -0
- {cmd_queue-0.2.0.dist-info → cmd_queue-0.2.2.dist-info}/top_level.txt +0 -0
cmd_queue/__init__.py
CHANGED
cmd_queue/serial_queue.py
CHANGED
|
@@ -7,30 +7,7 @@ import ubelt as ub
|
|
|
7
7
|
import uuid
|
|
8
8
|
from cmd_queue import base_queue
|
|
9
9
|
from cmd_queue.util import util_tags
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def indent(text, prefix=' '):
|
|
13
|
-
r"""
|
|
14
|
-
Indents a block of text
|
|
15
|
-
|
|
16
|
-
Args:
|
|
17
|
-
text (str): text to indent
|
|
18
|
-
prefix (str, default = ' '): prefix to add to each line
|
|
19
|
-
|
|
20
|
-
Returns:
|
|
21
|
-
str: indented text
|
|
22
|
-
|
|
23
|
-
>>> from cmd_queue.serial_queue import * # NOQA
|
|
24
|
-
>>> text = ['aaaa', 'bb', 'cc\n dddd\n ef\n']
|
|
25
|
-
>>> text = indent(text)
|
|
26
|
-
>>> print(text)
|
|
27
|
-
>>> text = indent(text)
|
|
28
|
-
>>> print(text)
|
|
29
|
-
"""
|
|
30
|
-
if isinstance(text, (list, tuple)):
|
|
31
|
-
return indent('\n'.join(text), prefix)
|
|
32
|
-
else:
|
|
33
|
-
return prefix + text.replace('\n', '\n' + prefix)
|
|
10
|
+
from cmd_queue.util import util_bash
|
|
34
11
|
|
|
35
12
|
|
|
36
13
|
class BashJob(base_queue.Job):
|
|
@@ -115,6 +92,21 @@ class BashJob(base_queue.Job):
|
|
|
115
92
|
self.tags = util_tags.Tags.coerce(tags)
|
|
116
93
|
self.allow_indent = allow_indent
|
|
117
94
|
|
|
95
|
+
def _test_bash_syntax_errors(self):
|
|
96
|
+
"""
|
|
97
|
+
Check for bash syntax errors
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
>>> from cmd_queue.serial_queue import * # NOQA
|
|
101
|
+
>>> # Demo full boilerplate for a job with dependencies
|
|
102
|
+
>>> self = BashJob('basd syhi(', name='job1')
|
|
103
|
+
>>> import pytest
|
|
104
|
+
>>> with pytest.raises(SyntaxError):
|
|
105
|
+
>>> self._test_bash_syntax_errors()
|
|
106
|
+
"""
|
|
107
|
+
bash_text = self.finalize_text()
|
|
108
|
+
_check_bash_text_for_syntax_errors(bash_text)
|
|
109
|
+
|
|
118
110
|
def finalize_text(self, with_status=True, with_gaurds=True,
|
|
119
111
|
conditionals=None, **kwargs):
|
|
120
112
|
script = []
|
|
@@ -178,7 +170,8 @@ class BashJob(base_queue.Job):
|
|
|
178
170
|
json_fmt_parts += [
|
|
179
171
|
('logs', '"%s"', self.log_fpath),
|
|
180
172
|
]
|
|
181
|
-
dump_pre_status =
|
|
173
|
+
dump_pre_status = util_bash.bash_json_dump(json_fmt_parts,
|
|
174
|
+
self.stat_fpath)
|
|
182
175
|
script.append('# Mark job as running')
|
|
183
176
|
script.append(dump_pre_status)
|
|
184
177
|
|
|
@@ -247,7 +240,8 @@ class BashJob(base_queue.Job):
|
|
|
247
240
|
json_fmt_parts += [
|
|
248
241
|
('logs', '"%s"', self.log_fpath),
|
|
249
242
|
]
|
|
250
|
-
dump_post_status =
|
|
243
|
+
dump_post_status = util_bash.bash_json_dump(json_fmt_parts,
|
|
244
|
+
self.stat_fpath)
|
|
251
245
|
|
|
252
246
|
on_pass_part = indent(_job_conditionals['on_pass'])
|
|
253
247
|
on_fail_part = indent(_job_conditionals['on_fail'])
|
|
@@ -468,7 +462,8 @@ class SerialQueue(base_queue.Queue):
|
|
|
468
462
|
('name', '"%s"', self.name),
|
|
469
463
|
('rootid', '"%s"', self.rootid),
|
|
470
464
|
]
|
|
471
|
-
dump_code =
|
|
465
|
+
dump_code = util_bash.bash_json_dump(json_fmt_parts,
|
|
466
|
+
self.state_fpath)
|
|
472
467
|
script.append('# Update queue status')
|
|
473
468
|
script.append(dump_code)
|
|
474
469
|
# script.append('cat ' + str(self.state_fpath))
|
|
@@ -575,6 +570,10 @@ class SerialQueue(base_queue.Queue):
|
|
|
575
570
|
r"""
|
|
576
571
|
Print info about the commands, optionally with rich
|
|
577
572
|
|
|
573
|
+
Args:
|
|
574
|
+
*args: see :func:`cmd_queue.base_queue.Queue.print_commands`.
|
|
575
|
+
**kwargs: see :func:`cmd_queue.base_queue.Queue.print_commands`.
|
|
576
|
+
|
|
578
577
|
CommandLine:
|
|
579
578
|
xdoctest -m cmd_queue.serial_queue SerialQueue.print_commands
|
|
580
579
|
|
|
@@ -675,41 +674,38 @@ class SerialQueue(base_queue.Queue):
|
|
|
675
674
|
return state
|
|
676
675
|
|
|
677
676
|
|
|
678
|
-
def
|
|
679
|
-
"""
|
|
680
|
-
|
|
681
|
-
bash environment.
|
|
677
|
+
def indent(text, prefix=' '):
|
|
678
|
+
r"""
|
|
679
|
+
Indents a block of text
|
|
682
680
|
|
|
683
681
|
Args:
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
printf code.
|
|
687
|
-
|
|
688
|
-
fpath (str): where bash should write the json file
|
|
682
|
+
text (str): text to indent
|
|
683
|
+
prefix (str, default = ' '): prefix to add to each line
|
|
689
684
|
|
|
690
685
|
Returns:
|
|
691
|
-
str
|
|
686
|
+
str: indented text
|
|
692
687
|
|
|
693
|
-
|
|
694
|
-
>>>
|
|
695
|
-
>>>
|
|
696
|
-
>>>
|
|
697
|
-
>>>
|
|
698
|
-
>>>
|
|
699
|
-
>>> ]
|
|
700
|
-
>>> fpath = 'out.json'
|
|
701
|
-
>>> dump_code = _bash_json_dump(json_fmt_parts, fpath)
|
|
702
|
-
>>> print(dump_code)
|
|
688
|
+
>>> from cmd_queue.serial_queue import * # NOQA
|
|
689
|
+
>>> text = ['aaaa', 'bb', 'cc\n dddd\n ef\n']
|
|
690
|
+
>>> text = indent(text)
|
|
691
|
+
>>> print(text)
|
|
692
|
+
>>> text = indent(text)
|
|
693
|
+
>>> print(text)
|
|
703
694
|
"""
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
695
|
+
if isinstance(text, (list, tuple)):
|
|
696
|
+
return indent('\n'.join(text), prefix)
|
|
697
|
+
else:
|
|
698
|
+
return prefix + text.replace('\n', '\n' + prefix)
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
def _check_bash_text_for_syntax_errors(bash_text):
|
|
702
|
+
import tempfile
|
|
703
|
+
tmpdir = tempfile.TemporaryDirectory()
|
|
704
|
+
with tmpdir:
|
|
705
|
+
dpath = ub.Path(tmpdir.name)
|
|
706
|
+
fpath = dpath / 'job_text.sh'
|
|
707
|
+
fpath.write_text(bash_text)
|
|
708
|
+
info = ub.cmd(['bash', '-nv', fpath])
|
|
709
|
+
if info.returncode != 0:
|
|
710
|
+
print(info.stderr)
|
|
711
|
+
raise SyntaxError('bash syntax error')
|