From fa88ff639580209a191443ae4161f8e4cdaf1b24 Mon Sep 17 00:00:00 2001 From: Vaclav Petras Date: Thu, 4 Aug 2022 22:57:21 -0400 Subject: [PATCH] lib/parser: Apply standards to generated scripts (#2506) The --script now generates code which complies with Black, Flake8 (except long lines), and Pylint (except line-too-long and unused-variable). The practice of calling main in sys.exit() and return 0 was removed (usually not needed in this context). Parser call is now in main, so the variables are not global anymore (and thus also follow the right naming practice). --- lib/gis/parser_script.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/gis/parser_script.c b/lib/gis/parser_script.c index affd8f792a8..fd95cd948f0 100644 --- a/lib/gis/parser_script.c +++ b/lib/gis/parser_script.c @@ -56,6 +56,8 @@ void G__script(void) fprintf(fp, "############################################################################\n\n"); + fprintf(fp, "\"\"\"Wraps %s to make it even better\"\"\"\n\n", G_program_name()); + fprintf(fp, "# %%module\n"); if (st->module_info.label) fprintf(fp, "# %% label: %s\n", st->module_info.label); @@ -134,12 +136,12 @@ void G__script(void) } } - fprintf(fp, "\nimport sys\n"); - fprintf(fp, "\nimport grass.script as gs\n"); + fprintf(fp, "\nimport grass.script as gs\n\n"); fprintf(fp, "\ndef main():"); - fprintf(fp, "\n # put code here\n"); - fprintf(fp, "\n return 0\n"); - fprintf(fp, "\nif __name__ == \"__main__\":"); + fprintf(fp, "\n \"\"\"Process command line parameters and run analysis\"\"\""); fprintf(fp, "\n options, flags = gs.parser()"); - fprintf(fp, "\n sys.exit(main())\n"); + fprintf(fp, "\n # Put your code here."); + fprintf(fp, "\n\n"); + fprintf(fp, "\nif __name__ == \"__main__\":"); + fprintf(fp, "\n main()\n"); }