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

Commit 0a0a6ee

Browse files
committed
creating job + bug fixes
1 parent 20ce0af commit 0a0a6ee

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

paperspace/cli/cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ def common_experiments_create_options(f):
5858
"--workspace",
5959
"workspace",
6060
required=False,
61-
help="Path to workspace directory or archive",
62-
default="."
61+
help="Path to workspace directory",
62+
),
63+
click.option(
64+
"--workspaceArchive",
65+
"workspaceArchive",
66+
required=False,
67+
help="Path to workspace .zip archive",
6368
),
6469
click.option(
6570
"--workspaceUrl",

paperspace/cli/jobs.py

Lines changed: 22 additions & 0 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.common import del_if_value_is_none
56
from paperspace.commands import jobs as jobs_commands
67

78

@@ -63,8 +64,29 @@ def list_jobs(api_key, **filters):
6364

6465

6566
@jobs_group.command("create", help="Create job")
67+
@click.option("--name", "name", help="Job name", required=True)
68+
@click.option('--machineType', 'machineType', help="Virtual machine type")
69+
@click.option('--container', 'container', help="Docker container")
70+
@click.option('--command', 'command', help="Job command/entrypoint")
71+
@click.option('--ports', 'ports', help="Mapped ports")
72+
@click.option('--isPublic', 'isPublic', help="Flag: is job public")
73+
@click.option("--workspace", "workspace", required=False, help="Path to workspace directory")
74+
@click.option("--workspaceArchive", "workspaceArchive", required=False, help="Path to workspace archive")
75+
@click.option("--workspaceUrl", "workspaceUrl", required=False, help="Project git repository url")
76+
@click.option("--workingDirectory", "workingDirectory", help="Working directory for the experiment", )
77+
@click.option('--experimentId', 'experimentId', help="Experiment Id")
78+
# @click.option('--envVars', 'envVars', help="Environmental variables ") # TODO
79+
@click.option('--useDockerfile', 'useDockerfile', help="Flag: using Dockerfile")
80+
@click.option('--isPreemptible', 'isPreemptible', help="Flag: isPreemptible")
81+
@click.option('--project', 'project', help="Project name")
82+
@click.option('--projectHandle', '--projectId', 'projectId', help="Project handle", required=True)
83+
@click.option('--startedByUserId', 'startedByUserId', help="User ID")
84+
@click.option('--relDockerfilePath', 'relDockerfilePath', help="Relative path to Dockerfile")
85+
@click.option('--registryUsername', 'registryUsername', help="Docker registry username")
86+
@click.option('--registryPassword', 'registryPassword', help="Docker registry password")
6687
@common.api_key_option
6788
def create_job(api_key, **kwargs):
89+
del_if_value_is_none(kwargs)
6890
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
6991
command = jobs_commands.CreateJobCommand(api=jobs_api)
7092
command.execute(kwargs)

paperspace/commands/experiments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class ExperimentCommand(CommandBase):
1515
def __init__(self, workspace_handler=None, **kwargs):
1616
super(ExperimentCommand, self).__init__(**kwargs)
17-
self._workspace_handler = workspace_handler or S3WorkspaceHandler(api=self.api, logger=self.logger)
17+
self._workspace_handler = workspace_handler or S3WorkspaceHandler(experiments_api=self.api, logger=self.logger)
1818

1919
def _log_create_experiment(self, response, success_msg_template, error_msg):
2020
if response.ok:

paperspace/commands/jobs.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import terminaltables
44

5+
from paperspace import config, client
56
from paperspace.commands import CommandBase
67
from paperspace.utils import get_terminal_lines
78
from paperspace.workspace import S3WorkspaceHandler
@@ -88,10 +89,17 @@ def _make_table(jobs):
8889
class CreateJobCommand(JobsCommandBase):
8990
def __init__(self, workspace_handler=None, **kwargs):
9091
super(CreateJobCommand, self).__init__(**kwargs)
91-
self.workspace_handler = workspace_handler or S3WorkspaceHandler(api=self.api, logger=self.logger)
92+
experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=kwargs.get('api_key'))
93+
self._workspace_handler = workspace_handler or S3WorkspaceHandler(experiments_api=experiments_api,
94+
logger=self.logger)
9295

9396
def execute(self, json_):
9497
url = "/jobs/createJob/"
98+
99+
workspace_url = self._workspace_handler.upload_workspace(json_)
100+
if workspace_url:
101+
json_['workspaceFileName'] = workspace_url
102+
95103
response = self.api.post(url, json_)
96104
self._log_message(response,
97105
"Job created",

paperspace/workspace.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414

1515
class S3WorkspaceHandler:
16-
def __init__(self, api, logger=None):
17-
self.api = api
16+
def __init__(self, experiments_api, logger=None):
17+
self.experiments_api = experiments_api
1818
self.logger = logger or logging.getLogger()
1919

2020
def _retrieve_file_paths(self, dirName):
@@ -78,13 +78,13 @@ def callback(monitor):
7878

7979
def upload_workspace(self, input_data):
8080
workspace_url = input_data.get('workspaceUrl')
81-
workspace_path = input_data.get('workspacePath')
81+
workspace_path = input_data.get('workspace')
8282
workspace_archive = input_data.get('workspaceArchive')
8383
if (workspace_archive and workspace_path) or (workspace_archive and workspace_url) or (
8484
workspace_path and workspace_url):
8585
raise click.UsageError("Use either:\n\t--workspaceUrl to point repository URL"
86-
"\n\t--workspacePath to point on project directory"
87-
"\n\t--workspaceArchive to point on project ZIP archive"
86+
"\n\t--workspace to point on project directory"
87+
"\n\t--workspaceArchive to point on project .zip archive"
8888
"\n or neither to use current directory")
8989

9090
if workspace_url:
@@ -115,7 +115,7 @@ def upload_workspace(self, input_data):
115115
return 's3://{}/{}'.format(bucket_name, file_name)
116116

117117
def _get_upload_data(self, file_name):
118-
response = self.api.get("/workspace/get_presigned_url", params={'workspaceName': file_name})
118+
response = self.experiments_api.get("/workspace/get_presigned_url", params={'workspaceName': file_name})
119119
if response.status_code == 404:
120120
raise PresignedUrlUnreachableException
121121
if response.status_code == 403:

0 commit comments

Comments
 (0)