shebang-not-executable (EXE001)
派生自 flake8-executable linter。
作用
检查不可执行文件中是否存在 shebang 指令。
为什么这不好?
在 Python 中,shebang(也称为 hashbang)是脚本的第一行,用于指定应该用于运行脚本的解释器。
shebang 的存在表明文件旨在可执行。如果文件包含 shebang 但不可执行,则 shebang 具有误导性,或者文件缺少可执行位。
如果该文件是要执行的,请将可执行位添加到该文件(例如,chmod +x __main__.py
或 git update-index --chmod=+x __main__.py
)。
否则,请删除 shebang。
如果文件设置了可执行位(即,其权限模式与 0o111
相交),则该文件被视为可执行。因此,此规则仅适用于类 Unix 系统,并且不会在 Windows 或 WSL 上强制执行。