1414
1515def default_values () -> dict :
1616 """Read default values out from the cookiecutter.json file."""
17- fn = os .path .join (os .path .dirname (__file__ ), ' template' , ' cookiecutter.json' )
17+ fn = os .path .join (os .path .dirname (__file__ ), " template" , " cookiecutter.json" )
1818
19- with open (fn , encoding = 'utf-8' ) as f :
20- return json .load (f )
19+ with open (fn , encoding = "utf-8" ) as f :
20+ data = json .load (f )
21+
22+ data ["frontend" ] = frontend .define_frontend (True , defaults = True )
23+
24+ return data
2125
2226
2327def gather_info (context : dict ) -> dict :
@@ -31,168 +35,163 @@ def gather_info(context: dict) -> dict:
3135 - Package name: The Python package name for the plugin (e.g., "custom_plugin").
3236 - Distribution name: The name used for the Python package distribution (e.g., "inventree-custom-plugin").
3337 """
34- info (' Enter project information:' )
38+ info (" Enter project information:" )
3539
3640 # Basic project information
37- context [' plugin_title' ] = (
41+ context [" plugin_title" ] = (
3842 questionary .text (
39- ' Enter plugin name' ,
40- default = context [' plugin_title' ],
43+ " Enter plugin name" ,
44+ default = context [" plugin_title" ],
4145 validate = validators .ProjectNameValidator ,
4246 )
4347 .ask ()
4448 .strip ()
4549 )
4650
47- context [' plugin_description' ] = (
51+ context [" plugin_description" ] = (
4852 questionary .text (
49- ' Enter plugin description' ,
50- default = context [' plugin_description' ],
53+ " Enter plugin description" ,
54+ default = context [" plugin_description" ],
5155 validate = validators .NotEmptyValidator ,
5256 )
5357 .ask ()
5458 .strip ()
5559 )
5660
57- context [' plugin_name' ] = context [' plugin_title' ].replace (' ' , '' )
61+ context [" plugin_name" ] = context [" plugin_title" ].replace (" " , "" )
5862
5963 # Convert the project name to a package name
6064 # e.g. 'Custom Plugin' -> 'custom_plugin'
61- context [' plugin_slug' ] = context [' plugin_title' ].replace (' ' , '-' ).lower ()
62- context [' package_name' ] = context [' plugin_slug' ].replace ('-' , '_' )
65+ context [" plugin_slug" ] = context [" plugin_title" ].replace (" " , "-" ).lower ()
66+ context [" package_name" ] = context [" plugin_slug" ].replace ("-" , "_" )
6367
6468 # Convert the package slug to a distribution name
6569 # e.g. 'custom-plugin' -> 'inventree-custom-plugin'
66- pkg = context [' plugin_slug' ]
70+ pkg = context [" plugin_slug" ]
6771
68- if not pkg .startswith (' inventree-' ):
69- pkg = f' inventree-{ pkg } '
72+ if not pkg .startswith (" inventree-" ):
73+ pkg = f" inventree-{ pkg } "
7074
71- context [' distribution_name' ] = pkg
75+ context [" distribution_name" ] = pkg
7276
7377 success (
7478 f"Generating plugin '{ context ['package_name' ]} ' - { context ['plugin_description' ]} "
7579 )
7680
77- info (' Enter author information:' )
81+ info (" Enter author information:" )
7882
79- context [' author_name' ] = (
83+ context [" author_name" ] = (
8084 questionary .text (
81- ' Author name' ,
82- default = context [' author_name' ],
85+ " Author name" ,
86+ default = context [" author_name" ],
8387 validate = validators .NotEmptyValidator ,
8488 )
8589 .ask ()
8690 .strip ()
8791 )
8892
89- context [' author_email' ] = (
90- questionary .text (' Author email' , default = context [' author_email' ]).ask ().strip ()
93+ context [" author_email" ] = (
94+ questionary .text (" Author email" , default = context [" author_email" ]).ask ().strip ()
9195 )
9296
93- context [' project_url' ] = (
94- questionary .text (' Project URL' , default = context [' project_url' ]).ask ().strip ()
97+ context [" project_url" ] = (
98+ questionary .text (" Project URL" , default = context [" project_url" ]).ask ().strip ()
9599 )
96100
97101 # Extract license information
98102 available_licences = list (license_pkg .iter ())
99103 license_keys = [lic .id for lic in available_licences ]
100104
101- context [' license_key' ] = questionary .select (
102- ' Select a license' , default = ' MIT' , choices = license_keys
105+ context [" license_key" ] = questionary .select (
106+ " Select a license" , default = " MIT" , choices = license_keys
103107 ).ask ()
104108
105- context [' license_text' ] = license_pkg .find (context [' license_key' ]).render (
106- name = context [' author_name' ], email = context [' author_email' ]
109+ context [" license_text" ] = license_pkg .find (context [" license_key" ]).render (
110+ name = context [" author_name" ], email = context [" author_email" ]
107111 )
108112
109113 # Plugin structure information
110- info (' Enter plugin structure information:' )
114+ info (" Enter plugin structure information:" )
111115
112116 plugin_mixins = mixins .get_mixins ()
113117
114- context [' plugin_mixins' ] = {' mixin_list' : plugin_mixins }
118+ context [" plugin_mixins" ] = {" mixin_list" : plugin_mixins }
115119
116120 # If we want to add frontend code support
117- if 'UserInterfaceMixin' in plugin_mixins :
118- context ['frontend' ] = {
119- 'enabled' : True ,
120- 'features' : frontend .select_features (),
121- 'translation' : frontend .enable_translation (),
122- }
123- else :
124- context ['frontend' ] = {'enabled' : False , 'features' : frontend .no_features ()}
121+ frontend_enabled = "UserInterfaceMixin" in plugin_mixins
122+
123+ context ["frontend" ] = frontend .define_frontend (frontend_enabled )
125124
126125 # Devops information
127- info (' Enter plugin devops support information:' )
126+ info (" Enter plugin devops support information:" )
128127
129- git_support = context [' git_support' ] = questionary .confirm (
130- ' Enable Git integration?' , default = True
128+ git_support = context [" git_support" ] = questionary .confirm (
129+ " Enable Git integration?" , default = True
131130 ).ask ()
132131
133- context [' ci_support' ] = devops .get_devops_mode () if git_support else ' None'
132+ context [" ci_support" ] = devops .get_devops_mode () if git_support else " None"
134133
135134 return context
136135
137136
138137def cleanup (plugin_dir : str , context : dict ) -> None :
139138 """Cleanup generated files after cookiecutter runs."""
140- info (' Cleaning up generated files...' )
139+ info (" Cleaning up generated files..." )
141140
142- devops .cleanup_devops_files (context [' ci_support' ], plugin_dir )
141+ devops .cleanup_devops_files (context [" ci_support" ], plugin_dir )
143142
144143 # Remove frontend code entirely if not enabled
145- if context [' frontend' ][ ' enabled' ]:
144+ if context [" frontend" ][ " enabled" ]:
146145 frontend .update_frontend (plugin_dir , context )
147146 else :
148147 frontend .remove_frontend (plugin_dir )
149148
150149 # Cleanup mixins
151150 mixins .cleanup_mixins (plugin_dir , context )
152151
153- if context [' git_support' ]:
152+ if context [" git_support" ]:
154153 devops .git_init (plugin_dir )
155154
156155
157156def main ():
158157 """Run plugin scaffolding."""
159- parser = argparse .ArgumentParser (description = ' InvenTree Plugin Creator Tool' )
158+ parser = argparse .ArgumentParser (description = " InvenTree Plugin Creator Tool" )
160159 parser .add_argument (
161- ' --default' ,
162- action = ' store_true' ,
163- help = ' Use default values for all prompts (non-interactive mode)' ,
160+ " --default" ,
161+ action = " store_true" ,
162+ help = " Use default values for all prompts (non-interactive mode)" ,
164163 )
165164 parser .add_argument (
166- ' --output' , action = ' store' , help = ' Specify output directory' , default = '.'
165+ " --output" , action = " store" , help = " Specify output directory" , default = "."
167166 )
168167 parser .add_argument (
169- ' --version' , action = ' version' , version = f' %(prog)s { PLUGIN_CREATOR_VERSION } '
168+ " --version" , action = " version" , version = f" %(prog)s { PLUGIN_CREATOR_VERSION } "
170169 )
171170
172171 args = parser .parse_args ()
173172
174- info (' InvenTree Plugin Creator Tool' )
173+ info (" InvenTree Plugin Creator Tool" )
175174
176175 context = default_values ()
177176 context .update (config .load_config ())
178177
179178 # Set version information
180- context [' plugin_creator_version' ] = PLUGIN_CREATOR_VERSION
179+ context [" plugin_creator_version" ] = PLUGIN_CREATOR_VERSION
181180
182181 if args .default :
183- info (' - Using default values for all prompts' )
182+ info (" - Using default values for all prompts" )
184183 else :
185184 context = gather_info (context )
186185
187- src_path = os .path .join (os .path .dirname (os .path .realpath (__file__ )), ' template' )
186+ src_path = os .path .join (os .path .dirname (os .path .realpath (__file__ )), " template" )
188187
189188 output_dir = os .path .abspath (args .output )
190- plugin_dir = os .path .join (output_dir , context [' plugin_name' ])
189+ plugin_dir = os .path .join (output_dir , context [" plugin_name" ])
191190
192191 # Save the user config
193192 config .save_config (context )
194193
195- info (' - output:' , plugin_dir )
194+ info (" - output:" , plugin_dir )
196195
197196 # Run cookiecutter template
198197 cookiecutter (
@@ -209,5 +208,5 @@ def main():
209208 success (f"Plugin created -> '{ plugin_dir } '" )
210209
211210
212- if __name__ == ' __main__' :
211+ if __name__ == " __main__" :
213212 main ()
0 commit comments