Skip to content

Commit

Permalink
SDK/DSL-compiler - Compile without temporary files (#172)
Browse files Browse the repository at this point in the history
This also avoids writing, closing and then reading again the same temporary file which is not always supported.
  • Loading branch information
Ark-kun authored and k8s-ci-robot committed Nov 10, 2018
1 parent b494e3d commit 43b2381
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sdk/python/kfp/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,12 @@ def compile(self, pipeline_func, package_path):
"""
workflow = self._compile(pipeline_func)
yaml.Dumper.ignore_aliases = lambda *args : True
with tempfile.NamedTemporaryFile() as tmp:
with open(tmp.name, 'w') as fd:
yaml.dump(workflow, fd, default_flow_style=False)
with tarfile.open(package_path, "w:gz") as tar:
tar.add(tmp.name, arcname="pipeline.yaml")
yaml_text = yaml.dump(workflow, default_flow_style=False)

from contextlib import closing
from io import BytesIO
with tarfile.open(package_path, "w:gz") as tar:
with closing(BytesIO(yaml_text.encode())) as yaml_file:
tarinfo = tarfile.TarInfo('pipeline.yaml')
tarinfo.size = len(yaml_file.getvalue())
tar.addfile(tarinfo, fileobj=yaml_file)

0 comments on commit 43b2381

Please sign in to comment.