Skip to content

Commit

Permalink
Fixes #29 - ensure that code resource for notebook is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
jfischer committed Apr 14, 2019
1 parent 35ea5ea commit e2ab795
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dataworkspaces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Copyright 2018,2019 by MPI-SWS and Data-ken Research. Licensed under Apache 2.0. See LICENSE.txt.

__version__ = '1.0.0'
__version__ = '1.0.1'
10 changes: 9 additions & 1 deletion dataworkspaces/kits/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import sys

from dataworkspaces.lineage import LineageBuilder
from dataworkspaces.utils.lineage_utils import infer_script_path
from dataworkspaces.utils.lineage_utils import infer_script_path, ResourceRef


def _get_notebook_name() -> Optional[str]:
Expand Down Expand Up @@ -79,6 +79,14 @@ def is_notebook() -> bool:
return False # Probably standard Python interpreter or a script


def get_notebook_directory():
notebook_path = _get_notebook_name()
if notebook_path is not None:
return dirname(notebook_path)
else:
return curdir


class NotebookLineageBuilder(LineageBuilder):
"""Notebooks are the final step in a pipeline
(and potentially the only step). We customize
Expand Down
6 changes: 4 additions & 2 deletions dataworkspaces/kits/scikit_learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from os.path import join, abspath, expanduser

from dataworkspaces.lineage import LineageBuilder
from .jupyter import is_notebook, get_step_name_for_notebook
from .jupyter import is_notebook, get_step_name_for_notebook, get_notebook_directory


class Metrics:
Expand Down Expand Up @@ -206,7 +206,9 @@ def train_and_predict_with_cv(classifier_class:ClassifierMixin,
lb = LineageBuilder().with_parameters(lineage_params)\
.as_results_step(results_dir, run_description)\
.with_input_path(input_dir)
lb = lb.with_step_name(get_step_name_for_notebook()) if is_notebook()\
lb = lb.with_step_name(get_step_name_for_notebook())\
.with_code_path(get_notebook_directory()) \
if is_notebook() \
else lb.as_script_step()

with lb.eval() as lineage:
Expand Down
4 changes: 4 additions & 0 deletions dataworkspaces/lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ def with_no_inputs(self) -> 'LineageBuilder':
self.no_inputs = True
return self

def with_code_path(self, path:str) -> 'LineageBuilder':
self.code.append(path)
return self

def with_code_ref(self, ref:ResourceRef) -> 'LineageBuilder':
self.code.append(ref)
return self
Expand Down

0 comments on commit e2ab795

Please sign in to comment.