Skip to content

Commit

Permalink
.pytool/EccCheck: Open files in utf-8
Browse files Browse the repository at this point in the history
The EccCheck plugin currently fails if a file contains characters
outside the platform-dependent encoding returned from
locale.getencoding().

This change updates the encoding to utf-8 so the plugin is more
robust while continuing to support backward compatibility with the
ASCII range.

Signed-off-by: Michael Kubacki <[email protected]>
  • Loading branch information
makubacki committed Dec 13, 2024
1 parent 4855844 commit 9921b8f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .pytool/Plugin/EccCheck/EccCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def GetDiff(self, pkg: str, temp_diff_output: str) -> List[str]:
#
params = "diff --output={} --unified=0 origin/master HEAD".format(temp_diff_output)
RunCmd("git", params)
with open(temp_diff_output) as file:
with open(temp_diff_output, encoding='utf8') as file:
patch = file.read().strip().split('\n')
return patch

Expand All @@ -163,7 +163,7 @@ def GetModifyDir(self, pkg: str, temp_diff_output: str) -> List[str]:
params = "diff --output={} --diff-filter=dr --name-status origin/master HEAD".format(temp_diff_output)
RunCmd("git", params)
dir_list = []
with open(temp_diff_output) as file:
with open(temp_diff_output, encoding='utf8') as file:
dir_list = file.read().strip().split('\n')

modify_dir_list = []
Expand Down Expand Up @@ -271,7 +271,7 @@ def GetCommentRange(self, modify_file: str, temp_path: str) -> List[Tuple[int, i
modify_file_path = os.path.join(temp_path, modify_file)
if not os.path.exists (modify_file_path):
return comment_range
with open(modify_file_path) as f:
with open(modify_file_path, encoding='utf8') as f:
line_no = 1
Start = False
for line in f:
Expand Down Expand Up @@ -319,7 +319,7 @@ def ParseEccReport(self, ecc_diff_range: Dict[str, List[Tuple[int, int]]], temp_
row_lines = []
ignore_error_code = self.GetIgnoreErrorCode()
if os.path.exists(ecc_csv):
with open(ecc_csv) as csv_file:
with open(ecc_csv, encoding='utf8') as csv_file:
reader = csv.reader(csv_file)
for row in reader:
for modify_file in ecc_diff_range:
Expand Down

0 comments on commit 9921b8f

Please sign in to comment.