Skip to content

Commit

Permalink
Added CLI Flag disable/enable spec inlining.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrapCodes committed Jun 24, 2021
1 parent e6ff622 commit 37d4f33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
6 changes: 3 additions & 3 deletions sdk/python/kfp_tekton/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ def compile(self,
Args:
pipeline_func: pipeline functions with @dsl.pipeline decorator.
package_path: the output workflow tar.gz file path. for example, "~/a.tar.gz"
type_check: whether to enable the type check or not, default: False.
type_check: whether to enable the type check or not, default: True.
pipeline_conf: PipelineConf instance. Can specify op transforms,
image pull secrets and other pipeline-level configuration options.
Overrides any configuration that may be set by the pipeline.
Expand Down Expand Up @@ -1330,11 +1330,11 @@ def _create_and_write_workflow(self,
pipeline_loop_crs, recursive_tasks_names)
if e:
pipeline_loop_crs[i]['spec']['pipelineSpec']['tasks'] = t
inlined_as_taskSpec.append(e)
inlined_as_taskSpec.extend(e)
# Step 2. inline pipeline_loop_crs in the workflow
workflow_tasks, e = TektonCompiler._inline_tasks(workflow['spec']['pipelineSpec']['tasks'],
pipeline_loop_crs, recursive_tasks_names)
inlined_as_taskSpec.append(e)
inlined_as_taskSpec.extend(e)
workflow['spec']['pipelineSpec']['tasks'] = workflow_tasks

TektonCompiler._write_workflow(workflow=workflow, package_path=package_path)
Expand Down
25 changes: 17 additions & 8 deletions sdk/python/kfp_tekton/compiler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import kfp.compiler.main as kfp_compiler_main
import argparse
import sys
import os
from . import TektonCompiler
import sys

import kfp.compiler.main as kfp_compiler_main
from kfp_tekton.compiler.pipeline_utils import TektonPipelineConf

from . import TektonCompiler
from .. import __version__


Expand All @@ -44,12 +46,15 @@ def parse_arguments():
parser.add_argument('--disable-type-check',
action='store_true',
help='disable the type check, default is enabled.')
parser.add_argument('--disable-task-inline',
action='store_true',
help='disable taskSpec inlining, default is enabled.')

args = parser.parse_args()
return args


def _compile_pipeline_function(pipeline_funcs, function_name, output_path, type_check):
def _compile_pipeline_function(pipeline_funcs, function_name, output_path, type_check, tekton_pipeline_conf=None):
if len(pipeline_funcs) == 0:
raise ValueError('A function with @dsl.pipeline decorator is required in the py file.')

Expand All @@ -65,16 +70,16 @@ def _compile_pipeline_function(pipeline_funcs, function_name, output_path, type_
else:
pipeline_func = pipeline_funcs[0]

TektonCompiler().compile(pipeline_func, output_path, type_check)
TektonCompiler().compile(pipeline_func, output_path, type_check, tekton_pipeline_conf=tekton_pipeline_conf)


def compile_pyfile(pyfile, function_name, output_path, type_check):
def compile_pyfile(pyfile, function_name, output_path, type_check, tekton_pipeline_conf=None):
sys.path.insert(0, os.path.dirname(pyfile))
try:
filename = os.path.basename(pyfile)
with kfp_compiler_main.PipelineCollectorContext() as pipeline_funcs:
__import__(os.path.splitext(filename)[0])
_compile_pipeline_function(pipeline_funcs, function_name, output_path, type_check)
_compile_pipeline_function(pipeline_funcs, function_name, output_path, type_check, tekton_pipeline_conf)
finally:
del sys.path[0]

Expand All @@ -86,7 +91,11 @@ def main():
(args.py is not None and args.package is not None)):
raise ValueError('Either --py or --package is needed but not both.')
if args.py:
compile_pyfile(args.py, args.function, args.output, not args.disable_type_check)
tekton_pipeline_conf = TektonPipelineConf()
tekton_pipeline_conf.set_tekton_inline_spec(True)
if args.disable_task_inline:
tekton_pipeline_conf.set_tekton_inline_spec(False)
compile_pyfile(args.py, args.function, args.output, not args.disable_type_check, tekton_pipeline_conf)
else:
if args.namespace is None:
raise ValueError('--namespace is required for compiling packages.')
Expand Down

0 comments on commit 37d4f33

Please sign in to comment.