Use and enforce python3 shebangs in userscripts

See #6080
This commit is contained in:
Florian Bruhin 2021-01-28 16:04:55 +01:00
parent 38fec3726f
commit 8f9d07674c
5 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Behavior:

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Behavior:

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Executes python-readability on current page and opens the summary as new tab.
#

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Adds DuckDuckGo bang as searchengine.
#

View File

@ -313,14 +313,18 @@ def check_userscript_shebangs(_args: argparse.Namespace) -> bool:
continue
with sub.open('r', encoding='utf-8') as f:
shebang = f.readline()
shebang = f.readline().rstrip('\n')
assert shebang.startswith('#!'), shebang
binary = shebang.split()[0][2:]
shebang = shebang[2:]
binary = shebang.split()[0]
if binary not in ['/bin/sh', '/usr/bin/env']:
bin_name = pathlib.Path(binary).name
print(f"In {sub}, use #!/usr/bin/env {bin_name} instead of #!{binary}")
ok = False
elif shebang in ['/usr/bin/env python', '/usr/bin/env python2']:
print(f"In {sub}, use #!/usr/bin/env python3 instead of #!{shebang}")
ok = False
return ok