Pylint Exit Code Handler
Pylint-exit is a utility that wraps the `pylint` command, providing enhanced control over its exit codes. It allows users to define which `pylint` message types (e.g., errors, warnings, refactors) should result in a non-zero exit code, which is crucial for CI/CD pipelines. The current version is 1.2.0, with releases typically tied to significant `pylint` changes or feature additions.
Common errors
-
command not found: pylint-exit
cause `pylint-exit` is not installed or its installation directory is not in your system's PATH.fixInstall `pylint-exit` using `pip install pylint-exit`. If installed in a virtual environment, ensure the environment is activated. -
pylint-exit: error: unrecognized arguments: --fatal-message=E
cause You are attempting to use the `--fatal-message` argument with a version of `pylint-exit` older than 1.1.0.fixUpgrade `pylint-exit` to version 1.1.0 or newer: `pip install --upgrade pylint-exit`. -
FileNotFoundError: [Errno 2] No such file or directory: 'pylint'
cause `pylint-exit` acts as a wrapper around the `pylint` command, and `pylint` itself is not found in your system's PATH.fixInstall `pylint` separately using `pip install pylint`. Ensure `pylint` is available in the same environment where you are running `pylint-exit`.
Warnings
- gotcha Pylint-exit is a wrapper and requires 'pylint' to be installed separately in your environment. It does not install pylint as a dependency.
- gotcha The `--fatal-message` argument for fine-grained control over exit codes was introduced in `pylint-exit` version 1.1.0. Using this argument with older versions will result in an 'unrecognized arguments' error.
- gotcha Pylint-exit reconfigures `pylint`'s default exit behavior. If you have existing scripts or CI/CD pipelines that rely on `pylint`'s original exit codes, be aware that `pylint-exit` will alter them based on its configuration (e.g., `--fatal-message`).
Install
-
pip install pylint-exit
Quickstart
pip install pylint pylint-exit
# Create a sample file with pylint errors/warnings
with open('my_code.py', 'w') as f:
f.write('def my_func():\n x = 1 # Unused variable\n return x + "string" # Type error\n')
# Run pylint-exit, treating 'E' (Error) messages as fatal
print("\n--- Running pylint-exit (E fatal) ---")
import subprocess
result = subprocess.run(['pylint-exit', '--fatal-message=E', 'my_code.py'], capture_output=True, text=True)
print(f"Exit Code: {result.returncode}")
print(result.stdout)
print(result.stderr)
# Run pylint-exit, treating 'W' (Warning) messages as fatal (will fail for unused variable)
print("\n--- Running pylint-exit (W fatal) ---")
result = subprocess.run(['pylint-exit', '--fatal-message=W', 'my_code.py'], capture_output=True, text=True)
print(f"Exit Code: {result.returncode}")
print(result.stdout)
print(result.stderr)