Merge #12972: Add python3 script shebang lint

2bff472992 [contrib] convert test-security-check to python3 (John Newbery)
958bf40489 add lint tool to check python3 shebang (practicalswift)

Pull request description:

  base58.py can executed by python3

Tree-SHA512: 30511204feefd4ccd5b4bf698fb88e516633e692dc95d31fe957b1c0c4879de25906355b28a5a0522171887315c8464a611e601ff00540db172d5bd463ee13d9
This commit is contained in:
MarcoFalke 2018-04-16 16:03:08 -04:00
commit 07825088f9
No known key found for this signature in database
GPG Key ID: D2EA4850E7528B25
2 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,11 @@
#!/bin/bash
# Shebang must use python3 (not python or python2)
EXIT_CODE=0
for PYTHON_FILE in $(git ls-files -- "*.py"); do
if [[ $(head -c 2 "${PYTHON_FILE}") == "#!" &&
$(head -n 1 "${PYTHON_FILE}") != "#!/usr/bin/env python3" ]]; then
echo "Missing shebang \"#!/usr/bin/env python3\" in ${PYTHON_FILE} (do not use python or python2)"
EXIT_CODE=1
fi
done
exit ${EXIT_CODE}

View File

@ -1,11 +1,10 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# Copyright (c) 2015-2017 The Bitcoin Core developers # Copyright (c) 2015-2017 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
''' '''
Test script for security-check.py Test script for security-check.py
''' '''
from __future__ import division,print_function
import subprocess import subprocess
import unittest import unittest
@ -22,7 +21,7 @@ def write_testcode(filename):
def call_security_check(cc, source, executable, options): def call_security_check(cc, source, executable, options):
subprocess.check_call([cc,source,'-o',executable] + options) subprocess.check_call([cc,source,'-o',executable] + options)
p = subprocess.Popen(['./security-check.py',executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) p = subprocess.Popen(['./security-check.py',executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
(stdout, stderr) = p.communicate() (stdout, stderr) = p.communicate()
return (p.returncode, stdout.rstrip()) return (p.returncode, stdout.rstrip())