lint: Do not allow locale dependent shell scripts
Bash is discouraged, and there was never a need to write locale dependent Bash. So remove the option and clarify that the LC_ALL settings enable UTF-8 mode in Python.
This commit is contained in:
1 file changed
+4
-10
@@ -1,22 +1,19 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright (c) 2018-2022 The Bitcoin Core developers
|
# Copyright (c) 2018-present 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.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Make sure all shell scripts are:
|
Make sure all shell scripts explicitly opt out of locale dependence using
|
||||||
a.) explicitly opt out of locale dependence using
|
"export LC_ALL=C" or "export LC_ALL=C.UTF-8", which also enables UTF-8 mode in
|
||||||
"export LC_ALL=C" or "export LC_ALL=C.UTF-8", or
|
Python. See: https://docs.python.org/3/library/os.html#python-utf-8-mode
|
||||||
b.) explicitly opt in to locale dependence using the annotation below.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
OPT_IN_LINE = '# This script is intentionally locale dependent by not setting \"export LC_ALL=C\"'
|
|
||||||
|
|
||||||
OPT_OUT_LINES = [
|
OPT_OUT_LINES = [
|
||||||
'export LC_ALL=C',
|
'export LC_ALL=C',
|
||||||
'export LC_ALL=C.UTF-8',
|
'export LC_ALL=C.UTF-8',
|
||||||
@@ -47,9 +44,6 @@ def main():
|
|||||||
with open(file_path, 'r', encoding='utf-8') as file_obj:
|
with open(file_path, 'r', encoding='utf-8') as file_obj:
|
||||||
contents = file_obj.read()
|
contents = file_obj.read()
|
||||||
|
|
||||||
if OPT_IN_LINE in contents:
|
|
||||||
continue
|
|
||||||
|
|
||||||
non_comment_pattern = re.compile(r'^\s*((?!#).+)$', re.MULTILINE)
|
non_comment_pattern = re.compile(r'^\s*((?!#).+)$', re.MULTILINE)
|
||||||
non_comment_lines = re.findall(non_comment_pattern, contents)
|
non_comment_lines = re.findall(non_comment_pattern, contents)
|
||||||
if not non_comment_lines:
|
if not non_comment_lines:
|
||||||
|
|||||||
Reference in new issue
Block a user