-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.py
More file actions
727 lines (610 loc) · 27 KB
/
scripts.py
File metadata and controls
727 lines (610 loc) · 27 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
from __future__ import annotations
import os
import textwrap
from typing import TYPE_CHECKING, Any
from anyio import Path
from sqlalchemy.ext.asyncio import async_scoped_session
from ..common.bash import write_bash_script
from ..common.butler import (
remove_collection_from_chain,
remove_datasets_from_collections,
remove_non_run_collections,
remove_run_collections,
)
from ..common.enums import LevelEnum, StatusEnum
from ..common.errors import CMBadExecutionMethodError, CMMissingScriptInputError, test_type_and_raise
from ..common.logging import LOGGER
from ..config import config
from ..db.element import ElementMixin
from ..db.script import Script
from ..db.step import Step
from .script_handler import ScriptHandler
logger = LOGGER.bind(module=__name__)
class NullScriptHandler(ScriptHandler):
"""A no-op script, mostly for testing"""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
script_url = await self._set_script_files(session, script, config.bps.artifact_path)
butler_repo = data_dict["butler_repo"]
except KeyError as e:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {e}") from e
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
command = f"echo trivial {butler_repo} {output_coll}"
await write_bash_script(script_url, command, values=template_values)
await script.update_values(session, script_url=script_url, status=StatusEnum.prepared)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
_resolved_cols = await script.resolve_collections(session)
_data_dict = await script.data_dict(session)
class ChainCreateScriptHandler(ScriptHandler):
"""Write a script to chain together collections
This will take
`script.collections['inputs']`
and chain them into
`script.collections['output']`
"""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
input_colls = resolved_cols["inputs"]
script_url = await self._set_script_files(session, script, config.bps.artifact_path)
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
logger.exception()
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
command = f"{config.butler.butler_bin} collection-chain {butler_repo} {output_coll}"
# This is here out of paranoia.
# script.resolved_collections should convert the list to a string
if isinstance(input_colls, list): # pragma: no cover
for input_coll in input_colls:
command += f" {input_coll}"
else:
command += f" {input_colls}"
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
await write_bash_script(script_url, command, values=template_values)
await script.update_values(session, script_url=script_url, status=StatusEnum.prepared)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
await remove_run_collections(butler_repo, output_coll, fake_reset=fake_reset)
class ChainPrependScriptHandler(ScriptHandler):
"""Write a script to prepend a collection to a chain
This will take
`script.collections['input']`
and chain --prepend it into
`script.collections['output']`
"""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
input_coll = resolved_cols["input"]
script_url = await self._set_script_files(session, script, config.bps.artifact_path)
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
command = (
f"{config.butler.butler_bin} collection-chain "
f"{butler_repo} {output_coll} --mode prepend {input_coll}"
)
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
await write_bash_script(script_url, command, values=template_values)
await script.update_values(session, script_url=script_url, status=StatusEnum.prepared)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
input_coll = resolved_cols["input"]
output_coll = resolved_cols["output"]
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
await remove_collection_from_chain(butler_repo, input_coll, output_coll, fake_reset=fake_reset)
class ChainCollectScriptHandler(ScriptHandler):
"""Write a script to collect stuff from an `Element` after processing
This will create:
`script.collections['output']`
and collect all of the output collections at a given level to it
and then append
`script.collections['inputs']` to it
"""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
input_colls = resolved_cols["inputs"]
to_collect = data_dict["collect"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
collect_colls = []
if to_collect == "jobs":
jobs = await parent.get_jobs(session)
for job_ in jobs:
job_colls = await job_.resolve_collections(session)
collect_colls.append(job_colls["job_run"])
elif to_collect == "steps":
for step_ in await parent.children(session):
step_colls = await step_.resolve_collections(session)
collect_colls.append(step_colls["step_output"])
collect_colls.reverse()
else: # pragma: no cover
raise CMMissingScriptInputError(
"Must specify what to collect in ChainCollectScriptHandler, jobs or steps",
)
script_url = await self._set_script_files(session, script, config.bps.artifact_path)
butler_repo = data_dict["butler_repo"]
command = f"{config.butler.butler_bin} collection-chain {butler_repo} {output_coll}"
for collect_coll_ in collect_colls:
command += f" {collect_coll_}"
for input_coll_ in input_colls:
command += f" {input_coll_}"
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
await write_bash_script(script_url, command, values=template_values)
await script.update_values(session, script_url=script_url, status=StatusEnum.prepared)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
await remove_non_run_collections(butler_repo, output_coll, fake_reset=fake_reset)
class TagInputsScriptHandler(ScriptHandler):
"""Write a script to make a TAGGED collection of inputs
This will take
`script.collections['input']`
and make a TAGGED collection at
`script.collections['output']`
"""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
input_coll = resolved_cols["input"]
script_url = await self._set_script_files(session, script, config.bps.artifact_path)
butler_repo = data_dict["butler_repo"]
data_query = data_dict.get("data_query")
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
command = f"{config.butler.butler_bin} associate {butler_repo} {output_coll}"
command += f" --collections {input_coll}"
command += f' --where "{data_query}"' if data_query else ""
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
await write_bash_script(script_url, command, values=template_values)
await script.update_values(session, script_url=script_url, status=StatusEnum.prepared)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
await remove_non_run_collections(butler_repo, output_coll, fake_reset=fake_reset)
class TagCreateScriptHandler(ScriptHandler):
"""Make an empty TAGGED collection
This will make a TAGGED collection at
`script.collections['output']`
"""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
script_url = await self._set_script_files(session, script, config.bps.artifact_path)
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
command = f"{config.butler.butler_bin} associate {butler_repo} {output_coll}"
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
await write_bash_script(script_url, command, values=template_values)
await script.update_values(session, status=StatusEnum.prepared)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
await remove_non_run_collections(butler_repo, output_coll, fake_reset=fake_reset)
class TagAssociateScriptHandler(ScriptHandler):
"""Add datasets to a TAGGED collection
This will add datasets from
`script.collections['input']`
to
`script.collections['output']`
"""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
input_coll = resolved_cols["input"]
output_coll = resolved_cols["output"]
script_url = await self._set_script_files(session, script, config.bps.artifact_path)
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
command = f"{config.butler.butler_bin} associate {butler_repo} {output_coll}"
command += f" --collections {input_coll}"
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
await write_bash_script(script_url, command, values=template_values)
await script.update_values(session, script_url=script_url, status=StatusEnum.prepared)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
input_coll = resolved_cols["input"]
output_coll = resolved_cols["output"]
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
await remove_datasets_from_collections(butler_repo, input_coll, output_coll, fake_reset=fake_reset)
class PrepareStepScriptHandler(ScriptHandler):
"""Make the input collection for a step
This will create a chained collection
`script.collections["output"]`
by taking the output collections of all the prerequisite steps, or
`script.collections["campaign_input"]` if the step has no inputs
it will then append `script.collections["output"]` to the output collection
"""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
test_type_and_raise(parent, Step, "PrepareStepScriptHandler._write_script parent")
if TYPE_CHECKING:
assert isinstance(parent, Step)
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
script_url = await self._set_script_files(session, script, config.bps.artifact_path)
butler_repo = data_dict["butler_repo"]
output_coll = resolved_cols["output"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
prereq_colls: list[str] = []
all_prereqs = await parent.get_all_prereqs(session)
for prereq_step in all_prereqs:
prereq_step_colls = await prereq_step.resolve_collections(session)
prereq_colls.append(prereq_step_colls["step_public_output"])
if not prereq_colls:
prereq_colls.append(resolved_cols["global_inputs"])
command = f"{config.butler.butler_bin} collection-chain {butler_repo} {output_coll}"
for prereq_coll_ in prereq_colls:
command += f" {prereq_coll_}"
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
await write_bash_script(script_url, command, values=template_values)
await script.update_values(session, script_url=script_url, status=StatusEnum.prepared)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
await remove_non_run_collections(butler_repo, output_coll, fake_reset=fake_reset)
class ResourceUsageScriptHandler(ScriptHandler):
"""Write the script to compute resource usage metrics for a campaign."""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
prod_area = os.path.expandvars(config.bps.artifact_path)
script_url = await self._set_script_files(session, script, prod_area)
butler_repo = data_dict["butler_repo"]
usage_graph_url = os.path.expandvars(f"{prod_area}/{parent.fullname}/resource_usage.qgraph")
command = (
f"{config.bps.resource_usage_bin} {butler_repo} {usage_graph_url} "
f"{resolved_cols['campaign_output']} --output {resolved_cols['campaign_resource_usage']};"
f"{config.bps.pipetask_bin} run -b {butler_repo} -g {usage_graph_url} "
f"-o {resolved_cols['campaign_resource_usage']} --register-dataset-types -j {config.bps.n_jobs}"
)
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
await write_bash_script(script_url, command, values=template_values)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
"""When the script is reset or the campaign is deleted, cleanup
resource usage products."""
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
parent = await script.get_parent(session)
if parent.level != LevelEnum.campaign: # pragma: no cover
raise CMBadExecutionMethodError(f"Script parent is a {parent.level}, not a LevelEnum.campaign")
try:
resource_coll = resolved_cols["campaign_resource_usage"]
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
await remove_run_collections(butler_repo, resource_coll, fake_reset=fake_reset)
return await super()._purge_products(session, script, to_status, fake_reset=fake_reset)
class HipsMapsScriptHandler(ScriptHandler):
"""Write the script to make the HiPS maps for a campaign."""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
prod_area = os.path.expandvars(config.bps.artifact_path)
script_url = await self._set_script_files(session, script, prod_area)
butler_repo = data_dict["butler_repo"]
hips_maps_graph_url = os.path.expandvars(f"{prod_area}/{parent.fullname}/hips_maps.qgraph")
hips_pipeline_yaml = await Path(
os.path.expandvars("${CM_CONFIGS}") + data_dict["hips_pipeline_yaml_path"]
).resolve()
gen_hips_both_yaml = await Path(
os.path.expandvars("${CM_CONFIGS}") + data_dict["hips_pipeline_config_path"]
).resolve()
# Note: The pipetask command below features a `-j N` which requests
# N nodes to run. This will guarantee that the HIPS maps generate at
# a reasonable rate. However, when allocating nodes for HTCondor,
# the user should allocate at least 16 so that this can execute
# properly. Future effort should be devoted to getting a number like
# this out of a campaign data dict and managing it in cm-service.
command = f"""# First we get the output of the generated pixels and then format it so the output of
# the first command can be used as input to the next.
output=$({config.hips.high_res_bin} segment -b {butler_repo} \
-p {hips_pipeline_yaml} -i {resolved_cols["campaign_output"]} -o 1);
# Then, we take pixels from previous commands and use to build the hips maps graph.
pixels=$(echo '$output' | grep -Eo '[0-9]+' | tr '\\n' ' ');
{config.hips.high_res_bin} build -b {butler_repo} -p {hips_pipeline_yaml} \
-i {resolved_cols["campaign_output"]} --output {resolved_cols["campaign_hips_maps"]} \
--pixels $pixels -q {hips_maps_graph_url};
# Now we pipetask run the graph
{config.bps.pipetask_bin} --long-log --log-level=INFO run -j {config.bps.n_jobs} -b {butler_repo} \
--output {resolved_cols["campaign_hips_maps"]} --register-dataset-types -g {hips_maps_graph_url};
# Generate HIPS 9-level .png images
{config.bps.pipetask_bin} --long-log --log-level=INFO run -j {config.bps.n_jobs} -b {butler_repo} \
-i {resolved_cols["campaign_output"]} --output {resolved_cols["campaign_hips_maps"]} \
-p {gen_hips_both_yaml} -c 'generateHips:hips_base_uri=\
{config.hips.uri}/{resolved_cols["campaign_hips_maps"]}' \
-c 'generateColorHips:hips_base_uri={config.hips.uri}/{resolved_cols["campaign_hips_maps"]}' \
--register-dataset-types
"""
# Remove indentation from multiline string
command = textwrap.dedent(command)
# Remove additional whitespace
command = command.replace(8 * " ", "")
# Strip leading/trailing spaces just in case
command = "\n".join([line.strip() for line in command.splitlines()])
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
await write_bash_script(script_url, command, values=template_values)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
"""When the script is reset or the campaign is deleted, cleanup
hips maps products."""
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
parent = await script.get_parent(session)
if parent.level != LevelEnum.campaign: # pragma: no cover
raise CMBadExecutionMethodError(f"Script parent is a {parent.level}, not a LevelEnum.campaign")
try:
hips_maps_coll = resolved_cols["campaign_hips_maps"]
butler_repo = data_dict["butler_repo"]
except KeyError as msg: # pragma: no cover
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
if to_status.value < StatusEnum.running.value:
await remove_run_collections(butler_repo, hips_maps_coll, fake_reset=fake_reset)
return await super()._purge_products(session, script, to_status)
class ValidateScriptHandler(ScriptHandler):
"""Write a script to run validate after processing
This will create:
`parent.collections['validation']`
FIXME: what script do we actually run here?
"""
async def _write_script(
self,
session: async_scoped_session,
script: Script,
parent: ElementMixin,
**kwargs: Any,
) -> StatusEnum:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
input_coll = resolved_cols["input"]
output_coll = resolved_cols["output"]
script_url = await self._set_script_files(session, script, config.bps.artifact_path)
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
command = f"{config.bps.pipetask_bin} validate {butler_repo} {input_coll} {output_coll}"
template_values = {
"script_method": script.run_method.name,
**data_dict,
}
await write_bash_script(script_url, command, values=template_values)
await script.update_values(session, script_url=script_url, status=StatusEnum.prepared)
return StatusEnum.prepared
async def _purge_products(
self,
session: async_scoped_session,
script: Script,
to_status: StatusEnum,
*,
fake_reset: bool = False,
) -> None:
resolved_cols = await script.resolve_collections(session)
data_dict = await script.data_dict(session)
try:
output_coll = resolved_cols["output"]
butler_repo = data_dict["butler_repo"]
except KeyError as msg:
raise CMMissingScriptInputError(f"{script.fullname} missing an input: {msg}") from msg
await remove_run_collections(butler_repo, output_coll, fake_reset=fake_reset)