Skip to content

Commit

Permalink
Use absolute form of export path when exporting pipelines (elyra-ai#690)
Browse files Browse the repository at this point in the history
Because the notebook server's current working directory
doesn't always match the notebook directory, paths relative
to the notebook directory are not valid relative to the current
working directory causing things like pipeline export to break. 

This change leverages the change made in elyra-ai#673 to compute
an absolute path for the export's output.

Fixes elyra-ai#689
  • Loading branch information
kevin-bates authored Jun 29, 2020
1 parent a6d3907 commit 0c5d414
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 9 additions & 0 deletions elyra/pipeline/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,12 @@ def process(self, pipeline) -> PipelineProcessorResponse:
@abstractmethod
def export(self, pipeline, pipeline_export_format, pipeline_export_path, overwrite):
raise NotImplementedError()

def get_absolute_path(self, path):
"""Checks if path is absolute or not. If not absolute, `path` is appended to `root_dir`. """

absolute_path = path
if not os.path.isabs(path):
absolute_path = os.path.join(self.root_dir, path)

return absolute_path
16 changes: 10 additions & 6 deletions elyra/pipeline/processor_kfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,24 @@ def export(self, pipeline, pipeline_export_format, pipeline_export_path, overwri

pipeline_name = pipeline.name

# Since pipeline_export_path may be relative to the notebook directory, ensure
# we're using its absolute form.
absolute_pipeline_export_path = self.get_absolute_path(pipeline_export_path)

runtime_configuration = self._get_runtime_configuration(pipeline.runtime_config)
api_endpoint = runtime_configuration.metadata['api_endpoint']

if os.path.exists(pipeline_export_path) and not overwrite:
raise ValueError("File " + pipeline_export_path + " already exists.")
if os.path.exists(absolute_pipeline_export_path) and not overwrite:
raise ValueError("File " + absolute_pipeline_export_path + " already exists.")

self.log.info('Creating pipeline definition as a .' + pipeline_export_format + ' file')
if pipeline_export_format != "py":
try:
pipeline_function = lambda: self._cc_pipeline(pipeline, pipeline_name) # nopep8
kfp.compiler.Compiler().compile(pipeline_function, pipeline_export_path)
kfp.compiler.Compiler().compile(pipeline_function, absolute_pipeline_export_path)
except Exception as ex:
raise RuntimeError('Error compiling pipeline {} for export at {}'.
format(pipeline_name, pipeline_export_path), str(ex)) from ex
format(pipeline_name, absolute_pipeline_export_path), str(ex)) from ex
else:
# Load template from installed elyra package
loader = PackageLoader('elyra', 'templates')
Expand All @@ -129,10 +133,10 @@ def export(self, pipeline, pipeline_export_format, pipeline_export_path, overwri
pipeline_description="Elyra Pipeline")

# Write to python file and fix formatting
with open(pipeline_export_path, "w") as fh:
with open(absolute_pipeline_export_path, "w") as fh:
fh.write(autopep8.fix_code(python_output))

return pipeline_export_path
return pipeline_export_path # Return the input value, not its absolute form

def _cc_pipeline(self, pipeline, pipeline_name):

Expand Down

0 comments on commit 0c5d414

Please sign in to comment.