feat(tools): Enforce utf-8 encoding with open() function

This commit is contained in:
Marek Fiala
2024-07-23 15:59:09 +02:00
parent ca961274f5
commit 2b0407eb2a
36 changed files with 117 additions and 137 deletions

View File

@@ -7,7 +7,6 @@
# It compares the priorities found in .c source files to the contents of system_init_fn.txt
# In case of an inconsistency, the script prints the differences found and returns with a
# non-zero exit code.
import difflib
import glob
import itertools
@@ -51,7 +50,7 @@ def main() -> None:
glob_iter = glob.glob(os.path.join(idf_path, 'components', '**', f'*.{extension}'), recursive=True)
source_files_iters.append(glob_iter)
for filename in itertools.chain(*source_files_iters):
with open(filename, 'r') as f_obj:
with open(filename, 'r', encoding='utf-8') as f_obj:
file_contents = f_obj.read()
if ESP_SYSTEM_INIT_FN_STR not in file_contents:
continue
@@ -86,7 +85,7 @@ def main() -> None:
# 3. Load startup entries list from STARTUP_ENTRIES_FILE, removing comments and empty lines
#
startup_entries_expected_lines = []
with open(os.path.join(idf_path, STARTUP_ENTRIES_FILE), 'r') as startup_entries_expected_file:
with open(os.path.join(idf_path, STARTUP_ENTRIES_FILE), 'r', encoding='utf-8') as startup_entries_expected_file:
for line in startup_entries_expected_file:
if line.startswith('#') or len(line.strip()) == 0:
continue