@@ -66,7 +66,8 @@ class FunctionCall:
6666 """Contains the df.py content related function calls."""
6767
6868 function_name : str
69- argument_values : list [str ]
69+ args : list [str ]
70+ kwargs : dict [str , str ]
7071
7172
7273@dataclass
@@ -83,7 +84,8 @@ class ColumnChoice:
8384 """Choose columns based on a random number in [0,1)."""
8485
8586 function_name : str
86- argument_values : list [str ]
87+ args : list [str ]
88+ kwargs : dict [str , str ]
8789
8890
8991def make_column_choices (
@@ -100,7 +102,8 @@ def make_column_choices(
100102 return [
101103 ColumnChoice (
102104 function_name = mg ["name" ],
103- argument_values = [f"{ k } ={ v } " for k , v in mg .get ("kwargs" , {}).items ()],
105+ args = mg .get ("args" , []),
106+ kwargs = mg .get ("kwargs" , {}),
104107 )
105108 for mg in table_config .get ("missingness_generators" , [])
106109 if "name" in mg
@@ -168,12 +171,11 @@ def _get_function_call(
168171 if keyword_arguments is None :
169172 keyword_arguments = {}
170173
171- argument_values : list [str ] = [str (value ) for value in positional_arguments ]
172- argument_values += [
173- f"{ key } ={ _render_value (value )} " for key , value in keyword_arguments .items ()
174- ]
175-
176- return FunctionCall (function_name = function_name , argument_values = argument_values )
174+ return FunctionCall (
175+ function_name = function_name ,
176+ args = positional_arguments ,
177+ kwargs = keyword_arguments ,
178+ )
177179
178180
179181def _get_row_generator (
@@ -580,13 +582,29 @@ def make_vocabulary_tables(
580582 )
581583
582584
583- def make_table_generators ( # pylint: disable=too-many-locals
585+ @dataclass
586+ class GenerationInfo :
587+ """Information for the generation of all data."""
588+ provider_imports : list [str ]
589+ orm_file_name : Path
590+ config_file_name : Path
591+ row_generator_module_name : str | None
592+ story_generator_module_name : str | None
593+ object_instantiation : dict [str , dict ]
594+ src_stats_filename : Path | None
595+ tables : list [TableGeneratorInfo ]
596+ vocabulary_tables : list [VocabularyTableGeneratorInfo ]
597+ story_generators : list [StoryGeneratorInfo ]
598+ max_unique_constraint_tries : int | None
599+
600+
601+ def get_generation_info ( # pylint: disable=too-many-locals
584602 metadata : MetaData ,
585603 config : Mapping ,
586604 orm_filename : Path ,
587605 config_filename : Path ,
588606 src_stats_filename : Optional [Path ],
589- ) -> str :
607+ ) -> GenerationInfo :
590608 """
591609 Create datafaker generator classes.
592610
@@ -605,10 +623,16 @@ def make_table_generators( # pylint: disable=too-many-locals
605623
606624 :return: A string that is a valid Python module, once written to file.
607625 """
608- row_generator_module_name : str = config .get ("row_generators_module" , None )
609- story_generator_module_name = config .get ("story_generators_module" , None )
610- object_instantiation : dict [str , dict ] = config .get ("object_instantiation" , {})
611- tables_config = config .get ("tables" , {})
626+ row_generator_module_name = get_property (
627+ config , "row_generators_module" , str | None , None
628+ )
629+ story_generator_module_name = get_property (
630+ config , "story_generators_module" , str | None , None
631+ )
632+ object_instantiation = get_property (
633+ config , "object_instantiation" , dict , {}
634+ )
635+ tables_config = get_property (config , "tables" , dict , {})
612636
613637 tables : list [TableGeneratorInfo ] = []
614638 vocabulary_tables : list [VocabularyTableGeneratorInfo ] = []
@@ -637,20 +661,47 @@ def make_table_generators( # pylint: disable=too-many-locals
637661
638662 story_generators = _get_story_generators (config )
639663
640- max_unique_constraint_tries = config .get ("max-unique-constraint-tries" , None )
664+ max_unique_constraint_tries = get_property (
665+ config , "max-unique-constraint-tries" , str | None , None
666+ )
667+ return GenerationInfo (
668+ provider_imports = PROVIDER_IMPORTS ,
669+ orm_file_name = orm_filename ,
670+ config_file_name = config_filename ,
671+ row_generator_module_name = row_generator_module_name ,
672+ story_generator_module_name = story_generator_module_name ,
673+ object_instantiation = object_instantiation ,
674+ src_stats_filename = src_stats_filename ,
675+ tables = tables ,
676+ vocabulary_tables = vocabulary_tables ,
677+ story_generators = story_generators ,
678+ max_unique_constraint_tries = max_unique_constraint_tries ,
679+ )
680+
681+
682+ def make_table_generators ( # pylint: disable=too-many-locals
683+ metadata : MetaData ,
684+ config : Mapping ,
685+ orm_filename : Path ,
686+ config_filename : Path ,
687+ src_stats_filename : Optional [Path ],
688+ ) -> str :
689+ gi = get_generation_info (
690+ metadata , config , orm_filename , config_filename , src_stats_filename
691+ )
641692 return generate_df_content (
642693 {
643- "provider_imports" : PROVIDER_IMPORTS ,
644- "orm_file_name" : orm_filename ,
645- "config_file_name" : config_filename ,
646- "row_generator_module_name" : row_generator_module_name ,
647- "story_generator_module_name" : story_generator_module_name ,
648- "object_instantiation" : object_instantiation ,
649- "src_stats_filename" : src_stats_filename ,
650- "tables" : tables ,
651- "vocabulary_tables" : vocabulary_tables ,
652- "story_generators" : story_generators ,
653- "max_unique_constraint_tries" : max_unique_constraint_tries ,
694+ "provider_imports" : gi . provider_imports ,
695+ "orm_file_name" : gi . orm_file_name ,
696+ "config_file_name" : gi . config_file_name ,
697+ "row_generator_module_name" : gi . row_generator_module_name ,
698+ "story_generator_module_name" : gi . story_generator_module_name ,
699+ "object_instantiation" : gi . object_instantiation ,
700+ "src_stats_filename" : gi . src_stats_filename ,
701+ "tables" : gi . tables ,
702+ "vocabulary_tables" : gi . vocabulary_tables ,
703+ "story_generators" : gi . story_generators ,
704+ "max_unique_constraint_tries" : gi . max_unique_constraint_tries ,
654705 }
655706 )
656707
0 commit comments