Skip to content

Commit 2a9e5ce

Browse files
authored
Merge pull request #34 from ZLLentz/fix_encoding
FIX: encoding issues with files on windows, better error reporting on twincat-lineids-remover
2 parents f0d27cd + 745a5af commit 2a9e5ce

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525
files: \.(TcPOU|TcDUT|TcGVL)$
2626

2727
- repo: https://github.com/pcdshub/pre-commit-hooks.git
28-
rev: v1.7.0
28+
rev: v1.7.1
2929
hooks:
3030
- id: twincat-leading-tabs-remover
3131
- id: twincat-lineids-remover

forTwinCatRepos/.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
files: \.(TcPOU|TcDUT|TcGVL)$
1010

1111
- repo: https://github.com/pcdshub/pre-commit-hooks.git
12-
rev: v1.7.0
12+
rev: v1.7.1
1313
hooks:
1414
- id: twincat-leading-tabs-remover
1515
- id: twincat-lineids-remover

pre_commit_hooks/check_twincat_versions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def main(args=None):
7171
versions = {}
7272
pinned = {}
7373
for filename in args.filenames:
74-
with open(filename, "r") as file:
74+
with open(filename, "r", encoding="utf-8") as file:
7575
xml_content = file.read()
7676
versions[filename] = get_tc_version(xml_content)
7777
pinned[filename] = tc_version_pinned(xml_content)
@@ -86,10 +86,10 @@ def main(args=None):
8686
reason_msg = f"\nReason: {args.reason}" if args.reason else ""
8787
if args.fix:
8888
for filename in mismatched_files:
89-
with open(filename, "r") as file:
89+
with open(filename, "r", encoding="utf-8") as file:
9090
xml_content = file.read()
9191
fixed_content = fix_tc_version(xml_content, args.target_version)
92-
with open(filename, "w") as file:
92+
with open(filename, "w", encoding="utf-8") as file:
9393
file.write(fixed_content)
9494

9595
print(
@@ -116,10 +116,10 @@ def main(args=None):
116116
if mismatched_files:
117117
if args.fix:
118118
for filename in mismatched_files:
119-
with open(filename, "r") as file:
119+
with open(filename, "r", encoding="utf-8") as file:
120120
xml_content = file.read()
121121
fixed_content = fix_pinned_version(xml_content, args.pinned)
122-
with open(filename, "w") as file:
122+
with open(filename, "w", encoding="utf-8") as file:
123123
file.write(fixed_content)
124124
print(
125125
f"Fixed pinned state for:{itemize}{itemize.join(mismatched_files)}"

pre_commit_hooks/leading_tabs_remover.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def fix_file(filename, tab_width=TAB_WIDTH):
10-
with open(filename, "r") as fd:
10+
with open(filename, "r", encoding="utf-8") as fd:
1111
original_lines = fd.readlines()
1212
new_lines = []
1313
changed = False
@@ -24,7 +24,7 @@ def fix_file(filename, tab_width=TAB_WIDTH):
2424
new_lines.append(line)
2525
if changed:
2626
print(f"Fixing {filename}")
27-
with open(filename, "w") as fd:
27+
with open(filename, "w", encoding="utf-8") as fd:
2828
fd.write("".join(new_lines))
2929

3030

pre_commit_hooks/twincat_lineids_remover.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def fix_file(filename):
7-
with open(filename, "r") as fd:
7+
with open(filename, "r", encoding="utf-8") as fd:
88
original_lines = fd.readlines()
99
new_lines = []
1010
changed = False
@@ -17,7 +17,7 @@ def fix_file(filename):
1717

1818
if changed:
1919
print(f"Fixing {filename}")
20-
with open(filename, "w") as fd:
20+
with open(filename, "w", encoding="utf-8") as fd:
2121
fd.write("".join(new_lines))
2222

2323

@@ -26,11 +26,14 @@ def main(args=None):
2626
parser = argparse.ArgumentParser()
2727
parser.add_argument("filenames", nargs="*")
2828
args = parser.parse_args()
29+
filename = None
2930
try:
3031
for filename in args.filenames:
3132
fix_file(filename)
3233
return 0
3334
except Exception as exc:
35+
if filename is not None:
36+
print(f"Error while processing {filename}")
3437
print(exc)
3538
return 1
3639

0 commit comments

Comments
 (0)