Skip to content

Commit

Permalink
add support for %sh cells
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvergnaud committed Apr 15, 2024
1 parent 7fc8533 commit 62b5ba7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/databricks/labs/ucx/source_code/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,29 @@ def migrate_notebook_path(self):
pass


class ShellCell(Cell):

@property
def language(self):
return CellLanguage.SHELL

def is_runnable(self) -> bool:
return True # TODO

Check warning on line 177 in src/databricks/labs/ucx/source_code/notebook.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/source_code/notebook.py#L177

Added line #L177 was not covered by tests

def build_dependency_graph(self, parent: DependencyGraph):
pass # nothing to do

Check warning on line 180 in src/databricks/labs/ucx/source_code/notebook.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/source_code/notebook.py#L180

Added line #L180 was not covered by tests

def migrate_notebook_path(self):
pass

Check warning on line 183 in src/databricks/labs/ucx/source_code/notebook.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/source_code/notebook.py#L183

Added line #L183 was not covered by tests


class CellLanguage(Enum):
# long magic_names must come first to avoid shorter ones being matched
PYTHON = Language.PYTHON, 'python', '#', True, PythonCell
SCALA = Language.SCALA, 'scala', '//', True, ScalaCell
SQL = Language.SQL, 'sql', '--', True, SQLCell
RUN = None, 'run', '', False, RunCell
SHELL = None, 'sh', '', False, ShellCell
# see https://spec.commonmark.org/0.31.2/#html-comment
MARKDOWN = None, 'md', "<!--->", False, MarkdownCell
R = Language.R, 'r', '#', True, RCell
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Databricks notebook source
import datetime

# COMMAND ----------

# MAGIC %sh "./shell-script.sh"
6 changes: 6 additions & 0 deletions tests/unit/source_code/test_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
Language.SQL,
['md', 'sql', 'sql', 'md', 'sql', 'python', 'sql', 'sql', 'sql', 'md', 'sql', 'sql', 'md', 'sql', 'sql', 'md', 'sql'],
)
SHELL_NOTEBOOK_SAMPLE = (
"notebook-with-shell-cell.py.txt",
Language.PYTHON,
['python', 'sh'],
)
# fmt: on


Expand All @@ -52,6 +57,7 @@
SCALA_NOTEBOOK_SAMPLE,
R_NOTEBOOK_SAMPLE,
SQL_NOTEBOOK_SAMPLE,
SHELL_NOTEBOOK_SAMPLE,
],
)
def test_notebook_splits_source_into_cells(source: tuple[str, Language, list[str]]):
Expand Down

0 comments on commit 62b5ba7

Please sign in to comment.