Skip to content

Commit bc16aec

Browse files
committed
applied fixes on review [ch28499]
1 parent 76c4500 commit bc16aec

File tree

10 files changed

+101
-68
lines changed

10 files changed

+101
-68
lines changed

dataikuapi/dss/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,6 @@ def get_object_discussions(self):
244244
Get a handle to manage discussions on the dataset
245245
246246
:returns: the handle to manage discussions
247-
:rtype: DSSObjectDiscussions
247+
:rtype: :class:`dataikuapi.discussion.DSSObjectDiscussions`
248248
"""
249249
return DSSObjectDiscussions(self.client, self.project_key, "DATASET", self.dataset_name)

dataikuapi/dss/discussion.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ class DSSObjectDiscussions(object):
1313
A handle to manage discussions on a DSS object
1414
"""
1515
def __init__(self, client, project_key, object_type, object_id):
16-
"""
17-
:param DSSClient client: an api client to connect to the DSS backend
18-
:param str project_key: identifier of the project to access
19-
:param str object_type: DSS object type
20-
:param str object_id: DSS object ID
21-
"""
16+
"""Do not call directly, use :meth:`dataikuapi.dssclient.DSSClient.get_object_discussions` or on any commentable DSS object"""
2217
self.client = client
2318
self.project_key = project_key
2419
self.object_type = object_type
@@ -32,14 +27,10 @@ def list_discussions(self):
3227
Get the list of discussions on the object
3328
3429
:returns: list of discussions on the object
35-
:rtype: list
30+
:rtype: list of :class:`dataikuapi.dss.discussion.DSSDiscussion`
3631
"""
3732
data = self.client._perform_json("GET", "/projects/%s/discussions/%s/%s/" % (self.project_key, self.object_type, self.object_id))
38-
39-
discu_list = []
40-
for discu_data in data:
41-
discu_list.append(DSSDiscussion(self.client, self.project_key, self.object_type, self.object_id, discu_data['id'], discu_data, False))
42-
return discu_list
33+
return [DSSDiscussion(self.client, self.project_key, self.object_type, self.object_id, discu_data['id'], discu_data, False) for discu_data in data]
4334

4435
def create_discussion(self, topic, message):
4536
"""
@@ -48,7 +39,7 @@ def create_discussion(self, topic, message):
4839
:param str topic: the discussion topic
4940
:param str message: the markdown formatted first message
5041
:returns: the newly created discussion
51-
:rtype: DSSDiscussion
42+
:rtype: :class:`dataikuapi.dss.discussion.DSSDiscussion`
5243
"""
5344
creation_data = {
5445
"topic" : topic,
@@ -63,15 +54,13 @@ def get_discussion(self, discussion_id):
6354
6455
:param str discussion_id: the discussion ID
6556
:returns: the discussion
66-
:rtype: DSSDiscussion
57+
:rtype: :class:`dataikuapi.dss.discussion.DSSDiscussion`
6758
"""
6859
discu_data = self.client._perform_json("GET", "/projects/%s/discussions/%s/%s/%s" % (self.project_key, self.object_type, self.object_id, discussion_id))
6960
return DSSDiscussion(self.client, self.project_key, self.object_type, self.object_id, discussion_id, discu_data, True)
7061

7162
class DSSDiscussion(object):
72-
"""
73-
A handle to manage a discussion on a DSS object
74-
"""
63+
"""Do not call directly, use :meth:`dataikuapi.dss.discussion.DSSObjectDiscussions.get_discussion`"""
7564
def __init__(self, client, project_key, object_type, object_id, discussion_id, discussion_data, discussion_data_has_replies):
7665
"""
7766
:param DSSClient client: an api client to connect to the DSS backend
@@ -129,15 +118,12 @@ def get_replies(self):
129118
Get the list of replies in this discussion
130119
131120
:returns: a list of replies
132-
:rtype: list
121+
:rtype: list of :class:`dataikuapi.dss.discussion.DSSDiscussionReply`
133122
"""
134123
if not self.discussion_data_has_replies:
135124
self._get_with_replies()
136125

137-
reply_list = []
138-
for reply_data in self.discussion_data["replies"]:
139-
reply_list.append(DSSDiscussionReply(reply_data))
140-
return reply_list
126+
return [DSSDiscussionReply(reply_data) for reply_data in self.discussion_data["replies"]]
141127

