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:
54 files changed
+127
-128
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user