|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# Apache Software License 2.0 |
|
3
|
|
|
# |
|
4
|
|
|
# Copyright (c) 2018, Christophe Duong |
|
5
|
|
|
# |
|
6
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
# you may not use this file except in compliance with the License. |
|
8
|
|
|
# You may obtain a copy of the License at |
|
9
|
|
|
# |
|
10
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
# |
|
12
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
# See the License for the specific language governing permissions and |
|
16
|
|
|
# limitations under the License. |
|
17
|
|
|
""" |
|
18
|
|
|
API module of the AIscalator tool. |
|
19
|
|
|
|
|
20
|
|
|
This module presents the entrypoint to use from a python script. |
|
21
|
|
|
It is intended to be used like this, usually from an airflow DAG |
|
22
|
|
|
scripts defining an AIscalator task:: |
|
23
|
|
|
|
|
24
|
|
|
from aiscalator import api |
|
25
|
|
|
|
|
26
|
|
|
api.jupyter_run("path/to/config.conf", "step_name") |
|
27
|
|
|
|
|
28
|
|
|
""" |
|
29
|
|
|
from aiscalator.core.config import AiscalatorConfig |
|
30
|
|
|
from aiscalator.jupyter import command |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
def jupyter_run(config, notebook=None, |
|
34
|
|
|
prepare_only=False, |
|
35
|
|
|
param=None, |
|
36
|
|
|
param_raw=None): |
|
37
|
|
|
""" |
|
38
|
|
|
Executes the step in browserless mode using papermill |
|
39
|
|
|
|
|
40
|
|
|
Parameters |
|
41
|
|
|
---------- |
|
42
|
|
|
config : str |
|
43
|
|
|
path to the configuration file |
|
44
|
|
|
notebook : str |
|
45
|
|
|
name of node to run, if None, then run the first one |
|
46
|
|
|
parameters : list |
|
47
|
|
|
List of parameters and their values |
|
48
|
|
|
prepare_only : bool |
|
49
|
|
|
Indicates if papermill should replace the parameters of the |
|
50
|
|
|
notebook only or it should execute all the cells too |
|
51
|
|
|
|
|
52
|
|
|
Returns |
|
53
|
|
|
------- |
|
54
|
|
|
string |
|
55
|
|
|
the path to the output notebook resulting from the execution |
|
56
|
|
|
of this step |
|
57
|
|
|
""" |
|
58
|
|
|
# TODO implements parameters passing |
|
59
|
|
|
if notebook: |
|
60
|
|
|
app_config = AiscalatorConfig(config=config, |
|
61
|
|
|
step_selection=notebook) |
|
62
|
|
|
else: |
|
63
|
|
|
app_config = AiscalatorConfig(config=config) |
|
64
|
|
|
return command.jupyter_run(app_config, prepare_only=prepare_only, |
|
65
|
|
|
param=param, param_raw=param_raw) |
|
66
|
|
|
|