mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-13 00:00:23 +02:00
contrib: Remove confusing and redundant encoding from IO
The encoding arg is confusing, because it is not applied consistently for all IO. Also, it is useless, as the majority of files are ASCII encoded, which are fine to encode and decode with any mode. Moreover, UTF-8 is already required for most scripts to work properly, so setting the encoding twice is redundant. So remove the encoding from most IO. It would be fine to remove from all IO, however I kept it for two files: * contrib/asmap/asmap-tool.py: This specifically looks for utf-8 encoding errors, so it makes sense to sepecify the utf-8 encoding explicitly. * test/functional/test_framework/test_node.py: Reading the debug log in text mode specifically counts the utf-8 characters (not bytes), so it makes sense to specify the utf-8 encoding explicitly.
This commit is contained in:
@@ -185,7 +185,7 @@ def check_shebang_file_permissions(files_meta) -> int:
|
||||
|
||||
# *.py files which don't contain an `if __name__ == '__main__'` are not expected to be executed directly
|
||||
if file_meta.extension == "py":
|
||||
with open(filename, "r", encoding="utf8") as f:
|
||||
with open(filename, "r") as f:
|
||||
file_data = f.read()
|
||||
if not re.search("""if __name__ == ['"]__main__['"]:""", file_data):
|
||||
continue
|
||||
|
||||
@@ -71,7 +71,7 @@ def main():
|
||||
|
||||
regex_pattern = f'^#(ifndef|define|endif //) {header_id}'
|
||||
|
||||
with open(header_file, 'r', encoding='utf-8') as f:
|
||||
with open(header_file, 'r') as f:
|
||||
header_file_contents = f.readlines()
|
||||
|
||||
count = 0
|
||||
|
||||
@@ -40,13 +40,13 @@ EXPECTED_BOOST_INCLUDES = [
|
||||
|
||||
|
||||
def get_toplevel():
|
||||
return check_output(["git", "rev-parse", "--show-toplevel"], text=True, encoding="utf8").rstrip("\n")
|
||||
return check_output(["git", "rev-parse", "--show-toplevel"], text=True).rstrip("\n")
|
||||
|
||||
|
||||
def list_files_by_suffix(suffixes):
|
||||
exclude_args = [":(exclude)" + dir for dir in EXCLUDED_DIRS]
|
||||
|
||||
files_list = check_output(["git", "ls-files", "src"] + exclude_args, text=True, encoding="utf8").splitlines()
|
||||
files_list = check_output(["git", "ls-files", "src"] + exclude_args, text=True).splitlines()
|
||||
|
||||
return [file for file in files_list if file.endswith(suffixes)]
|
||||
|
||||
@@ -68,7 +68,7 @@ def find_included_cpps():
|
||||
included_cpps = list()
|
||||
|
||||
try:
|
||||
included_cpps = check_output(["git", "grep", "-E", r"^#include [<\"][^>\"]+\.cpp[>\"]", "--", "*.cpp", "*.h"], text=True, encoding="utf8").splitlines()
|
||||
included_cpps = check_output(["git", "grep", "-E", r"^#include [<\"][^>\"]+\.cpp[>\"]", "--", "*.cpp", "*.h"], text=True).splitlines()
|
||||
except CalledProcessError as e:
|
||||
if e.returncode > 1:
|
||||
raise e
|
||||
@@ -82,7 +82,7 @@ def find_extra_boosts():
|
||||
exclusion_set = set()
|
||||
|
||||
try:
|
||||
included_boosts = check_output(["git", "grep", "-E", r"^#include <boost/", "--", "*.cpp", "*.h"], text=True, encoding="utf8").splitlines()
|
||||
included_boosts = check_output(["git", "grep", "-E", r"^#include <boost/", "--", "*.cpp", "*.h"], text=True).splitlines()
|
||||
except CalledProcessError as e:
|
||||
if e.returncode > 1:
|
||||
raise e
|
||||
@@ -105,7 +105,7 @@ def find_quote_syntax_inclusions():
|
||||
quote_syntax_inclusions = list()
|
||||
|
||||
try:
|
||||
quote_syntax_inclusions = check_output(["git", "grep", r"^#include \"", "--", "*.cpp", "*.h"] + exclude_args, text=True, encoding="utf8").splitlines()
|
||||
quote_syntax_inclusions = check_output(["git", "grep", r"^#include \"", "--", "*.cpp", "*.h"] + exclude_args, text=True).splitlines()
|
||||
except CalledProcessError as e:
|
||||
if e.returncode > 1:
|
||||
raise e
|
||||
@@ -120,7 +120,7 @@ def main():
|
||||
|
||||
# Check for duplicate includes
|
||||
for filename in list_files_by_suffix((".cpp", ".h")):
|
||||
with open(filename, "r", encoding="utf8") as file:
|
||||
with open(filename, "r") as file:
|
||||
include_list = [line.rstrip("\n") for line in file if re.match(r"^#include", line)]
|
||||
|
||||
duplicates = find_duplicate_includes(include_list)
|
||||
@@ -148,13 +148,13 @@ def main():
|
||||
if extra_boosts:
|
||||
for boost in extra_boosts:
|
||||
print(f"A new Boost dependency in the form of \"{boost}\" appears to have been introduced:")
|
||||
print(check_output(["git", "grep", boost, "--", "*.cpp", "*.h"], text=True, encoding="utf8"))
|
||||
print(check_output(["git", "grep", boost, "--", "*.cpp", "*.h"], text=True))
|
||||
exit_code = 1
|
||||
|
||||
# Check if Boost dependencies are no longer used
|
||||
for expected_boost in EXPECTED_BOOST_INCLUDES:
|
||||
try:
|
||||
check_output(["git", "grep", "-q", r"^#include <%s>" % expected_boost, "--", "*.cpp", "*.h"], text=True, encoding="utf8")
|
||||
check_output(["git", "grep", "-q", r"^#include <%s>" % expected_boost, "--", "*.cpp", "*.h"], text=True)
|
||||
except CalledProcessError as e:
|
||||
if e.returncode > 1:
|
||||
raise e
|
||||
|
||||
@@ -219,7 +219,7 @@ def find_locale_dependent_function_uses():
|
||||
git_grep_output = list()
|
||||
|
||||
try:
|
||||
git_grep_output = check_output(git_grep_command, text=True, encoding="utf8").splitlines()
|
||||
git_grep_output = check_output(git_grep_command, text=True).splitlines()
|
||||
except CalledProcessError as e:
|
||||
if e.returncode > 1:
|
||||
raise e
|
||||
|
||||
@@ -41,7 +41,7 @@ def main():
|
||||
if re.search('src/(secp256k1|minisketch)/', file_path):
|
||||
continue
|
||||
|
||||
with open(file_path, 'r', encoding='utf-8') as file_obj:
|
||||
with open(file_path, 'r') as file_obj:
|
||||
contents = file_obj.read()
|
||||
|
||||
non_comment_pattern = re.compile(r'^\s*((?!#).+)$', re.MULTILINE)
|
||||
|
||||
@@ -23,7 +23,7 @@ def grep_boost_fixture_test_suite():
|
||||
"src/test/**.cpp",
|
||||
"src/wallet/test/**.cpp",
|
||||
]
|
||||
return subprocess.check_output(command, text=True, encoding="utf8")
|
||||
return subprocess.check_output(command, text=True)
|
||||
|
||||
|
||||
def check_matching_test_names(test_suite_list):
|
||||
|
||||
Reference in New Issue
Block a user