Skip to content

Commit

Permalink
lib/parser: Apply standards to generated scripts (#2506)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
wenzeslaus authored Aug 5, 2022
1 parent 53b69fb commit fa88ff6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/gis/parser_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}

0 comments on commit fa88ff6

Please sign in to comment.