==== Overview ==== Python is the main language used in Autosubmit. This style guide is a list of //dos// and //don'ts// for Autosubmit code based on the [[https://google.github.io/styleguide/pyguide.html|Google's Python style guide]]. In order to format the code correctly you can use [[https://google.github.io/styleguide/google_python_style.vim|the settings file for Vim]] created by Google. ==== Variables, properties and accessor-setter methods ==== * Use public variables for accessing or setting data where accessor or setter methods would be trivial, avoiding the extra cost of function calls in Python. * Use properties for accessing or setting data where you would normally have used simple, lightweight accessor or setter methods. More about properties [[https://google.github.io/styleguide/pyguide.html#Properties|here]]. * Use accessor or setter methods where you would require heavy processing. ==== Python Language Rules ==== * Run [[http://www.pylint.org/|pylint]] over the code * **Tabnanny:** Tool to check tabs [[https://docs.python.org/3/library/tabnanny.html|tabnanny]]: * Command line: python -m tabnanny -v file.py * Code: import tabnanny tabnanny.check('file.py') ==== Python Style Rules ==== * Maximum line length is 120 characters. * Do not use parenthesis in return statements or conditional statements. * Indent your code blocks with 4 spaces. * Two blank lines between top-level definitions, one blank line between method definitions * Use doc strings for module, function, method, class and attributes comments in the format explained [[https://google.github.io/styleguide/pyguide.html#Comments|here]] and in-line explanations using "#" for tricky or non-obvious operations. * If a class inherits from no other base classes, explicitly inherit from object. This also applies to nested classes. * Use TODO comments for code that is temporary, a short-term solution, or good-enough but not perfect. * Imports should be on separate lines. * Refer to https://google.github.io/styleguide/pyguide.html#Naming for naming rules and conventions.