11from ..utils import DataikuException
22from .discussion import DSSObjectDiscussions
33import json , logging , warnings
4- import inspect
54
65#####################################################
76# Base classes
@@ -17,10 +16,6 @@ def __init__(self, client, project_key, recipe_name):
1716 self .project_key = project_key
1817 self .recipe_name = recipe_name
1918
20- @property
21- def name (self ):
22- return self .recipe_name
23-
2419 def compute_schema_updates (self ):
2520 """
2621 Computes which updates are required to the outputs of this recipe.
@@ -485,40 +480,6 @@ def _get_input_refs(self):
485480 ret .append (item ["ref" ])
486481 return ret
487482
488- def _get_output_refs (self ):
489- ret = []
490- for role_key , role_obj in self .recipe_proto ['outputs' ].items ():
491- for item in role_obj ['items' ]:
492- ret .append (item ['ref' ])
493- return ref
494-
495- def get_input_refs_for_role (self , role = "main" ):
496-
497- role_obj = self .recipe_proto ['inputs' ].get (role , None )
498-
499- ret = []
500- if role_obj is not None :
501- for item in role_obj ['items' ]:
502- ret .append (item ['ref' ])
503- return ret
504-
505- def get_output_refs_for_role (self , role = "main" ):
506-
507- role_obj = self .recipe_proto ['outputs' ].get (role , None )
508-
509- ret = []
510- if role_obj is not None :
511- for item in role_obj ['items' ]:
512- ret .append (item ['ref' ])
513- return ret
514-
515- def get_name (self ):
516- return self .recipe_proto ['name' ]
517-
518- def set_name (self , name ):
519- self .recipe_proto ['name' ] = name
520- return self
521-
522483 def with_input (self , dataset_name , project_key = None , role = "main" ):
523484 """
524485 Add an existing object as input to the recipe-to-be-created
@@ -545,23 +506,15 @@ def with_output(self, dataset_name, append=False, role="main"):
545506
546507 def build (self ):
547508 """Deprecated. Use create()"""
548- warnings .warn ("build() is deprecated, please use create()" , DeprecationWarning )
549509 return self .create ()
550510
551- def create (self , overwrite = False ):
511+ def create (self ):
552512 """
553513 Creates the new recipe in the project, and return a handle to interact with it.
554514
555515 Returns:
556516 A :class:`dataikuapi.dss.recipe.DSSRecipe` recipe handle
557517 """
558- if not overwrite and self .recipe_proto .get ('name' , None ):
559- recipe_name = self .recipe_proto ['name' ]
560- data = self .project .client ._perform_json (
561- "GET" , "/projects/%s/recipes/%s" % (self .project .project_key , recipe_name ))
562- if data :
563- raise Exception ("Recipe {} already exists, use overwrite=True to force delete" .format (recipe_name ))
564-
565518 self ._finish_creation_settings ()
566519 return self .project .create_recipe (self .recipe_proto , self .creation_settings )
567520
@@ -1087,18 +1040,6 @@ def with_script(self, script):
10871040 self .script = script
10881041 return self
10891042
1090- def with_input_list (self , input_ds_names , project_key = None , role = "main" ):
1091- if not isinstance (input_ds_names , list ):
1092- raise TypeError ("Expected type: list and was given type: {}" .format (type (input_ds_names )))
1093- for ds_name in input_ds_names :
1094- self .with_input (ds_name , project_key , role )
1095-
1096- def with_output_list (self , output_ds_names , append = False , role = "main" ):
1097- if not isinstance (output_ds_name , list ):
1098- raise TypeError ("Expected type: list and was givent type {}" .format (type (output_ds_names )))
1099- for ds_name in output_ds_names :
1100- self .with_output (ds_name , append , role )
1101-
11021043 def with_new_output_dataset (self , name , connection ,
11031044 type = None , format = None ,
11041045 copy_partitioning_from = "FIRST_INPUT" ,
@@ -1123,13 +1064,6 @@ def with_new_output_dataset(self, name, connection,
11231064 ch = self .project .new_managed_dataset_creation_helper (name )
11241065 ch .with_store_into (connection , type_option_id = type , format_option_id = format )
11251066
1126- if force_delete and ch .dataset_exists ():
1127- try :
1128- self .project .get_dataset (name ).delete ()
1129- except :
1130- logging .warn ("Force delete dataset {} in new_output_dataset creation failed" .format (name ))
1131- raise
1132-
11331067 # FIXME: can't manage input folder
11341068 if copy_partitioning_from == "FIRST_INPUT" :
11351069 inputs = self ._get_input_refs ()
@@ -1145,24 +1079,10 @@ def with_new_output_dataset(self, name, connection,
11451079 self .with_output (name , append = append )
11461080 return self
11471081
1148- def with_new_output_dataset_list (self , output_ds_names , connection ,
1149- type = None , format = None ,
1150- copy_partitioning_from = "FIRST_INPUT" ,
1151- append = False , force_delete = False ):
1152-
1153- if not isinstance (output_ds_names , list ):
1154- raise TypeError ("Expected type: list and was given type: {}" .format (type (output_ds_names )))
1155- for ds_name in output_ds_names :
1156- self .with_new_output_dataset (ds_name , connection ,
1157- type = type , format = format ,
1158- copy_partitioning_from = copy_partitioning_from ,
1159- append = append , force_delete = force_delete )
1160-
11611082 def _finish_creation_settings (self ):
11621083 super (CodeRecipeCreator , self )._finish_creation_settings ()
11631084 self .creation_settings ['script' ] = self .script
11641085
1165-
11661086class PythonRecipeCreator (CodeRecipeCreator ):
11671087 """
11681088 Creates a Python recipe.
@@ -1180,7 +1100,6 @@ def __init__(self, name, project):
11801100 DEFAULT_RECIPE_CODE_TMPL = """
11811101# This code is autogenerated by PythonRecipeCreator function mode
11821102import dataiku, dataiku.recipe, json
1183-
11841103from {module_name} import {fname}
11851104input_datasets = dataiku.recipe.get_inputs_as_datasets()
11861105output_datasets = dataiku.recipe.get_outputs_as_datasets()
@@ -1209,7 +1128,6 @@ def with_function_name(self, module_name, function_name, custom_template=None, *
12091128 """
12101129 Defines this recipe as being a functional recipe calling a function name from a module name
12111130 """
1212- #TODO add detailed documentation
12131131 script_tmpl = PythonRecipeCreator .DEFAULT_RECIPE_CODE_TMPL if custom_template is None else custom_template
12141132
12151133 if function_args is None :
0 commit comments