There are a lot of ways to control the code quality, you have an option to put a hook on save file event and then apply black, isort, pylint or mypy, you can use a pre-commit on git to validate or fix the file on the fly too.
The problem is: it is very hard to maintain all your develop team having all of this configured. This will create the following situation: You get a task, change the code and put the famous if, simple thing, two lines of code, but when you apply your lint you change all the file. It happens because the guy who changed the file before you did not apply the lint and the last PR reviewer didn’t see the missing lint.
Now you have to open a PR with a lot of lints changes, your PR is more complex now.
You can solve this by creating a GitHub Action that triggers for all PRs and after that you apply the lints which you think necessary.
Let's create an Action to apply the following libs:
If you use a GitHub suggestion, which is used for preparing the pipe for Python, to install and to execute every lib, it will be more or less like this:
name:Python applicationon:[push]jobs:build:runs-on:ubuntu-lateststeps:-uses:actions/checkout@v1-name:Set up Python3.7uses:actions/setup-python@v1with:python-version:3.7-name:Install dependenciesrun:|python -m pip install --upgrade pippip install -r requirements.txt-name:Lint with flake8run:|pip install flake8# stop the build if there are Python syntax errors or undefined namesflake8 . --count --select=E9,F63,F7,F82 --show-source --statistics# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wideflake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics-name:Lint with pylintrun:|pip install pylintpylint ....-name:Lint with blackrun:|pip install blackblack ....-name:Lint with isortrun:|pip install isortisort ....-name:Lint with pycodestylerun:|pip install pycodestylepycodestyle ....-name:Lint with mypyrun:|pip install mypymypy ....
This was my first try, when I understood that I would need to create all the configuration for every microservice project, I realized that I would need to create my own action to abstract all those things.
Solution
To you apply the lint today, just use this action:python-lint.
On your project root dir, create a directory with the name .github, inside this create another directory with the name workflow and inside this last one create one file with the name lint.yml (you can use any name here), with the following content:
name:Python Linton:[pull_request]jobs:lint:runs-on:ubuntu-lateststeps:-uses:actions/checkout@v1-uses:ricardochaves/python-lint@test
How it works
name
- Just the action name in your projecton
- A list with all events that will trigger your action.runs-on
- It's the image where your job will runsteps
- It is what the job will execute. Here we will execute two steps, one for checkout your code and the other to apply the lint
Options
There are some options to use with this action
-uses:ricardochaves/python-lint@testwith:python-root-list:'python_alelotests'use-pylint:falseuse-pycodestyle:falseuse-flake8:falseuse-black:falseuse-mypy:falseuse-isort:false
You can pass a list with all directories where the files need to be tested and you can disable each lib.
Real World
Checkpython-alelo.
Top comments(1)

You can also usewemake-python-styleguide
as a pre-build github action.
It is the strictest python linter out there. It has a huge amount of style, semantic, and consistency rules inside.
Usage:
-name:wemake-python-styleguideuses:wemake-services/wemake-python-styleguide
Link:github.com/marketplace/actions/wem...
Docs:wemake-python-stylegui.de/en/lates...
wemake-services / wemake-python-styleguide
The strictest and most opinionated python linter ever!
wemake-python-styleguide
Welcome to the strictest and most opinionated python linter ever.
wemake-python-styleguide
is actually aflake8plugin withsome other plugins as dependencies.
Quickstart
pip install wemake-python-styleguide
You will also need to create asetup.cfg
file with theconfiguration.
We highly recommend to also use:
- flakehell for easy integration into alegacy codebase
- nitpick for sharing and validating configuration across multiple projects
Running
flake8 your_module.py
This app is still just good oldflake8
And it won't change your existing workflow.
See"Usage" sectionin the docs for examples and integrations.
We also supportGitHub Actions as first class-citizensTry it out!
What we are about
The ultimate goal of this project isto make all people writeexactly the samepython
code.
flake8 | pylint | black | mypy | wemake-python-styleguide | |
---|---|---|---|---|---|
Formats code? | |||||
Finds style issues? | |||||
Finds bugs? |
Give it a try!
For further actions, you may consider blocking this person and/orreporting abuse