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

Commit db17d63

Browse files
committed
tests fixed and expanded
exceptions renamed
1 parent e34a8ad commit db17d63

File tree

12 files changed

+350
-116
lines changed

12 files changed

+350
-116
lines changed

Pipfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ verify_ssl = true
66
[packages]
77
e1839a8 = {path = ".",editable = true}
88
requests = {extras = ["security"]}
9-
requests-toolbelt = *
10-
progressbar2 = *
9+
requests-toolbelt = "*"
10+
progressbar2 = "*"
1111
cryptography = {extras = ["security"]}
1212
"boto3" = "*"
1313
botocore = "*"

Pipfile.lock

Lines changed: 65 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

paperspace/cli/jobs.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from paperspace import client, config
44
from paperspace.cli import common
5+
from paperspace.cli.cli_types import json_string
56
from paperspace.cli.common import del_if_value_is_none
67
from paperspace.cli.cli import cli
78
from paperspace.commands import jobs as jobs_commands
@@ -66,25 +67,25 @@ def list_jobs(api_key, **filters):
6667

6768
@jobs_group.command("create", help="Create job")
6869
@click.option("--name", "name", help="Job name", required=True)
69-
@click.option('--machineType', 'machineType', help="Virtual machine type")
70-
@click.option('--container', 'container', help="Docker container")
71-
@click.option('--command', 'command', help="Job command/entrypoint")
72-
@click.option('--ports', 'ports', help="Mapped ports")
73-
@click.option('--isPublic', 'isPublic', help="Flag: is job public")
70+
@click.option("--machineType", "machineType", help="Virtual machine type")
71+
@click.option("--container", "container", help="Docker container")
72+
@click.option("--command", "command", help="Job command/entrypoint")
73+
@click.option("--ports", "ports", help="Mapped ports")
74+
@click.option("--isPublic", "isPublic", help="Flag: is job public")
7475
@click.option("--workspace", "workspace", required=False, help="Path to workspace directory")
7576
@click.option("--workspaceArchive", "workspaceArchive", required=False, help="Path to workspace archive")
7677
@click.option("--workspaceUrl", "workspaceUrl", required=False, help="Project git repository url")
7778
@click.option("--workingDirectory", "workingDirectory", help="Working directory for the experiment", )
78-
@click.option('--experimentId', 'experimentId', help="Experiment Id")
79-
# @click.option('--envVars', 'envVars', help="Environmental variables ") # TODO
80-
@click.option('--useDockerfile', 'useDockerfile', help="Flag: using Dockerfile")
81-
@click.option('--isPreemptible', 'isPreemptible', help="Flag: isPreemptible")
82-
@click.option('--project', 'project', help="Project name")
83-
@click.option('--projectHandle', '--projectId', 'projectHandle', help="Project handle", required=True)
84-
@click.option('--startedByUserId', 'startedByUserId', help="User ID")
85-
@click.option('--relDockerfilePath', 'relDockerfilePath', help="Relative path to Dockerfile")
86-
@click.option('--registryUsername', 'registryUsername', help="Docker registry username")
87-
@click.option('--registryPassword', 'registryPassword', help="Docker registry password")
79+
@click.option("--experimentId", "experimentId", help="Experiment Id")
80+
@click.option("--jobEnv", "envVars", type=json_string, help="Environmental variables ")
81+
@click.option("--useDockerfile", "useDockerfile", help="Flag: using Dockerfile")
82+
@click.option("--isPreemptible", "isPreemptible", help="Flag: isPreemptible")
83+
@click.option("--project", "project", help="Project name")
84+
@click.option("--projectHandle", "--projectId", "projectHandle", help="Project handle", required=True)
85+
@click.option("--startedByUserId", "startedByUserId", help="User ID")
86+
@click.option("--relDockerfilePath", "relDockerfilePath", help="Relative path to Dockerfile")
87+
@click.option("--registryUsername", "registryUsername", help="Docker registry username")
88+
@click.option("--registryPassword", "registryPassword", help="Docker registry password")
8889
@common.api_key_option
8990
def create_job(api_key, **kwargs):
9091
del_if_value_is_none(kwargs)

paperspace/commands/machines.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import terminaltables
55

66
from paperspace.commands import CommandBase
7-
from paperspace.exceptions import BadResponseException
7+
from paperspace.exceptions import BadResponseError
88
from paperspace.utils import get_terminal_lines
99

1010

@@ -228,7 +228,7 @@ def execute(self, machine_id, state, interval=5):
228228
while True:
229229
try:
230230
current_state = self._get_machine_state(machine_id)
231-
except BadResponseException as e:
231+
except BadResponseError as e:
232232
self.logger.error(e)
233233
return
234234
else:
@@ -246,8 +246,8 @@ def _get_machine_state(self, machine_id):
246246
json_ = response.json()
247247
if not response.ok:
248248
self.logger.log_error_response(json_)
249-
raise BadResponseException("Error while reading machine state")
249+
raise BadResponseError("Error while reading machine state")
250250
state = json_.get("state")
251251
except (ValueError, AttributeError):
252-
raise BadResponseException("Unknown error while reading machine state")
252+
raise BadResponseError("Unknown error while reading machine state")
253253
return state

