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

Commit f89b787

Browse files
BartoszCkiMudlaffP
authored andcommitted
Allow for filtering experiments list with multiple project handles
1 parent bc8c07c commit f89b787

File tree

6 files changed

+850
-17
lines changed

6 files changed

+850
-17
lines changed

paperspace/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ def stop(experiment_handle):
271271
commands.stop_experiment(experiment_handle)
272272

273273

274-
@click.option("--projectHandle", "project_handle")
274+
@click.option("--projectHandle", "-p", "project_handles", multiple=True)
275275
@experiments.command("list")
276-
def list_experiments(project_handle):
276+
def list_experiments(project_handles):
277277
command = commands.ListExperimentsCommand()
278-
command.execute(project_handle)
278+
command.execute(project_handles)
279279

280280

281281
@experiments.command("details")

paperspace/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ def get_path(self, url):
1515

1616
def post(self, url, json=None, params=None):
1717
path = self.get_path(url)
18-
logger.debug("Sending POST: {}\nto: {}\nwith headers: {}".format(json, path, self.headers))
1918
response = requests.post(path, json=json, params=params, headers=self.headers)
19+
logger.debug("POST request sent to: {} with headers: {}".format(response.url, self.headers))
2020
logger.debug("Response status code: {}".format(response.status_code))
2121
logger.debug("Response content: {}".format(response.content))
2222
return response
2323

2424
def put(self, url):
2525
path = self.get_path(url)
26-
logger.debug("Sending PUT to {}\nwith headers: {}".format(path, self.headers))
2726
response = requests.put(path, headers=self.headers)
27+
logger.debug("PUT request sent to: {} with headers: {}".format(response.url, self.headers))
2828
logger.debug("Response status code: {}".format(response.status_code))
2929
logger.debug("Response content: {}".format(response.content))
3030
return response
3131

3232
def get(self, url, params=None):
3333
path = self.get_path(url)
34-
logger.debug("Sending GET to {}\nwith headers: {}".format(path, self.headers))
3534
response = requests.get(path, params=params, headers=self.headers)
35+
logger.debug("GET request sent to: {} with headers: {}".format(response.url, self.headers))
3636
logger.debug("Response status code: {}".format(response.status_code))
3737
logger.debug("Response content: {}".format(response.content))
3838
return response

paperspace/commands.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,28 @@ class ListExperimentsCommand(object):
6969
def __init__(self, api=experiments_api):
7070
self.api = api
7171

72-
def execute(self, project_handle=None):
73-
# TODO: change to limit: -1 when PS-9535 is deployed to production
74-
params = {"limit": 1000000} # to list all experiments
75-
if project_handle:
76-
params["projectHandle[0]"] = project_handle
72+
def execute(self, project_handles=None):
73+
params = self._get_query_params(project_handles)
7774
response = self.api.get("/experiments/", params=params)
7875

7976
try:
80-
experiments = self._get_experiments_list(response, bool(project_handle))
77+
experiments = self._get_experiments_list(response, bool(project_handles))
8178
except (ValueError, KeyError) as e:
82-
logger.log("Error while parsing response data")
79+
logger.log("Error while parsing response data: {}".format(e))
8380
else:
8481
self._log_experiments_list(experiments)
8582

83+
@staticmethod
84+
def _get_query_params(project_handles):
85+
# TODO: change to limit: -1 when PS-9535 is deployed to production
86+
# to list all experiments
87+
params = {"limit": 1000000}
88+
for i, handle in enumerate(project_handles):
89+
key = "projectHandle[{}]".format(i)
90+
params[key] = handle
91+
92+
return params
93+
8694
@staticmethod
8795
def _make_experiments_list_table(experiments):
8896
data = [("Name", "Handle", "Status")]
@@ -103,11 +111,14 @@ def _get_experiments_list(response, filtered=False):
103111
if not response.ok:
104112
raise ValueError("Unknown error")
105113

106-
experiments = response.json()["data"]
107-
if not filtered: # If filtering by projectHandle response data has different format
108-
return experiments
114+
data = response.json()["data"]
115+
if not filtered: # If filtering by projectHandle response data has different format...
116+
return data
109117

110-
experiments = [experiment for experiment in experiments[0]["data"]]
118+
experiments = []
119+
for project_experiments in data:
120+
for experiment in project_experiments["data"]:
121+
experiments.append(experiment)
111122
return experiments
112123

113124
def _log_experiments_list(self, experiments):

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)