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
Then install PEP8
$ pip install pep8
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
Since we now have the two needed tools we can now open vs code
$ code .
Once we open our vs code editor; we can select our preferred interpreter, just press
Ctrl + Shift + P.
You should see something similar to the above result. Next we select our Python Interpreter
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
Edit in settings.json
Your workspace should match the above linting settings. After editing your json save the settings and start coding. Now every time you access Vs Code in virtaulenv it will always activate linting.