Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions dataikuapi/dss/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ def duplicate(self, target_project_key,
if target_project_folder is not None:
obj["targetProjectFolderId"] = target_project_folder.project_folder_id

ref = self.client._perform_json("POST", "/projects/%s/duplicate/" % self.project_key, body = obj)
return ref
return self.client._perform_json(
"POST", "/projects/%s/duplicate/" % self.project_key, body=obj
)
Comment on lines -196 to +198

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DSSProject.duplicate refactored with the following changes:


########################################################
# Project infos
Expand Down Expand Up @@ -263,9 +264,9 @@ def list_datasets(self, as_type="listitems"):
:rtype: list
"""
items = self.client._perform_json("GET", "/projects/%s/datasets/" % self.project_key)
if as_type == "listitems" or as_type == "listitem":
if as_type in ["listitems", "listitem"]:
return [DSSDatasetListItem(self.client, item) for item in items]
elif as_type == "objects" or as_type == "object":
elif as_type in ["objects", "object"]:
Comment on lines -266 to +269

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DSSProject.list_datasets refactored with the following changes:

return [DSSDataset(self.client, self.project_key, item["name"]) for item in items]
else:
raise ValueError("Unknown as_type")
Expand Down Expand Up @@ -403,9 +404,9 @@ def list_streaming_endpoints(self, as_type="listitems"):
:rtype: list
"""
items = self.client._perform_json("GET", "/projects/%s/streamingendpoints/" % self.project_key)
if as_type == "listitems" or as_type == "listitem":
if as_type in ["listitems", "listitem"]:
return [DSSStreamingEndpointListItem(self.client, item) for item in items]
elif as_type == "objects" or as_type == "object":
elif as_type in ["objects", "object"]:
Comment on lines -406 to +409

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DSSProject.list_streaming_endpoints refactored with the following changes:

return [DSSStreamingEndpoint(self.client, self.project_key, item["id"]) for item in items]
else:
raise ValueError("Unknown as_type")
Expand Down Expand Up @@ -715,7 +716,7 @@ def list_model_evaluation_stores(self, as_type=None):
:rtype: list
"""
items = self.client._perform_json("GET", "/projects/%s/modelevaluationstores/" % self.project_key)
if as_type == "objects" or as_type == "object":
if as_type in ["objects", "object"]:
Comment on lines -718 to +719

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DSSProject.list_model_evaluation_stores refactored with the following changes:

return [DSSModelEvaluationStore(self.client, self.project_key, item["id"]) for item in items]
else:
return items
Expand Down Expand Up @@ -927,9 +928,9 @@ def set_variables(self, obj):

@param dict obj: must be a modified version of the object returned by get_variables
"""
if not "standard" in obj:
if "standard" not in obj:
raise ValueError("Missing 'standard' key in argument")
if not "local" in obj:
if "local" not in obj:
Comment on lines -930 to +933

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DSSProject.set_variables refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

raise ValueError("Missing 'local' key in argument")

self.client._perform_empty(
Expand Down Expand Up @@ -1146,9 +1147,9 @@ def list_recipes(self, as_type="listitems"):
:rtype: list
"""
items = self.client._perform_json("GET", "/projects/%s/recipes/" % self.project_key)
if as_type == "listitems" or as_type == "listitem":
if as_type in ["listitems", "listitem"]:
return [DSSRecipeListItem(self.client, item) for item in items]
elif as_type == "objects" or as_type == "object":
elif as_type in ["objects", "object"]:
Comment on lines -1149 to +1152

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DSSProject.list_recipes refactored with the following changes:

return [DSSRecipe(self.client, self.project_key, item["name"]) for item in items]
else:
raise ValueError("Unknown as_type")
Expand Down Expand Up @@ -1234,7 +1235,7 @@ def new_recipe(self, type, name=None):
return recipe.SamplingRecipeCreator(name, self)
elif type == "split":
return recipe.SplitRecipeCreator(name, self)
elif type == "prepare" or type == "shaker":
elif type in ["prepare", "shaker"]:
Comment on lines -1237 to +1238

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DSSProject.new_recipe refactored with the following changes:

return recipe.PrepareRecipeCreator(name, self)
elif type == "prediction_scoring":
return recipe.PredictionScoringRecipeCreator(name, self)
Expand Down Expand Up @@ -1593,11 +1594,9 @@ def add_exposed_object(self, object_type, object_id, target_project):
found_eo = {"type" : object_type, "localName" : object_id, "rules" : []}
self.settings["exposedObjects"]["objects"].append(found_eo)

already_exists = False
for rule in found_eo["rules"]:
if rule["targetProject"] == target_project:
already_exists = True
break
already_exists = any(
rule["targetProject"] == target_project for rule in found_eo["rules"]
)
Comment on lines -1596 to +1599

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DSSProjectSettings.add_exposed_object refactored with the following changes:

  • Use any() instead of for loop (use-any)


if not already_exists:
found_eo["rules"].append({"targetProject": target_project})
Expand Down
12 changes: 7 additions & 5 deletions dataikuapi/dssclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,12 @@ def create_cluster(self, cluster_name, cluster_type='manual', params=None):
:returns: A :class:`dataikuapi.dss.admin.DSSCluster` cluster handle

"""
definition = {}
definition['name'] = cluster_name
definition['type'] = cluster_type
definition['params'] = params if params is not None else {}
definition = {
'name': cluster_name,
'type': cluster_type,
'params': params if params is not None else {},
}

Comment on lines -594 to +599

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DSSClient.create_cluster refactored with the following changes:

resp = self._perform_json(
"POST", "/admin/clusters/", body=definition)
if resp is None:
Expand Down Expand Up @@ -705,7 +707,7 @@ def create_meaning(self, id, label, type, description=None,
:returns: A :class:`dataikuapi.dss.meaning.DSSMeaning` meaning handle
"""
def make_entry(v):
if isinstance(v, str) or isinstance(v, unicode):
if isinstance(v, (str, unicode)):
Comment on lines -708 to +710

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DSSClient.make_entry refactored with the following changes:

return {'value':v}
else:
return v
Expand Down