Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 681ad9f

Browse files
committed
merge and post-merge fixes
1 parent fcb5d4a commit 681ad9f

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

paperspace/commands/jobs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def execute(self, json_):
157157
if self._workspace_handler.archive_path:
158158
data = self._get_multipart_data(json_)
159159
else:
160-
data["workspaceFileName"] = workspace_url
160+
json_["workspaceFileName"] = workspace_url
161161

162162
self.logger.log("Creating job...")
163163
response = self.api.post(url, params=json_, data=data)
@@ -168,12 +168,16 @@ def execute(self, json_):
168168
def _get_multipart_data(self, json_):
169169
archive_basename = self._workspace_handler.archive_basename
170170
json_["workspaceFileName"] = archive_basename
171-
job_data = {'file': (archive_basename, open(self._workspace_handler.archive_path, 'rb'), 'text/plain')}
171+
job_data = self._get_files_dict(archive_basename)
172172
monitor = MultipartEncoder(job_data).get_monitor()
173173
self.api.headers["Content-Type"] = monitor.content_type
174174
data = monitor
175175
return data
176176

177+
def _get_files_dict(self, archive_basename):
178+
job_data = {'file': (archive_basename, open(self._workspace_handler.archive_path, 'rb'), 'text/plain')}
179+
return job_data
180+
177181
@staticmethod
178182
def set_project(json_):
179183
if json_.get("projectId"):

paperspace/workspace.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def callback(monitor):
3030
bar.finish()
3131
else:
3232
bar.update(monitor.bytes_read)
33+
3334
return callback
3435

3536

@@ -103,7 +104,7 @@ def handle(self, input_data):
103104
ignore_files = input_data.get('ignore_files')
104105

105106
if workspace_url:
106-
return # nothing to do
107+
return workspace_url # nothing to do
107108

108109
# Should be removed as soon it won't be necessary by PS_API
109110
if workspace_path == 'none':
@@ -112,7 +113,7 @@ def handle(self, input_data):
112113
archive_path = os.path.abspath(workspace_archive)
113114
else:
114115
self.logger.log('Archiving your working directory for upload as your experiment workspace...'
115-
'(See https://docs.paperspace.com/gradient/experiments/run-experiments for more information.)')
116+
'(See https://docs.paperspace.com/gradient/experiments/run-experiments for more information.)')
116117
archive_path = self._zip_workspace(workspace_path, ignore_files)
117118
self.archive_path = archive_path
118119
self.archive_basename = os.path.basename(archive_path)

tests/functional/test_jobs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ class TestJobsCreate(object):
407407
"machineType": u"testType",
408408
"command": u"testCommand",
409409
"workspaceUrl": u"some-workspace",
410+
"workspaceFileName": u"some-workspace",
410411
}
411412
FULL_OPTIONS_REQUEST = {
412413
"name": u"exp1",

tests/functional/test_run.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,32 @@ class TestRunCommand(object):
1717

1818
@mock.patch("paperspace.client.requests.post")
1919
@mock.patch("paperspace.workspace.WorkspaceHandler._zip_workspace")
20+
@mock.patch("paperspace.workspace.MultipartEncoder.get_monitor")
2021
@mock.patch("paperspace.commands.jobs.CreateJobCommand._get_files_dict")
21-
def test_run_simple_file_with_args(self, get_files_patched, workspace_zip_patched, post_patched):
22+
def test_run_simple_file_with_args(self, get_files_patched, get_moniror_patched, workspace_zip_patched, post_patched):
2223
get_files_patched.return_value = mock.MagicMock()
2324
workspace_zip_patched.return_value = '/foo/bar'
2425
post_patched.return_value = MockResponse(status_code=200)
2526

27+
mock_monitor = mock.MagicMock()
28+
mock_monitor.content_type = "mock/multipart"
29+
30+
get_moniror_patched.return_value = mock_monitor
31+
2632
runner = CliRunner()
2733
result = runner.invoke(cli.cli, [self.command_name] + self.common_commands + ["/myscript.py", "a", "b"])
2834

2935
expected_headers = self.headers.copy()
3036
expected_headers.update({
31-
'Content-Type': "multipart/form-data"
37+
'Content-Type': "mock/multipart"
3238
})
3339
post_patched.assert_called_with(self.url,
3440
params={'name': u'test', 'projectId': u'projectId',
3541
'workspaceFileName': 'bar',
3642
'command': 'python{} myscript.py a b'.format(str(sys.version_info[0])),
37-
'projectHandle': u'projectId',
3843
'container': u'paperspace/tensorflow-python'},
39-
data=None,
40-
files=mock.ANY,
44+
data=mock.ANY,
45+
files=None,
4146
headers=expected_headers,
4247
json=None)
4348

@@ -55,7 +60,6 @@ def test_run_python_command_with_args_and_no_workspace(self, post_patched):
5560
'workspaceFileName': 'none',
5661
'workspace': 'none',
5762
'command': 'python{} -c print(foo)'.format(str(sys.version_info[0])),
58-
'projectHandle': u'projectId',
5963
'container': u'paperspace/tensorflow-python'},
6064
data=None,
6165
files=None,
@@ -79,7 +83,6 @@ def test_run_shell_command_with_args_with_s3_workspace(self, workspace_zip_patch
7983
'workspaceFileName': 's3://bucket/object',
8084
'workspaceUrl': 's3://bucket/object',
8185
'command': 'echo foo',
82-
'projectHandle': u'projectId',
8386
'container': u'paperspace/tensorflow-python'},
8487
data=None,
8588
files=None,

0 commit comments

Comments
 (0)