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

Commit 0d987db

Browse files
committed
bug fixes and tests fixes
1 parent 3535d4a commit 0d987db

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

paperspace/commands/jobs.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
import terminaltables
44
from click import style
55

6-
from paperspace import config, client
76
from paperspace.commands import common
87
from paperspace.exceptions import BadResponseError
98
from paperspace.utils import get_terminal_lines
10-
from paperspace.workspace import S3WorkspaceHandler, WorkspaceHandler
9+
from paperspace.workspace import WorkspaceHandler
1110

1211

1312
class JobsCommandBase(common.CommandBase):
@@ -137,7 +136,7 @@ def execute(self, json_):
137136
archive_basename = self._workspace_handler.archive_basename
138137
json_["workspaceFileName"] = archive_basename
139138
self.api.headers["Content-Type"] = "multipart/form-data"
140-
files = {"file": open(workspace_url, "rb")}
139+
files = self._get_files_dict(workspace_url)
141140
else:
142141
json_["workspaceFileName"] = workspace_url
143142

@@ -148,6 +147,11 @@ def execute(self, json_):
148147
"Job created",
149148
"Unknown error while creating job")
150149

150+
@staticmethod
151+
def _get_files_dict(workspace_url):
152+
files = {"file": open(workspace_url, "rb")}
153+
return files
154+
151155
@staticmethod
152156
def set_project(json_):
153157
project_id = json_.get("projectId", json_.get("projectHandle"))

paperspace/commands/run.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ def _clear_script_name(script_name, mode):
3232
return script_name
3333

3434
def _create_command(self, mode, script, python_version=None):
35+
command_parts = []
3536
executor = self._get_executor(mode, python_version)
37+
if executor:
38+
command_parts.append(executor)
39+
3640
script_name = self._clear_script_name(script[0], mode)
37-
command_parts = [executor, script_name]
41+
if script_name:
42+
command_parts.append(script_name)
43+
3844
script_params = ' '.join(script[1:])
3945
if script_params:
4046
command_parts.append(script_params)
47+
4148
command = ' '.join(command_parts)
4249
return command
4350

paperspace/workspace.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ def handle(self, input_data):
101101
ignore_files = input_data.get('ignore_files')
102102

103103
if workspace_url:
104-
return # nothing to do
104+
return workspace_url # nothing to do
105105

106106
# Should be removed as soon it won't be necessary by PS_API
107107
if workspace_path == 'none':
108-
return 'none'
108+
return workspace_path
109+
109110
if workspace_archive:
110111
archive_path = os.path.abspath(workspace_archive)
111112
else:
@@ -142,10 +143,10 @@ def __init__(self, experiments_api, logger=None):
142143
self.experiments_api = experiments_api
143144

144145
def handle(self, input_data):
145-
archive_path = super(S3WorkspaceHandler, self).handle(input_data)
146-
if archive_path in ['none', None]:
147-
return archive_path
148-
146+
workspace = super(S3WorkspaceHandler, self).handle(input_data)
147+
if not self.archive_path:
148+
return workspace
149+
archive_path = workspace
149150
file_name = os.path.basename(archive_path)
150151
project_handle = input_data['projectHandle']
151152

tests/functional/test_run.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ class TestRunCommand(object):
1515

1616
@mock.patch("paperspace.client.requests.post")
1717
@mock.patch("paperspace.workspace.WorkspaceHandler._zip_workspace")
18-
def test_run_simple_file_with_args(self, workspace_zip_patched, post_patched):
19-
workspace_zip_patched.return_value = '/dev/random'
18+
@mock.patch("paperspace.commands.jobs.CreateJobCommand._get_files_dict")
19+
def test_run_simple_file_with_args(self, get_files_patched, workspace_zip_patched, post_patched):
20+
get_files_patched.return_value = mock.MagicMock()
21+
workspace_zip_patched.return_value = '/foo/bar'
2022
post_patched.return_value = MockResponse(status_code=200)
2123

2224
runner = CliRunner()
@@ -28,7 +30,7 @@ def test_run_simple_file_with_args(self, workspace_zip_patched, post_patched):
2830
})
2931
post_patched.assert_called_with(self.url,
3032
params={'name': u'test', 'projectId': u'projectId',
31-
'workspaceFileName': 'random',
33+
'workspaceFileName': 'bar',
3234
'command': 'python2 myscript.py a b',
3335
'projectHandle': u'projectId',
3436
'container': u'paperspace/tensorflow-python'},
@@ -38,9 +40,7 @@ def test_run_simple_file_with_args(self, workspace_zip_patched, post_patched):
3840
json=None)
3941

4042
@mock.patch("paperspace.client.requests.post")
41-
@mock.patch("paperspace.workspace.WorkspaceHandler._zip_workspace")
42-
def test_run_python_command_with_args_and_no_workspace(self, workspace_zip_patched, post_patched):
43-
workspace_zip_patched.return_value = '/dev/random'
43+
def test_run_python_command_with_args_and_no_workspace(self, post_patched):
4444
post_patched.return_value = MockResponse(status_code=200)
4545

4646
runner = CliRunner()
@@ -59,3 +59,27 @@ def test_run_python_command_with_args_and_no_workspace(self, workspace_zip_patch
5959
files=None,
6060
headers=expected_headers,
6161
json=None)
62+
63+
@mock.patch("paperspace.client.requests.post")
64+
@mock.patch("paperspace.workspace.WorkspaceHandler._zip_workspace")
65+
def test_run_shell_command_with_args_with_s3_workspace(self, workspace_zip_patched, post_patched):
66+
workspace_zip_patched.return_value = '/foo/bar'
67+
post_patched.return_value = MockResponse(status_code=200)
68+
69+
runner = CliRunner()
70+
result = runner.invoke(cli.cli,
71+
[self.command_name] + self.common_commands + ["-s", "echo foo", "--workspaceUrl",
72+
"s3://bucket/object"])
73+
74+
expected_headers = self.headers.copy()
75+
post_patched.assert_called_with(self.url,
76+
params={'name': u'test', 'projectId': u'projectId',
77+
'workspaceFileName': 's3://bucket/object',
78+
'workspaceUrl': 's3://bucket/object',
79+
'command': 'echo foo',
80+
'projectHandle': u'projectId',
81+
'container': u'paperspace/tensorflow-python'},
82+
data=None,
83+
files=None,
84+
headers=expected_headers,
85+
json=None)

0 commit comments

Comments
 (0)