Skip to content

A GitHub Action which ensures Python code quality and supports customizable strictness.

License

Notifications You must be signed in to change notification settings

sunnysid3up/python-linter

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Linter

Ensure Python code quality. Supports mypy, pylint, black and isort.

Details

mypy

Mypy is an optional static type checker for Python. You can add type hints (PEP 484) to your Python programs, and use mypy to type check them statically. Find bugs in your programs without even running them!

pylint

Pylint is a Python static code analysis tool which looks for programming errors, helps to enforce a coding standard, sniffs for code smells and offers simple refactoring suggestions.

black

Black is the uncompromising Python code formatter. Black makes code review faster by producing the smallest diffs possible.

isort

isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections and by type.

Configuration

Options

Name Description Optional Default
source Source file or directory false "."
strict Set strictness for lint [low, medium, high] false "medium"
mypy-options Mypy options false ""
pylint-options Pylint options false ""
black-options Black options false ""
isort-options Isort options false ""
django Confirm if source is a Django project false false

Strictness

High

  • Must not have any type errors.
  • Must not have any code format issues.
  • Must not have import disorganization.
  • Must meet code standard style (PEP8). Code must have a Pylint score of 10.

Medium (default)

  • Must not have any type errors.
  • Must not have any code format issues.
  • Must not have import disorganization.
  • Code must have a Pylint score of 8 or greater.

Low

  • Must not have any type errors.
  • Must not have any code format issues.

(Optional) More pylint customization

Create a setup.cfg or a .pylintrc file in the current working directory.

[pylint]
ignore=
    migrations,
    manage.py,
    __init__.py,
    apps.py,
    admin.py,
    models.py,
    serializers.py,
    urls.py,
disable=
    import-error,
    missing-module-docstring,
    missing-function-docstring

(Optional) More isort customization

Create a setup.cfg or a .isort.cfg file in the current working directory.

[isort]
include_trailing_comma=True
known_first_party=app
lines_between_sections=0
lines_between_types=0
known_django=django
known_drf=rest_framework
line_length=100
multi_line_output=3
sections=FUTURE,STDLIB,DJANGO,DRF,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

Example

 steps:
 - uses: actions/checkout@v4
 - name: Python Linter
   uses: sunnysid3up/python-linter@master
   with:
     source: "src"
     mypy-options: "--ignore-missing-imports --show-error-codes"
     pylint-options: "--rcfile=setup.cfg"
     isort-options: "-w 100"
     django: true