Earth Sciences

Earth Sciences Wiki

User Tools

Site Tools


tools:style_guides:python

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 Google's Python style guide.

In order to format the code correctly you can use 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 here.
  • Use accessor or setter methods where you would require heavy processing.

Python Language Rules

  • Run pylint over the code
  • Tabnanny: Tool to check tabs 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 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.
tools/style_guides/python.txt · Last modified: 2020/05/20 15:20 by msamso