You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/05/08 18:01:06 UTC

[GitHub] [airflow] bolkedebruin commented on a change in pull request #5254: [AIRFLOW-4473] Add papermill operator

bolkedebruin commented on a change in pull request #5254: [AIRFLOW-4473] Add papermill operator
URL: https://github.com/apache/airflow/pull/5254#discussion_r282181452
 
 

 ##########
 File path: airflow/operators/papermill_operator.py
 ##########
 @@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import papermill as pm
+
+from airflow.models import BaseOperator
+from airflow.lineage.datasets import DataSet
+from airflow.utils.decorators import apply_defaults
+
+
+class NoteBook(DataSet):
+    type_name = "jupyter_notebook"
+    attributes = ['location', 'parameters']
+
+
+class PapermillOperator(BaseOperator):
+    """
+    Executes a jupyter notebook through papermill that is annotated with parameters
+
+    :param input_nb: input notebook (can also be a NoteBook or a File inlet)
+    :type input_nb: str
+    :param output_nb: output notebook (can also be a NoteBook or File outlet)
+    :type output_nb: str
+    :param parameters: the notebook parameters to set
+    :type parameters: dict
+    """
+    @apply_defaults
+    def __init__(self, input_nb: str, output_nb: str, parameters: dict,
+                 *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+        self.inlets.append(NoteBook(qualified_name=input_nb,
+                                    location=input_nb,
+                                    parameters=parameters))
+        self.outlets.append(NoteBook(qualified_name=output_nb,
+                                     location=output_nb))
+
+    def execute(self, context):
+        for i in range(len(self.inlets)):
 
 Review comment:
   Inlets can be multiple actually and you are not required to set input/output. I’m a little in doubt how to tackle this without affecting parallelism of airflow.
   
   I should probably make Notebook derive from File and accept all File derivatives 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services