Skip to content

Commit 78c91f5

Browse files
authored
add dbc support to workspace api (#276)
1 parent f0d1003 commit 78c91f5

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

databricks_cli/workspace/types.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,27 @@ class WorkspaceLanguage(object):
3030
SQL = 'SQL'
3131
R = 'R'
3232
ALL = [SCALA, PYTHON, SQL, R]
33-
EXTENSIONS = ['.scala', '.py', '.sql', '.SQL', '.r', '.R', '.ipynb', '.html']
33+
EXTENSIONS = ['.scala', '.py', '.sql', '.SQL', '.r', '.R', '.ipynb', '.html', '.dbc']
3434

3535
@classmethod
3636
def to_language_and_format(cls, path):
3737
ext = cls.get_extension(path).lower()
38+
language_and_format = (None, None)
3839
if ext == '.scala':
39-
return (cls.SCALA, WorkspaceFormat.SOURCE)
40+
language_and_format = (cls.SCALA, WorkspaceFormat.SOURCE)
4041
elif ext == '.py':
41-
return (cls.PYTHON, WorkspaceFormat.SOURCE)
42+
language_and_format = (cls.PYTHON, WorkspaceFormat.SOURCE)
4243
elif ext == '.sql':
43-
return (cls.SQL, WorkspaceFormat.SOURCE)
44+
language_and_format = (cls.SQL, WorkspaceFormat.SOURCE)
4445
elif ext == '.r':
45-
return (cls.R, WorkspaceFormat.SOURCE)
46+
language_and_format = (cls.R, WorkspaceFormat.SOURCE)
4647
elif ext == '.ipynb':
47-
return (cls.PYTHON, WorkspaceFormat.JUPYTER)
48+
language_and_format = (cls.PYTHON, WorkspaceFormat.JUPYTER)
4849
elif ext == '.html':
49-
return (None, WorkspaceFormat.HTML)
50+
language_and_format = (None, WorkspaceFormat.HTML)
51+
elif ext == '.dbc':
52+
language_and_format = (None, WorkspaceFormat.DBC)
53+
return language_and_format
5054

5155
@classmethod
5256
def to_extension(cls, language):

tests/stack/test_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ def test_deploy_workspace(self, stack_api, tmpdir):
308308
stack_api._deploy_workspace(test_workspace_nb_properties, None, True)
309309
assert stack_api.workspace_client.import_workspace.call_args[0][0] == 'test/notebook.html'
310310

311+
# Test Input of Workspace notebook with dbc source
312+
test_workspace_nb_properties.update(
313+
{api.WORKSPACE_RESOURCE_SOURCE_PATH: 'test/notebook.dbc'})
314+
nb_databricks_id = \
315+
stack_api._deploy_workspace(test_workspace_nb_properties, None, True)
316+
assert stack_api.workspace_client.import_workspace.call_args[0][0] == 'test/notebook.dbc'
317+
311318
# Should raise error if resource object_type doesn't match actually is in filesystem.
312319
test_workspace_dir_properties.update(
313320
{api.WORKSPACE_RESOURCE_OBJECT_TYPE: workspace_api.NOTEBOOK})

0 commit comments

Comments
 (0)