mirror of
https://github.com/cp2k/cp2k.git
synced 2026-07-27 21:55:16 -04:00
precommit: Add check for Python shebang
This commit is contained in:
parent
6c3d14b30c
commit
76e1f5a4cb
5 changed files with 11 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# vim: set ts=4 sw=4 tw=0 :
|
||||
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# vim: set ts=4 sw=4 tw=0 :
|
||||
|
||||
from distutils.core import setup
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# vim: set ts=4 sw=4 tw=0 :
|
||||
|
||||
import unittest
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
# author: Ole Schuett & Tiziano Müller
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
|
@ -125,6 +126,7 @@ def check_file(path: pathlib.Path) -> typing.List[str]:
|
|||
fn_ext = path.suffix
|
||||
abspath = path.resolve()
|
||||
basefn = path.name
|
||||
is_executable = os.access(abspath, os.X_OK)
|
||||
|
||||
if not PORTABLE_FILENAME_RE.match(str(path)):
|
||||
warnings += [f"Filename '{path}' not portable"]
|
||||
|
|
@ -155,6 +157,11 @@ def check_file(path: pathlib.Path) -> typing.List[str]:
|
|||
if fn_ext in C_EXTENSIONS and not content.startswith(BANNER_C.format(year, spdx)):
|
||||
warnings += [f"{path}: Copyright banner malformed"]
|
||||
|
||||
# check shebang
|
||||
PY_SHEBANG = "#!/usr/bin/env python3"
|
||||
if fn_ext == ".py" and is_executable and not content.startswith(f"{PY_SHEBANG}\n"):
|
||||
warnings += [f"{path}: Wrong shebang, please use '{PY_SHEBANG}'"]
|
||||
|
||||
# find all flags
|
||||
flags = set()
|
||||
line_continuation = False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue