-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·51 lines (38 loc) · 1.79 KB
/
run.py
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
#!/usr/bin/env python
"""The run script"""
import logging
import sys
from flywheel_gear_toolkit import GearToolkitContext
# This design with a separate main and parser module
# allows the gear to be publishable and the main interfaces
# to it can then be imported in another project which enables
# chaining multiple gears together.
from fw_gear_sitewide_snapshot.main import run
from fw_gear_sitewide_snapshot.parser import parse_config
# The run.py should be as minimal as possible.
# The gear is split up into 2 main components. The run.py file which is executed
# when the container runs. The run.py file then imports the rest of the gear as a
# module.
log = logging.getLogger(__name__)
def main(context: GearToolkitContext) -> None: # pragma: no cover
"""Parses gear config and run"""
# Call parse_config to extract the args, kwargs from the context
# (e.g. config.json).
project_filter, batch_name, retry_failed, api_key, output_file_path = parse_config(
context
)
# Pass the args, kwargs to fw_gear_skeleton.main.run function to execute
# the main functionality of the gear.
e_code = run(api_key, project_filter, batch_name, output_file_path, retry_failed)
# Exit the python script (and thus the container) with the exit
# code returned by example_gear.main.run function.
sys.exit(e_code)
# Only execute if file is run as main, not when imported by another module
if __name__ == "__main__": # pragma: no cover
# Get access to gear config, inputs, and sdk client if enabled.
with GearToolkitContext() as gear_context:
# Initialize logging, set logging level based on `debug` configuration
# key in gear config.
gear_context.init_logging()
# Pass the gear context into main function defined above.
main(gear_context)