SDK Development


Discuss and develop the mbed SDK.

You are viewing an older revision! See the latest version

mbed sdk python coding styles

Rationale

Some of our tools in workspace_tools are written in Python 2.7. In case of developing tools for python we prefer to keep similar code styles across all Python source code. Please note that not all rules must be enforced. For example we do not limit you to 80 characters per line, just be sure your code can fit to widescreen display.

Coding guidelines

Please stay compatible with Python 2.7 but nothing stops you to write your code so in the future it will by Python 3 friendly.

Please check our Python source code (especially test_api.py and singletest.py) to get notion of how your new code should look like). We know our code is not perfect but please try to fit the same coding style to existing code so source looks consistent and is not series of different flavors.

Static Code Analizers for Python

If you are old-school developer for sure you remember tools like lint. "lint was the name originally given to a particular program that flagged some suspicious and non-portable constructs (likely to be bugs) in C language source code." Now lint-like programs are used to check similar code issues for multiple languages, also for Python. Please do use them if you want to commit new code to workspace_tools and other mbed SDK Python tooling.

Below is the list Python lint tools you may want to use:

  • pyflakes - Please scan your code with pyflakes and remove all issues reported by it. If you are unsure if something should be modified or not you can skip lint report related fix and report this issue as possible additional commit in your pull request description.
  • pylint - Please scan your code with pylint and check if there are any issues which can be resolved and are obvious "to fix" bugs. For example you may forgot to add 'self' as first parameter in class method parameter list or you are calling unknown functions / functions from not imported modules.
  • pychecker - optional, but more the merrier ;)

All wikipages