Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions databricks_cli/sdk/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,19 +1013,19 @@ def list(self, path, headers=None):
return self.client.perform_query('GET', '/workspace/list', data=_data, headers=headers)

def import_workspace(
self, path, format=None, language=None, content=None, overwrite=None, headers=None
self, path, format=None, content=None, overwrite=None, headers=None, language=None
):
_data = {}
if path is not None:
_data['path'] = path
if format is not None:
_data['format'] = format
if language is not None:
_data['language'] = language
if content is not None:
_data['content'] = content
if overwrite is not None:
_data['overwrite'] = overwrite
if language is not None:
_data['language'] = language
return self.client.perform_query('POST', '/workspace/import', data=_data, headers=headers)

def export_workspace(self, path, format=None, direct_download=None, headers=None):
Expand Down
6 changes: 3 additions & 3 deletions databricks_cli/workspace/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ def list_objects(self, workspace_path, headers=None):
def mkdirs(self, workspace_path, headers=None):
self.client.mkdirs(workspace_path, headers=headers)

def import_workspace(self, source_path, target_path, language, fmt, is_overwrite, headers=None):
def import_workspace(self, source_path, target_path, fmt, is_overwrite, headers=None, language=None):
with open(source_path, 'rb') as f:
# import_workspace must take content that is typed str.
content = b64encode(f.read()).decode()
self.client.import_workspace(
target_path,
fmt,
language,
content,
is_overwrite,
headers=headers)
headers=headers,
language=language)

def export_workspace(self, source_path, target_path, fmt, is_overwrite, headers=None):
"""
Expand Down
8 changes: 4 additions & 4 deletions databricks_cli/workspace/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,23 @@ def mkdirs_cli(api_client, workspace_path):
short_help='Imports a file from local to the Databricks workspace.')
@click.argument('source_path')
@click.argument('target_path')
@click.option('--language', '-l', required=True, type=LanguageClickType(),
help=', '.join(WorkspaceLanguage.ALL))
@click.option('--format', '-f', default=WorkspaceFormat.SOURCE, type=FormatClickType())
@click.option('--overwrite', '-o', is_flag=True, default=False)
@click.option('--language', '-l', required=False, type=LanguageClickType(),
help=', '.join(WorkspaceLanguage.ALL))
@debug_option
@profile_option
@eat_exceptions
@provide_api_client
def import_workspace_cli(api_client, source_path, target_path, language, format, overwrite): # NOQA
def import_workspace_cli(api_client, source_path, target_path, format, overwrite, language): # NOQA
"""
Imports a file from local to the Databricks workspace.

The format is by default SOURCE. Possible formats are SOURCE, HTML, JUPYTER, and DBC. Each
format is documented at
https://docs.databricks.com/api/latest/workspace.html#notebookexportformat.
"""
WorkspaceApi(api_client).import_workspace(source_path, target_path, language, format, overwrite) # NOQA
WorkspaceApi(api_client).import_workspace(source_path, target_path, format, overwrite, language) # NOQA


@click.command(context_settings=CONTEXT_SETTINGS,
Expand Down
3 changes: 2 additions & 1 deletion databricks_cli/workspace/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ def convert(self, value, param, ctx):


class WorkspaceFormat(object):
AUTO = 'AUTO'
SOURCE = 'SOURCE'
HTML = 'HTML'
JUPYTER = 'JUPYTER'
DBC = 'DBC'
ALL = [SOURCE, HTML, JUPYTER, DBC]
ALL = [AUTO, SOURCE, HTML, JUPYTER, DBC]


class FormatClickType(ParamType):
Expand Down
11 changes: 6 additions & 5 deletions tests/workspace/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,16 @@ def test_import_workspace(self, workspace_api, tmpdir):
test_file_path = os.path.join(tmpdir.strpath, 'test')
with open(test_file_path, 'w') as f:
f.write('test')
workspace_api.import_workspace(test_file_path, TEST_WORKSPACE_PATH, TEST_LANGUAGE,
TEST_FMT, is_overwrite=False)
workspace_api.import_workspace(test_file_path, TEST_WORKSPACE_PATH,
TEST_FMT, is_overwrite=False, language=TEST_LANGUAGE)
import_workspace_mock = workspace_api.client.import_workspace
assert import_workspace_mock.call_count == 1
assert import_workspace_mock.call_args[0][0] == TEST_WORKSPACE_PATH
assert import_workspace_mock.call_args[0][1] == TEST_FMT
assert import_workspace_mock.call_args[0][2] == TEST_LANGUAGE
assert import_workspace_mock.call_args[0][3] == b64encode(b'test').decode()
assert import_workspace_mock.call_args[0][4] is False
assert import_workspace_mock.call_args[0][2] == b64encode(b'test').decode()
assert import_workspace_mock.call_args[0][3] is False
assert import_workspace_mock.call_args[1]['headers'] is None
assert import_workspace_mock.call_args[1]['language'] == TEST_LANGUAGE

def test_export_workspace(self, workspace_api, tmpdir):
test_file_path = os.path.join(tmpdir.strpath, 'test')
Expand Down