Add shebang notice to Python projects in Pyflakes linter?

280 Views Asked by At

Is there a way to add a notice, similar to a PEP8 notice, if the first line in a .py file isn't #!/usr/bin/env python3?

Like how if I have a line > 80 characters, it notifies me? I'd like that same type of reminder to add the shebang to the top:

enter image description here

1

There are 1 best solutions below

0
anthony sottile On

for what it's worth, most python files shouldn't have a shebang -- you only want that for executable scripts (you don't really want most library modules to be executable for example)

the only linter that I know of that attempts to handle this sort of thing is check-executables-have-shebangs from pre-commit-hooks -- this linter will alert you if an executable text file does not start with a shebang (it's not specific to python because the problem itself is not specific to python)

the linter itself isn't really useful outside of pre-commit however as it depends on the framework properly detecting "text files" and "has the executable bit set" -- there may be a sublime integration for the framework but I'm not familiar with it

disclaimer: I'm the author of pre-commit-hooks and pre-commit above (as well as one of the maintainers of pyflakes -- though the warning above is actually coming from pycodestyle)