142128
def add_reply(self, text):
143129
"""
@@ -156,14 +142,12 @@ class DSSDiscussionReply(object):
156142
A read-only handle to access a discussion reply
157143
"""
158144
def __init__(self, reply_data):
159-
"""
160-
:param dict reply_data: the reply data from the discussion
161-
"""
145+
"""Do not call directly, use :meth:`dataikuapi.dss.discussion.DSSDiscussion.get_replies`"""
162146
self.reply_data = reply_data
163147

164-
def get_reply_data(self):
148+
def get_raw_data(self):
165149
"""
166-
Get the reply data
150+
Get the reply raw data
167151
168152
:returns: the reply data
169153
:rtype: dict

dataikuapi/dss/managedfolder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,6 @@ def get_object_discussions(self):
170170
Get a handle to manage discussions on the managed folder
171171
172172
:returns: the handle to manage discussions
173-
:rtype: DSSObjectDiscussions
173+
:rtype: :class:`dataikuapi.discussion.DSSObjectDiscussions`
174174
"""
175175
return DSSObjectDiscussions(self.client, self.project_key, "MANAGED_FOLDER", self.odb_id)

dataikuapi/dss/notebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ def get_object_discussions(self):
5656
Get a handle to manage discussions on the notebook
5757
5858
:returns: the handle to manage discussions
59-
:rtype: DSSObjectDiscussions
59+
:rtype: :class:`dataikuapi.discussion.DSSObjectDiscussions`
6060
"""
6161
return DSSObjectDiscussions(self.client, self.project_key, "JUPYTER_NOTEBOOK", self.notebook_name)

dataikuapi/dss/project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ def get_wiki(self):
755755
Get the wiki
756756
757757
:returns: the wiki associated to the project
758-
:rtype: DSSWiki
758+
:rtype: :class:`dataikuapi.dss.wiki.DSSWiki`
759759
"""
760760
return DSSWiki(self.client, self.project_key)
761761

@@ -767,7 +767,7 @@ def get_object_discussions(self):
767767
Get a handle to manage discussions on the project
768768
769769
:returns: the handle to manage discussions
770-
:rtype: DSSObjectDiscussions
770+
:rtype: :class:`dataikuapi.discussion.DSSObjectDiscussions`
771771
"""
772772
return DSSObjectDiscussions(self.client, self.project_key, "PROJECT", self.project_key)
773773

dataikuapi/dss/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def get_object_discussions(self):
8585
Get a handle to manage discussions on the recipe
8686
8787
:returns: the handle to manage discussions
88-
:rtype: DSSObjectDiscussions
88+
:rtype: :class:`dataikuapi.discussion.DSSObjectDiscussions`
8989
"""
9090
return DSSObjectDiscussions(self.client, self.project_key, "RECIPE", self.recipe_name)
9191

dataikuapi/dss/savedmodel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ def get_object_discussions(self):
106106
Get a handle to manage discussions on the saved model
107107
108108
:returns: the handle to manage discussions
109-
:rtype: DSSObjectDiscussions
109+
:rtype: :class:`dataikuapi.discussion.DSSObjectDiscussions`
110110
"""
111111
return DSSObjectDiscussions(self.client, self.project_key, "SAVED_MODEL", self.sm_id)

dataikuapi/dss/scenario.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def get_object_discussions(self):
164164
Get a handle to manage discussions on the scenario
165165
166166
:returns: the handle to manage discussions
167-
:rtype: DSSObjectDiscussions
167+
:rtype: :class:`dataikuapi.discussion.DSSObjectDiscussions`
168168
"""
169169
return DSSObjectDiscussions(self.client, self.project_key, "SCENARIO", self.id)
170170

dataikuapi/dss/wiki.py

Lines changed: 81 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .discussion import DSSObjectDiscussions
2+
from dataikuapi.utils import DataikuException
23
import json
34
import sys
45

@@ -14,19 +15,16 @@ class DSSWiki(object):
1415
A handle to manage the wiki of a project
1516
"""
1617
def __init__(self, client, project_key):
17-
"""
18-
:param DSSClient client: an api client to connect to the DSS backend
19-
:param str project_key: identifier of the project to access
20-
"""
18+
"""Do not call directly, use :meth:`dataikuapi.dss.project.DSSProject.get_wiki`"""
2119
self.client = client
2220
self.project_key = project_key
2321

2422
def get_settings(self):
2523
"""
2624
Get wiki settings
2725
28-
:returns: an handle to manage the wiki settings (taxonomy, home article)
29-
:rtype: DSSWikiSettings
26+
:returns: a handle to manage the wiki settings (taxonomy, home article)
27+
:rtype: :class:`dataikuapi.dss.wiki.DSSWikiSettings`
3028
"""
3129
return DSSWikiSettings(self.client, self.project_key, self.client._perform_json("GET", "/projects/%s/wiki/" % (self.project_key)))
3230

@@ -35,8 +33,8 @@ def get_article(self, article_id):
3533
Get a wiki article
3634
3735
:param str article_id: the article ID
38-
:returns: an handle to manage the Article
39-
:rtype: DSSWikiArticle
36+
:returns: a handle to manage the Article
37+
:rtype: :class:`dataikuapi.dss.wiki.DSSWikiArticle`
4038
"""
4139
return DSSWikiArticle(self.client, self.project_key, article_id)
4240

