Skip to content

Commit 544f165

Browse files
authored
Merge pull request #47 from dataiku/feature/project-settings-helpers
Helpers for setting various default settings on project settings
2 parents 6ccde56 + 54bbf31 commit 544f165

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

dataikuapi/dss/project.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,53 @@ def get_raw(self):
987987
"""
988988
return self.settings
989989

990+
def set_python_code_env(self, code_env_name):
991+
"""Sets the default Python code env used by this project
992+
993+
:param str code_env_name: Identifier of the code env to use. If None, sets the project to use the builtin Python env
994+
"""
995+
if code_env_name is None:
996+
self.settings["settings"]["codeEnvs"]["python"]["useBuiltinEnv"] = True
997+
else:
998+
self.settings["settings"]["codeEnvs"]["python"]["useBuiltinEnv"] = False
999+
self.settings["settings"]["codeEnvs"]["python"]["envName"] = code_env_name
1000+
1001+
def set_r_code_env(self, code_env_name):
1002+
"""Sets the default R code env used by this project
1003+
1004+
:param str code_env_name: Identifier of the code env to use. If None, sets the project to use the builtin R env
1005+
"""
1006+
if code_env_name is None:
1007+
self.settings["settings"]["codeEnvs"]["r"]["useBuiltinEnv"] = True
1008+
else:
1009+
self.settings["settings"]["codeEnvs"]["r"]["useBuiltinEnv"] = False
1010+
self.settings["settings"]["codeEnvs"]["r"]["envName"] = code_env_name
1011+
1012+
def set_container_exec_config(self, config_name):
1013+
"""Sets the default containerized execution config used by this project
1014+
1015+
:param str config_name: Identifier of the containerized execution config to use. If None, sets the project to use local execution
1016+
"""
1017+
if config_name is None:
1018+
self.settings["settings"]["container"]["containerMode"] = "NONE"
1019+
else:
1020+
self.settings["settings"]["container"]["containerMode"] = "EXPLICIT_CONTAINER"
1021+
self.settings["settings"]["container"]["containerConf"] = config_name
1022+
1023+
def set_k8s_cluster(self, cluster, fallback_cluster=None):
1024+
"""Sets the Kubernetes cluster used by this project
1025+
1026+
:param str cluster: Identifier of the cluster to use. May use variables expansion. If None, sets the project
1027+
to use the globally-defined cluster
1028+
:param str fallback_cluster: Identifier of the cluster to use if the variable used for "cluster" does not exist
1029+
"""
1030+
if cluster is None:
1031+
self.settings["settings"]["k8sCluster"]["clusterMode"] = "INHERIT"
1032+
else:
1033+
self.settings["settings"]["k8sCluster"]["clusterMode"] = "EXPLICIT_CLUSTER"
1034+
self.settings["settings"]["k8sCluster"]["clusterId"] = cluster
1035+
self.settings["settings"]["k8sCluster"]["defaultClusterId"] = fallback_cluster
1036+
9901037
def set_cluster(self, cluster, fallback_cluster=None):
9911038
"""Sets the Hadoop/Spark cluster used by this project
9921039

0 commit comments

Comments
 (0)