Skip to content

Commit

Permalink
[dagstermill] render notebook in windows (#10862)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiedemaria committed Dec 5, 2022
1 parent d03a484 commit 1fda581
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import papermill
from dagstermill.compat import ExecutionError
from dagstermill.factory import get_papermill_parameters, replace_parameters
from dagstermill.factory import (
_clean_path_for_windows,
get_papermill_parameters,
replace_parameters,
)
from papermill.engines import papermill_engines
from papermill.iorw import load_notebook_node, write_ipynb

Expand Down Expand Up @@ -251,7 +255,8 @@ def iris_dataset():
"kind" not in op_tags,
"user-defined op tags contains the `kind` key, but the `kind` key is reserved for use by Dagster",
)
default_tags = {"notebook_path": notebook_path, "kind": "ipynb"}

default_tags = {"notebook_path": _clean_path_for_windows(notebook_path), "kind": "ipynb"}

return asset(
name=name,
Expand Down
9 changes: 8 additions & 1 deletion python_modules/libraries/dagstermill/dagstermill/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
from .translator import DagsterTranslator


def _clean_path_for_windows(notebook_path: str) -> str:
"""In windows, the notebook cant render in dagit unless the C: prefix is removed.
os.path.splitdrive will split the path into (drive, tail), so just return the tail
"""
return os.path.splitdrive(notebook_path)[1]


# https://github.com/nteract/papermill/blob/17d4bbb3960c30c263bca835e48baf34322a3530/papermill/parameterize.py
def _find_first_tagged_cell_index(nb, tag):
parameters_indices = []
Expand Down Expand Up @@ -401,7 +408,7 @@ def define_dagstermill_op(
"kind" not in tags,
"user-defined op tags contains the `kind` key, but the `kind` key is reserved for use by Dagster",
)
default_tags = {"notebook_path": notebook_path, "kind": "ipynb"}
default_tags = {"notebook_path": _clean_path_for_windows(notebook_path), "kind": "ipynb"}

return OpDefinition(
name=name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from pathlib import Path
from typing import Any, Optional, Sequence

from dagstermill.factory import _clean_path_for_windows

import dagster._check as check
from dagster import AssetKey, AssetMaterialization
from dagster._config import Field
Expand Down Expand Up @@ -50,7 +52,11 @@ def handle_output(self, context: OutputContext, obj: bytes):
with open(output_notebook_path, self.write_mode) as dest_file_obj:
dest_file_obj.write(obj)

metadata = {"Executed notebook": MetadataValue.notebook(output_notebook_path)}
metadata = {
"Executed notebook": MetadataValue.notebook(
_clean_path_for_windows(output_notebook_path)
)
}

if context.has_asset_key:
context.add_output_metadata(metadata)
Expand Down
2 changes: 1 addition & 1 deletion python_modules/libraries/dagstermill/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def get_version() -> str:
"packaging>=20.5",
"papermill>=1.0.0",
"scrapbook>=0.5.0",
"nbconvert",
],
extras_require={
"test": [
"matplotlib",
"nbconvert",
"scikit-learn>=0.19.0",
"tqdm<=4.48", # https://github.com/tqdm/tqdm/issues/1049
]
Expand Down

0 comments on commit 1fda581

Please sign in to comment.