The action-pylint GitHub Action package provides a comprehensive solution for linting Python code repositories. It comes pre-configured with a selection of popular Python linting tools and automatically generates a linting report during GitHub Action execution.
- black: An uncompromising Python code formatter.
- flake8: A versatile code checker for Python.
- mypy: A static type checker for Python.
- pycodestyle: A tool to check Python code against a style guide.
- pyflakes: A lightweight Python lint checker.
- pylint: A source code, bug, and quality checker for Python.
To use action-pylint in your workflow, include the following steps in your workflow YAML file:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
This configuration will set up your workflow to check out the repository, set up Python environment, and execute the action-pylint package for linting your Python code.
For more advanced usage and customization options, please refer below.
For more advanced usage scenarios, refer to the following sections. This action provides several inputs for customization:
You can specify which linting tool to use with the tool
input. The default tool used is flake8
. Here are examples of
how to specify different tools:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
tool: 'black'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
tool: 'flake8'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
tool: 'mypy'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
tool: 'pycodestyle'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
tool: 'pyflakes'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
tool: 'pylint'
You can specify the directory or file to perform the linting on using the path
input. The default path is .
(current
directory). Examples:
# Linting all Python files in the current directory
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
path: '.'
# Linting a specific Python file
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
path: 'test.py'
You can further customize the behavior of the action with the following inputs:
Specify the name for the linting report artifact using the artifact-name
input. The default name is lint-report
.
Example:
# Customize artifact name for flake8 report
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
artifact-name: 'flake8-report'
Enable or disable verbose mode with the verbose
input. This controls the amount of output generated during linting.
Default is true
. Example:
# Disable verbose mode for less output
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
verbose: 'false'
Control terminal colorization with the color
input. This feature enhances readability of the linting output. Default
is true
. Example:
# Disable colorization for plain text output in the terminal
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
color: 'false'
Enable or disable statistics in the linting report with the statistics
input. This provides insights into the code
quality based on the selected tool. Default is true
. Example:
# Disable statistics in the linting report for brevity
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
statistics: 'false'
You can pass additional arguments to the linting tool using the arguments
input. This allows for further customization
of the linting process.
# Additional arguments for flake8
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: coldsofttech/action-pylint@v1
with:
tool: 'flake8'
arguments: '--select E123,W456 --enable-extensions H111'
For configurations related to linting, please consult the documentation of the respective linting tool. You can create the required configuration file within the repository, and this linting action will automatically pick up the configuration accordingly.
- Create a
pyproject.toml
file in the root of your repository. - Add the configuration options like:
[tool.black]
line-length = 88
target-version = ['py37']
include = '\.pyi?$'
- For more details, refer to the black Configuration Documentation.
- Create a
.flake8
file in the root of your repository. - Add the configuration options like:
[flake8]
extend-ignore = E203
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist
max-complexity = 10
- For more details, refer to the flake8 Configuration Documentation.
- Create a
mypy.ini
file in the root of your directory. - Add the configuration options like:
[mypy]
warn_return_any = True
warn_unused_configs = True
[mypy-mycode.foo.*]
disallow_untyped_defs = True
[mypy-mycode.bar]
warn_return_any = False
[mypy-somelibrary]
ignore_missing_imports = True
- For more details, refer to the mypy Configuration Documentation.
- Create a
.pycodestyle
file in the root of your directory. - Add the configuration options like:
[pycodestyle]
count = False
ignore = E226,E302,E71
max-line-length = 160
statistics = True
- For more details, refer to the pycodestyle Configuration Documentation.
- Create a
pyproject.toml
file in the root of your directory. - Add the configuration options like:
[tool.pylint.main]
analyse-fallback-blocks = false
clear-cache-post-run = false
confidence = ["HIGH", "CONTROL_FLOW", "INFERENCE", "INFERENCE_FAILURE", "UNDEFINED"]
disable = ["bad-inline-option", "consider-using-augmented-assign", "deprecated-pragma", "file-ignored", "locally-disabled", "prefer-typing-namedtuple", "raw-checker-failed", "suppressed-message", "use-implicit-booleaness-not-comparison-to-string", "use-implicit-booleaness-not-comparison-to-zero", "use-symbolic-message-instead", "useless-suppression"]
enable = []
evaluation = "max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10))"
exit-zero = false
- For more details, refer to the pylint Configuration Documentation.
Please refer to the MIT License within the project for more detailed information about licensing. Additionally, consult the ADDITIONAL LICENSES file for licensing details pertaining to components used within this package.
We welcome contributing from the community! Whether you have ideas for new features, bug fixes, or enhancements, feel free to open an issue or submit a pull request on GitHub.