Skip to content

Commit efc85b7

Browse files
committed
use as_type instead of as_object.
1 parent c39d1ab commit efc85b7

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

dataikuapi/dss/jupyternotebook.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def get_sessions(self, as_objects=False):
3838
else:
3939
return sessions
4040

41-
def get_content(self):
41+
def get_contents(self):
4242
"""
4343
Get the content of this Jupyter notebook (metadata, cells, nbformat)
4444
"""
45-
raw_content = self.client._perform_json("GET", "/projects/%s/jupyter-notebooks/%s" % (self.project_key, self.notebook_name))
46-
return DSSNotebookContent(self.client, self.project_key, self.notebook_name, raw_content)
45+
raw_contents = self.client._perform_json("GET", "/projects/%s/jupyter-notebooks/%s" % (self.project_key, self.notebook_name))
46+
return DSSNotebookContents(self.client, self.project_key, self.notebook_name, raw_contents)
4747

4848
def delete(self):
4949
"""
@@ -64,48 +64,48 @@ def get_object_discussions(self):
6464
"""
6565
return DSSObjectDiscussions(self.client, self.project_key, "JUPYTER_NOTEBOOK", self.notebook_name)
6666

67-
class DSSNotebookContent(object):
67+
class DSSNotebookContents(object):
6868
"""
69-
Content of a Jupyter Notebook. Do not create this directly, use :meth:`DSSJupyterNotebook.get_content`
69+
Contents of a Jupyter Notebook. Do not create this directly, use :meth:`DSSJupyterNotebook.get_contents`
7070
"""
7171

7272
"""
7373
A Python/R/Scala notebook on the DSS instance
7474
"""
75-
def __init__(self, client, project_key, notebook_name, content):
75+
def __init__(self, client, project_key, notebook_name, contents):
7676
self.client = client
7777
self.project_key = project_key
7878
self.notebook_name = notebook_name
79-
self.content = content
79+
self.contents = contents
8080

8181
def get_raw(self):
8282
"""
83-
Get the content of this Jupyter notebook (metadata, cells, nbformat)
84-
:rtype: a dict containing the full content of a notebook
83+
Get the contents of this Jupyter notebook (metadata, cells, nbformat)
84+
:rtype: a dict containing the full contents of a notebook
8585
"""
86-
return self.content
86+
return self.contents
8787

8888
def get_metadata(self):
8989
"""
9090
Get the metadata associated to this Jupyter notebook
9191
:rtype: dict with metadata
9292
"""
93-
return self.content["metadata"]
93+
return self.contents["metadata"]
9494

9595
def get_cells(self):
9696
"""
9797
Get the cells associated to this Jupyter notebook
9898
:rtype: list of cells
9999
"""
100-
return self.content["cells"]
100+
return self.contents["cells"]
101101

102102
def save(self):
103103
"""
104-
Save the content of this Jupyter notebook
104+
Save the contents of this Jupyter notebook
105105
"""
106106
return self.client._perform_json("PUT",
107107
"/projects/%s/jupyter-notebooks/%s" % (self.project_key, self.notebook_name),
108-
body=self.content)
108+
body=self.contents)
109109

110110
class DSSNotebookSession(object):
111111
"""

dataikuapi/dss/project.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time, warnings, sys, os.path as osp
22
from .dataset import DSSDataset, DSSDatasetListItem, DSSManagedDatasetCreationHelper
3-
from .jupyternotebook import DSSJupyterNotebook, DSSNotebookContent
3+
from .jupyternotebook import DSSJupyterNotebook
44
from .notebook import DSSNotebook
55
from .streaming_endpoint import DSSStreamingEndpoint, DSSStreamingEndpointListItem, DSSManagedStreamingEndpointCreationHelper
66
from .recipe import DSSRecipeListItem, DSSRecipe
@@ -829,23 +829,24 @@ def new_job_definition_builder(self, job_type='NON_RECURSIVE_FORCED_BUILD'):
829829
# Jupyter Notebooks
830830
########################################################
831831

832-
def list_jupyter_notebooks(self, as_objects=True, active=False):
832+
def list_jupyter_notebooks(self, active=False, as_type="object"):
833833
"""
834834
List the jupyter notebooks of a project.
835835
836-
:param bool as_objects: if True, return the jupyter notebooks as a :class:`dataikuapi.dss.notebook.DSSNotebook`
837-
notebook handles instead of raw JSON
836+
:param bool as_type: How to return the list. Supported values are "names" and "objects".
838837
:param bool active: if True, only return currently running jupyter notebooks.
839838
840-
841-
:returns: The list of the notebooks - see as_objects for more information
842-
:rtype: list
839+
:returns: The list of the notebooks. If "as_type" is "names", each one as a string, if "as_type" is "objects", each one as a :class:`dataikuapi.dss.notebook.DSSJupyterNotebook`
840+
:rtype: list of :class:`dataikuapi.dss.notebook.DSSJupyterNotebook` or list of String
843841
"""
844842
notebook_names = self.client._perform_json("GET", "/projects/%s/jupyter-notebooks/" % self.project_key, params={"active": active})
845-
if as_objects:
843+
if as_type == "names" or as_type == "name":
844+
return notebook_names
845+
elif as_type == "objects" or as_type == "object":
846846
return [DSSJupyterNotebook(self.client, self.project_key, notebook_name) for notebook_name in notebook_names]
847847
else:
848-
return notebook_names
848+
raise ValueError("Unknown as_type")
849+
849850

850851
def get_jupyter_notebook(self, notebook_name):
851852
"""

dataikuapi/dssclient.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import json
2-
import warnings
32

43
from requests import Session
54
from requests import exceptions
65
from requests.auth import HTTPBasicAuth
76

8-
from dataikuapi.dss.jupyternotebook import DSSJupyterNotebook
97
from dataikuapi.dss.notebook import DSSNotebook
108
from .dss.future import DSSFuture
119
from .dss.projectfolder import DSSProjectFolder

0 commit comments

Comments
 (0)