@@ -46,7 +44,7 @@ def __flatten_taxonomy__(self, taxonomy):
4644
4745
:param list taxonomy:
4846
:returns: list of articles
49-
:rtype: list
47+
:rtype: list of :class:`dataikuapi.dss.wiki.DSSWikiArticle`
5048
"""
5149
article_list = []
5250
for article in taxonomy:
@@ -56,10 +54,10 @@ def __flatten_taxonomy__(self, taxonomy):
5654

5755
def list_articles(self):
5856
"""
59-
Get a list of all the articles
57+
Get a list of all the articles in form of :class:`dataikuapi.dss.wiki.DSSWikiArticle` objects
6058
6159
:returns: list of articles
62-
:rtype: list
60+
:rtype: list of :class:`dataikuapi.dss.wiki.DSSWikiArticle`
6361
"""
6462
return self.__flatten_taxonomy__(self.get_settings().get_taxonomy())
6563

@@ -71,7 +69,7 @@ def create_article(self, article_id, parent_id=None, content=None):
7169
:param str parent_id: the parent article ID (or None if the article has to be at root level)
7270
:param str content: the article content
7371
:returns: the created article
74-
:rtype: DSSWikiArticle
72+
:rtype: :class:`dataikuapi.dss.wiki.DSSWikiArticle`
7573
"""
7674
body = {
7775
"projectKey": self.project_key,
@@ -94,24 +92,81 @@ class DSSWikiSettings(object):
9492
Global settings for the wiki, including taxonomy. Call save() to save
9593
"""
9694
def __init__(self, client, project_key, settings):
97-
"""
98-
:param DSSClient client: an api client to connect to the DSS backend
99-
:param str project_key: identifier of the project to access
100-
:param dict settings: current wiki settings (containing taxonomy and home article)
101-
"""
95+
"""Do not call directly, use :meth:`dataikuapi.dss.wiki.DSSWiki.get_settings`"""
10296
self.client = client
10397
self.project_key = project_key
10498
self.settings = settings
10599

106100
def get_taxonomy(self):
107101
"""
108102
Get the taxonomy
103+
The taxonomy is an array listing at top level the root article IDs and their children in a tree format.
104+
Every existing article of the wiki has to be in the taxonomy once and only once.
105+
For instance:
106+
[
107+
{
108+
'id': 'article1',
109+
'children': []
110+
},
111+
{
112+
'id': 'article2',
113+
'children': [
114+
{
115+
'id': 'article3',
116+
'children': []
117+
}
118+
]
119+
}
120+
]
121+
Note that this is a direct reference, not a copy, so modifications to the returned object will be reflected when saving
109122
110123
:returns: The taxonomy
111124
:rtype: list
112125
"""
113126
return self.settings["taxonomy"]
114127

128+
def __retrieve_article_in_taxonomy__(self, taxonomy, article_id, remove=False):
129+
"""
130+
Private recusive method that get the sub tree structure from the taxonomy for a specific article
131+
132+
:param list taxonomy: the current level of taxonomy
133+
:param str article_id: the article to retrieve
134+
:param bool remove: either remove the sub tree structure or not
135+
"""
136+
idx = 0
137+
for tax_article in taxonomy:
138+
if tax_article["id"] == article_id:
139+
ret = taxonomy.pop(idx) if remove else taxonomy[idx]
140+
return ret
141+
children_ret = self.__retrieve_article_in_taxonomy__(tax_article["children"], article_id, remove)
142+
if children_ret is not None:
143+
return children_ret
144+
idx += 1
145+
return None
146+
147+
def move_article_in_taxonomy(self, article_id, parent_article_id=None):
148+
"""
149+
An helper to update the taxonomy by moving an article with its children as a child of another article
150+
151+
:param str article_id: the main article ID
152+
:param str parent_article_id: the new parent article ID or None for root level
153+
"""
154+
old_taxonomy = list(self.settings["taxonomy"])
155+
156+
tax_article = self.__retrieve_article_in_taxonomy__(self.settings["taxonomy"], article_id, True)
157+
if tax_article is None:
158+
raise DataikuException("Article not found: %s" % (article_id))
159+
160+
if parent_article_id is None:
161+
self.settings["taxonomy"].append(tax_article)
162+
else:
163+
tax_parent_article = self.__retrieve_article_in_taxonomy__(self.settings["taxonomy"], parent_article_id, False)
164+
if tax_article is None:
165+
self.settings["taonomy"] = old_taxonomy
166+
raise DataikuException("Parent article not found (or is one of the article descendants): %s" % (parent_article_id))
167+
tax_parent_article["children"].append(tax_article)
168+
169+
115170
def set_taxonomy(self, taxonomy):
116171
"""
117172
Set the taxonomy
@@ -148,11 +203,7 @@ class DSSWikiArticle(object):
148203
A handle to manage an article
149204
"""
150205
def __init__(self, client, project_key, article_id):
151-
"""
152-
:param DSSClient client: an api client to connect to the DSS backend
153-
:param str project_key: identifier of the project to access
154-
:param str article_id: the article ID
155-
"""
206+
"""Do not call directly, use :meth:`dataikuapi.dss.wiki.DSSWiki.get_article`"""
156207
self.client = client
157208
self.project_key = project_key
158209
self.article_id = article_id
@@ -165,18 +216,20 @@ def get_data(self):
165216
Get article data handle
166217
167218
:returns: the article data handle
168-
:rtype: DSSWikiArticleData
219+
:rtype: :class:`dataikuapi.dss.wiki.DSSWikiArticleData`
169220
"""
170221
article_data = self.client._perform_json("GET", "/projects/%s/wiki/%s" % (self.project_key, dku_quote_fn(self.article_id)))
171222
return DSSWikiArticleData(self.client, self.project_key, self.article_id, article_data)
172223

173-
def upload_attachement(self, fp):
224+
def upload_attachement(self, fp, filename):
174225
"""
175226
Upload an attachment file and attaches it to the article
227+
Note that the type of file will be determined by the filename extension
176228
177229
:param file fp: A file-like object that represents the upload file
230+
:param str filename: The attachement filename
178231
"""
179-
self.client._perform_json("POST", "/projects/%s/wiki/%s/upload" % (self.project_key, dku_quote_fn(self.article_id)), files={"file":fp})
232+
self.client._perform_json("POST", "/projects/%s/wiki/%s/upload" % (self.project_key, dku_quote_fn(self.article_id)), files={"file":(filename, fp)})
180233

181234
def delete(self):
182235
"""
@@ -189,7 +242,7 @@ def get_object_discussions(self):
189242
Get a handle to manage discussions on the article
190243
191244
:returns: the handle to manage discussions
192-
:rtype: DSSObjectDiscussions
245+
:rtype: :class:`dataikuapi.dss.wiki.DSSObjectDiscussions`
193246
"""
194247
return DSSObjectDiscussions(self.client, self.project_key, "ARTICLE", self.article_id)
195248

@@ -198,12 +251,7 @@ class DSSWikiArticleData(object):
198251
A handle to manage an article
199252
"""
200253
def __init__(self, client, project_key, article_id, article_data):
201-
"""
202-
:param DSSClient client: an api client to connect to the DSS backend
203-
:param str project_key: identifier of the project to access
204-
:param str article_id: the article ID
205-
:param dict article_data: the article data got from the backend
206-
"""
254+
"""Do not call directly, use :meth:`dataikuapi.dss.wiki.DSSWikiArticle.get_data`"""
207255
self.client = client
208256
self.project_key = project_key
209257
self.article_id = article_id # don't need to check unicode here (already done in DSSWikiArticle)
@@ -229,6 +277,7 @@ def set_body(self, content):
229277
def get_metadata(self):
230278
"""
231279
Get the article metadata
280+
Note that this is a direct reference, not a copy, so modifications to the returned object will be reflected when saving
232281
233282
:returns: the article metadata
234283
:rtype: dict

dataikuapi/dssclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ def get_object_discussions(self, project_key, object_type, object_id):
765765
:param str object_type: DSS object type
766766
:param str object_id: DSS object ID
767767
:returns: the handle to manage discussions
768-
:rtype: DSSObjectDiscussions
768+
:rtype: :class:`dataikuapi.discussion.DSSObjectDiscussions`
769769
"""
770770
return DSSObjectDiscussions(self, project_key, object_type, object_id)
771771

0 commit comments

Comments
 (0)