Pylint Exit Code Converter
The pylint-exit
tool is designed to streamline your Continuous Integration (CI) workflows by converting Pylint messages into meaningful exit codes. This utility is invaluable for automating build processes and ensuring code quality standards are met before deployment.
Automate Pylint Message Handling
By mapping different Pylint message categories (like errors, warnings, refactors, conventions, usage, and fatal) to specific exit codes, you can precisely control your CI pipeline's behavior. This allows for granular control over build failures based on the severity of detected code quality issues.
Practical Usage Examples
Here are some common scenarios demonstrating how to use pylint-exit
:
Basic Conversion to Exit Codes
This command converts Pylint messages into predefined exit codes. For instance, errors will trigger an exit code of 1, warnings 2, and so on. This is useful for a quick setup where standard Pylint severities map directly to your CI's error handling.
# pylint-exit
# A tool to convert Pylint messages into exit codes for use in CI pipelines.
# Use `pylint-exit` to convert Pylint messages into exit codes
pylint-exit --error-exit-code=1 --warning-exit-code=2 --refactor-exit-code=3 --convention-exit-code=4 --usage-exit-code=5 --fatal-exit-code=6 pylint_output.txt
Error-Specific Exit Code
If you only want your CI pipeline to fail when Pylint reports errors, you can specify a dedicated exit code for errors only.
# Simple usage to trigger a specific exit code for errors only
pylint-exit --error-exit-code=1 pylint_output.txt
Customizing Exit Codes
You can assign custom numerical values to different message categories to align with your organization's specific CI conventions or error tracking systems.
# Setting custom exit codes for different message categories
pylint-exit --error-exit-code=10 --warning-exit-code=20 --refactor-exit-code=30 pylint_output.txt
Chaining Pylint and Exit Code Conversion
This example shows how to run Pylint, save its output to a file, and then immediately process that output with pylint-exit
. The &&
operator ensures that pylint-exit
only runs if the Pylint command was successful, and the exit code from pylint-exit
will determine the overall script's success or failure.
# Using `pylint-exit` with a Pylint run and chaining commands; exit if there are errors
pylint module_or_package | tee pylint_output.txt && pylint-exit --error-exit-code=1 pylint_output.txt
Understanding Output Files
In the provided examples, pylint_output.txt
represents a file where the standard output of a Pylint execution is stored. This is particularly useful when you are not directly piping Pylint's output to pylint-exit
or when you need to retain the Pylint report for other purposes.
Note: In these examples, pylint_output.txt
represents the file where you might have saved the output of a Pylint run if not directly chaining commands.