Skip to content

Commit 089e584

Browse files
Merge pull request #238 from Paperspace/PS-12323-Add_--projectId_to_models_upload_command
Add --projectId option to models upload command
2 parents a27356b + d1bdf76 commit 089e584

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

gradient/api_sdk/clients/model_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def delete(self, model_id):
2929
repository = self.build_repository(repositories.DeleteModel)
3030
repository.delete(model_id)
3131

32-
def upload(self, path, name, model_type, model_summary=None, notes=None, tags=None, ):
32+
def upload(self, path, name, model_type, model_summary=None, notes=None, tags=None, project_id=None):
3333
"""Upload model
3434
3535
:param file path: path to Model
@@ -38,6 +38,7 @@ def upload(self, path, name, model_type, model_summary=None, notes=None, tags=No
3838
:param dict|None model_summary: Dictionary describing model parameters like loss, accuracy, etc.
3939
:param str|None notes: Optional model description
4040
:param list[str] tags: List of tags
41+
:param str|None project_id: ID of a project
4142
4243
:return: ID of new model
4344
:rtype: str
@@ -48,6 +49,7 @@ def upload(self, path, name, model_type, model_summary=None, notes=None, tags=No
4849
model_type=model_type,
4950
summary=json.dumps(model_summary) if model_summary else None,
5051
notes=notes,
52+
project_id=project_id,
5153
)
5254

5355
repository = self.build_repository(repositories.UploadModel)

gradient/cli/models.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ def delete_model(api_key, model_id, options_file):
8181
help="Model type",
8282
cls=common.GradientOption,
8383
)
84+
@click.option(
85+
"--projectId",
86+
"project_id",
87+
help="ID of a project",
88+
cls=common.GradientOption,
89+
)
8490
@click.option(
8591
"--modelSummary",
8692
"model_summary",
@@ -109,10 +115,10 @@ def delete_model(api_key, model_id, options_file):
109115
)
110116
@common.api_key_option
111117
@common.options_file
112-
def upload_model(path, name, model_type, model_summary, notes, api_key, options_file, **kwargs):
113-
kwargs["tags"] = validate_comma_split_option(kwargs.pop("tags_comma"), kwargs.pop("tags"))
118+
def upload_model(api_key, options_file, **model):
119+
model["tags"] = validate_comma_split_option(model.pop("tags_comma"), model.pop("tags"))
114120
command = models_commands.UploadModel(api_key=api_key)
115-
command.execute(path, name, model_type, model_summary, notes, **kwargs)
121+
command.execute(**model)
116122

117123

118124
@models_group.command("details", help="Show model details")

gradient/commands/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def execute(self, model_id, *args, **kwargs):
5454
class UploadModel(GetModelsClientMixin, BaseCommand):
5555
SPINNER_MESSAGE = "Uploading model"
5656

57-
def execute(self, path, name, model_type, model_summary, notes, **kwargs):
57+
def execute(self, **kwargs):
5858
with halo.Halo(text=self.SPINNER_MESSAGE, spinner="dots"):
59-
model_id = self.client.upload(path, name, model_type, model_summary, notes, **kwargs)
59+
model_id = self.client.upload(**kwargs)
6060

6161
self.logger.log("Model uploaded with ID: {}".format(model_id))
6262

tests/config_files/models_upload.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ modelSummary:
55
modelType: Tensorflow
66
name: some_name
77
notes: some notes
8+
projectId: some_project_id

tests/functional/test_models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import mock
66
from click.testing import CliRunner
7-
87
from gradient.api_sdk.clients.http_client import default_headers
98
from gradient.cli import cli
109
from tests import example_responses, MockResponse
@@ -269,12 +268,14 @@ class TestModelUpload(object):
269268
"--modelType", "tensorflow",
270269
"--modelSummary", """{"key": "value"}""",
271270
"--notes", "some notes",
271+
"--projectId", "some_project_id",
272272
]
273273
ALL_OPTIONS_PARAMS = {
274274
"name": "some_name",
275275
"modelType": "Tensorflow",
276276
"summary": """{"key": "value"}""",
277277
"notes": "some notes",
278+
"projectId": "some_project_id",
278279
}
279280

280281
COMMAND_WITH_API_KEY_PARAMETER_USED = [
@@ -284,6 +285,7 @@ class TestModelUpload(object):
284285
"--modelType", "tensorflow",
285286
"--modelSummary", """{"key": "value"}""",
286287
"--notes", "some notes",
288+
"--projectId", "some_project_id",
287289
"--apiKey", "some_key",
288290
]
289291
COMMAND_WITH_OPTIONS_FILE = ["models", "upload", "--optionsFile", ] # path added in test

0 commit comments

Comments
 (0)