Setting Up PEP8 and Pylint on VS Code

Formatting Python Code to pass the Maintainability test can be hard; especially if you are not receiving some help. It’s in human nature to get tired of redundancy, we easily want to get the job done quickly and move on. However, this affects our work output and the quality of our work. When it comes to code quality it’s paramount to maintain standards, there’s no better way to do so than to follow some already set standards.

PEP8 defines Python coding standards; from variable declaration to formatting of classes. It has it all, this allows you to nicely format your python code. To install the package ensure you are in your project folder and virtualenv is enabled, if not run the following lines in your folder directory



$ virtualenv env

$ source env/bin/activate



Enter fullscreen mode Exit fullscreen mode

Then install PEP8



$ pip install pep8


Enter fullscreen mode Exit fullscreen mode

Now let’s checkout Pylint, this tool checks whether we follow PEP8 standards and returns errors where we fail to follow. Furthermore, this tool also does error checking due to syntax errors. To install pylint run the following code;



$ pip install pylint


Enter fullscreen mode Exit fullscreen mode

Since we now have the two needed tools we can now open vs code



$ code .


Enter fullscreen mode Exit fullscreen mode

Once we open our vs code editor; we can select our preferred interpreter, just press
Ctrl + Shift + P.
图片[1]-Setting Up PEP8 and Pylint on VS Code - 拾光赋-拾光赋
You should see something similar to the above result. Next we select our Python Interpreter
图片[2]-Setting Up PEP8 and Pylint on VS Code - 拾光赋-拾光赋
Just select the python3/2 with virtualenv enabled. This will ensure that Vs code picks up tools we installed in virtual env.

Next we finally activate linting on Vs code.
Follow the following steps
File > Preferences > Settings > Workspace Settings > Python Configuration
Click Edit in settings.json

图片[3]-Setting Up PEP8 and Pylint on VS Code - 拾光赋-拾光赋
Your workspace should match the above linting settings. After editing your json save the settings and start coding. Now everytime you access Vs Code in virtaulenv it will always activate linting.

原文链接:Setting Up PEP8 and Pylint on VS Code

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容