Title: Code and style checks for Python at Sublime Text
Slug: Code-and-style-checks-for-Python-at-Sublime-Text
Date: 2016-01-01 18:42:00
Author: Kartones
Lang: en
Tags: Tools, Python, Development
Description: Outlines the packages used for code and style checks for Python in Sublime Text, including SublimeLinter 3, PEP8, MyPy, Flake8, and Flake8Lint. Also explains how custom rules can be added under the pep8 section.

<p>As now I'm coding with Python (and learning it), here comes a similar post as <a href="https://blog.kartones.net/post/Code-and-style-checks-for-Ruby-at-Sublime-Text">the one I did for Ruby</a> but adapted. Basically I want to centralize my coding to use if possible just one IDE for every language and file, so while probably PyCharm is better (as usually JetBrains tools are awesome) I get more flexibility with Sublime Text. Here are the specific packages I use:
<ul>
    <li><a href="https://packagecontrol.io/installation">Package Control</a>: Plugin/package manager, required for the other components</li>
    <li><a href="http://sublimelinter.readthedocs.org/en/latest/">SublimeLinter 3</a>: Generic text linter for the editor. Required for the specific linters</li>
    <li><a href="https://www.python.org/dev/peps/pep-0008/">PEP8</a> (Style guide for Python coding): <font face="Courier New">pip install pep8</font></li>
    <li><a href="https://github.com/SublimeLinter/SublimeLinter-pep8">SublimeLinter-PEP8</a>: To have the PEP8 rules inside the editor</li>
    <li><a href="https://github.com/python/mypy#quick-start">MyPy</a> (Static type checker): <font face="Courier New">pip install mypy</font></li>
    <li><a href="https://github.com/fredcallaway/SublimeLinter-contrib-mypy">SublimeLinter-contrib-mypy</a>: To have the MyPy rules inside the editor (might conflict with PEP8 ones)</li>
</ul>
</p>
<p>Despite having a tox.ini pep8 configuration file, if you see Sublime ignoring you, you can force some configuration settings for any linter going to:</p>
<p><font face="Courier New">Preferences -&gt; Package Settings -&gt; SublimeLinter -&gt; Settings – User</font></p>
<p>And then adding custom rules under the <font face="Courier New">pep8</font> section, e.g.:</p> <p><font face="Courier New">"pep8": {<br>    "max-line-length": 120<br>}</font></p>
<p>For additional, more strict rules, I use:
<ul>
    <li><a href="https://pypi.python.org/pypi/flake8">Flake8</a> (another source code checker): <font face="Courier New">pip install flake8</font></li>
    <li><a href="https://github.com/SublimeLinter/SublimeLinter-flake8">SublimeLinter-Flake8</a>: Again, to integrate with Sublime</li>
    <li><a href="https://github.com/dreadatour/Flake8Lint">Flake8Lint</a>: I'm still comparing with previous one to see if I need both or just this one, but this is quite powerful and configurable, so definetly a must</li>
</ul>
</p>
<p>And that's all for now, if I add more interesting packages I'll update the post, and of course comments and suggestions are welcome.</p>