paperspace/exceptions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
class ApplicationException(Exception):
1+
class ApplicationError(Exception):
22
pass
33

44

5-
class BadResponseException(ApplicationException):
5+
class BadResponseError(ApplicationError):
66
pass
77

88

9-
class PresignedUrlUnreachableException(ApplicationException):
9+
class PresignedUrlUnreachableError(ApplicationError):
1010
pass
1111

1212

13-
class ProjectAccessDeniedException(ApplicationException):
13+
class ProjectAccessDeniedError(ApplicationError):
1414
pass
1515

1616

17-
class PresignedUrlAccessDeniedException(ApplicationException):
17+
class PresignedUrlAccessDeniedError(ApplicationError):
1818
pass
1919

2020

21-
class PresignedUrlConnectionException(ApplicationException):
21+
class PresignedUrlConnectionError(ApplicationError):
2222
pass
2323

2424

25-
class S3UploadFailedException(ApplicationException):
25+
class S3UploadFailedError(ApplicationError):
2626
pass

paperspace/workspace.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from requests_toolbelt.multipart import encoder
99
from paperspace import logger as default_logger
1010

11-
from paperspace.exceptions import S3UploadFailedException, PresignedUrlUnreachableException, \
12-
PresignedUrlAccessDeniedException, PresignedUrlConnectionException, ProjectAccessDeniedException
11+
from paperspace.exceptions import S3UploadFailedError, PresignedUrlUnreachableError, \
12+
PresignedUrlAccessDeniedError, PresignedUrlConnectionError, ProjectAccessDeniedError
1313

1414

1515
class S3WorkspaceHandler:
@@ -22,23 +22,23 @@ def __init__(self, experiments_api, logger=None):
2222
self.experiments_api = experiments_api
2323
self.logger = logger or default_logger
2424

25-
def _retrieve_file_paths(self, dirName):
25+
@staticmethod
26+
def _retrieve_file_paths(dir_name):
2627
# setup file paths variable
2728
file_paths = {}
2829
exclude = ['.git', '.idea', '.pytest_cache']
2930
# Read all directory, subdirectories and file lists
30-
for root, dirs, files in os.walk(dirName, topdown=True):
31+
for root, dirs, files in os.walk(dir_name, topdown=True):
3132
dirs[:] = [d for d in dirs if d not in exclude]
3233
for filename in files:
3334
# Create the full filepath by using os module.
34-
relpath = os.path.relpath(root, dirName)
35+
relpath = os.path.relpath(root, dir_name)
3536
if relpath == '.':
3637
file_path = filename
3738
else:
38-
file_path = os.path.join(os.path.relpath(root, dirName), filename)
39+
file_path = os.path.join(os.path.relpath(root, dir_name), filename)
3940
file_paths[file_path] = os.path.join(root, filename)
4041

41-
# return all paths
4242
return file_paths
4343

4444
def _zip_workspace(self, workspace_path):
@@ -72,7 +72,8 @@ def _zip_workspace(self, workspace_path):
7272
self.logger.log('\nFinished creating archive: %s' % zip_file_name)
7373
return zip_file_path
7474

75-
def _create_callback(self, encoder_obj):
75+
@staticmethod
76+
def _create_callback(encoder_obj):
7677
bar = progressbar.ProgressBar(max_value=encoder_obj.len)
7778

7879
def callback(monitor):
@@ -116,7 +117,7 @@ def upload_workspace(self, input_data):
116117
return 's3://{}/{}'.format(bucket_name, s3_object_path)
117118

118119
def _upload(self, archive_path, s3_upload_data):
119-
files = {'file': (archive_path, open(archive_path, 'rb'))}
120+
files = self._get_files_dict(archive_path)
120121
fields = OrderedDict(s3_upload_data['fields'])
121122
fields.update(files)
122123

@@ -125,17 +126,21 @@ def _upload(self, archive_path, s3_upload_data):
125126
s3_response = requests.post(s3_upload_data['url'], data=monitor, headers={'Content-Type': monitor.content_type})
126127
self.logger.debug("S3 upload response: {}".format(s3_response.headers))
127128
if not s3_response.ok:
128-
raise S3UploadFailedException(s3_response)
129+
raise S3UploadFailedError(s3_response)
130+
131+
def _get_files_dict(self, archive_path):
132+
files = {'file': (archive_path, open(archive_path, 'rb'))}
133+
return files
129134

130135
def _get_upload_data(self, file_name, project_handle):
131136
response = self.experiments_api.get("/workspace/get_presigned_url",
132137
params={'workspaceName': file_name, 'projectHandle': project_handle})
133138
if response.status_code == 401:
134-
raise ProjectAccessDeniedException(project_handle)
139+
raise ProjectAccessDeniedError(project_handle)
135140
if response.status_code == 403:
136-
raise PresignedUrlAccessDeniedException
141+
raise PresignedUrlAccessDeniedError
137142
if response.status_code == 404:
138-
raise PresignedUrlUnreachableException
143+
raise PresignedUrlUnreachableError
139144
if not response.ok:
140-
raise PresignedUrlConnectionException(response.reason)
145+
raise PresignedUrlConnectionError(response.reason)
141146
return response.json()

0 commit comments

Comments
 (0)