Flake8 Executable Plugin
flake8-executable (v2.1.3) is a Flake8 plugin designed to enforce best practices for executable files, checking for correct shebangs and file permissions. It integrates seamlessly with the Flake8 linter, providing automated checks that help maintain code quality and prevent common script execution issues. The library is actively maintained, with releases primarily focused on Python version compatibility and bug fixes.
Common errors
-
flake8: command not found
cause The `flake8` command-line tool is not installed or not in your system's PATH.fixInstall Flake8: `pip install flake8`. -
File has no shebang (EXE001)
cause flake8-executable detected a file that appears to be an executable (e.g., `chmod +x` was applied) but lacks a `#!` shebang line.fixAdd a shebang line to the top of the file (e.g., `#!/usr/bin/env python3` or `#!/bin/bash`). If the file is not meant to be executable, remove its executable permissions (`chmod -x filename`). -
Executable file is missing executable permission (EXE003)
cause A file with a shebang was detected, implying it should be executable, but it does not have the executable permission bit set.fixGrant executable permission to the file: `chmod +x filename`. If the file is not meant to be executable, remove the shebang line. -
flake8: error: unrecognized arguments: --check-executable
cause You are trying to explicitly enable flake8-executable with a command-line argument, but plugins are typically auto-detected and run by `flake8` without special flags.fixRemove the `--check-executable` (or similar) argument. Simply run `flake8` and the plugin will automatically apply its checks.
Warnings
- breaking Python 3.6 support was dropped in v2.1.2. Users on Python 3.6 will need to upgrade their Python version or use an older version of flake8-executable (<2.1.2).
- gotcha flake8-executable requires Flake8 to be installed and available in the same environment. It is a plugin, not a standalone tool. Running `flake8` without a working `flake8` installation will result in a 'command not found' or similar error.
- gotcha File detection for 'executable' can sometimes be broader than intended. For example, a file with a shebang but without executable permissions might still be flagged (EXE004) if it's not meant to be executable. Configure Flake8's `exclude` or `ignore` options in `pyproject.toml`, `setup.cfg`, or `.flake8` to manage these.
Install
-
pip install flake8-executable
Imports
- __version__
from flake8_executable import __version__
Quickstart
# 1. Install flake8 and flake8-executable pip install flake8 flake8-executable # 2. Create an example executable script (e.g., 'myscript.sh') # Note: This file should be marked as executable (e.g., chmod +x myscript.sh) # and have a shebang. # Example 'myscript.sh' content: # #!/bin/bash # echo "Hello from a script!" # 3. Run flake8 against your project # It will automatically detect and use flake8-executable. # Example with a specific file: # flake8 myscript.sh # Or to run on your current directory (assuming myscript.sh is there): # flake8 . # Expected output for a correctly configured script (no errors): # (No output) # If 'myscript.sh' had no shebang (EXE001) or wrong permissions (EXE003), # flake8 would report it.