If you've spent enough time in Python, then you're already familiar with the Style Guide for Python Code, also known as PEP 8. For those who have not seen it, or if you need a refresher, you can take a look at it here:
https://www.python.org/dev/peps/pep-0008/
There is also a guide to the Salt Coding Style, available at:
https://docs.saltstack.com/en/latest/topics/development/conventions/style.html
In general, Salt coding conventions follow PEP 8, but there are some key differences:
Quoting: One of the first conventions that new developers come across is that Salt uses single quotes (') instead of double quotes ("). This applies to everything from string formatting to docstrings.
Line length: It is very common for code to restrict lines to no longer than 80 characters. This seems to be especially adhered to in Python, but it is based on an older convention where computer screens were exactly 80 characters wide. Because this is no longer the case, it is considered acceptable in Salt to expand to 120 characters, particularly if it helps with readability.
Tabs versus spaces: Salt uses four spaces for indentation. No tabs. No exceptions.
Salt makes extensive use of a program called Pylint to ensure that its code adheres to its style guide. You can find information about installing Pylint at:
Keep in mind that Salt currently uses Python 2 (the minimum version being 2.6), so if you're working in a distribution where both Python 2 and 3 versions of Pylint are available, make sure you use the Python 2 version.
The Salt code base ships with a .pylintrc
file to be used with Pylint. It doesn't get used by default, so you need to make sure to point it out to Pylint:
$ cd /path/to/salt $ pylint --rcfile=.pylintrc
Not only will this file allow you to check your code against Salt style guidelines but also to check the entire code base at once. This is important, because the loader inserts variables into modules that wouldn't be picked up otherwise by Pylint.