diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/scripts/svg2cpp.py b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/scripts/svg2cpp.py index f505636c86..3b26cc4e47 100755 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/scripts/svg2cpp.py +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/scripts/svg2cpp.py @@ -296,7 +296,7 @@ if __name__ == "__main__": parser.add_argument('--layer', help='only include layers which have this string in their names') args = parser.parse_args() - f = open(args.filename, "r") + f = open(args.filename, "r", encoding='utf-8') data = f.read() # First pass to grab viewbox diff --git a/buildroot/bin/config.py b/buildroot/bin/config.py index 980c6ecc65..8d6cc5891a 100755 --- a/buildroot/bin/config.py +++ b/buildroot/bin/config.py @@ -16,7 +16,7 @@ def set(file_path, define_name, value): Returns True if the define was found and replaced, False otherwise. ''' # Read the contents of the file - with open(file_path, 'r') as f: + with open(file_path, 'r', encoding='utf-8') as f: content = f.readlines() modified = False @@ -32,7 +32,7 @@ def set(file_path, define_name, value): # Write the modified content back to the file only if changes were made if modified: - with open(file_path, 'w') as f: + with open(file_path, 'w', encoding='utf-8') as f: f.writelines(content) return True @@ -42,7 +42,7 @@ def add(file_path, define_name, value=""): ''' Insert a define on the first blank line in a file. ''' - with open(file_path, 'r') as f: + with open(file_path, 'r', encoding='utf-8') as f: content = f.readlines() # Prepend a space to the value if it's not empty @@ -59,7 +59,7 @@ def add(file_path, define_name, value=""): # If no blank line is found, append to the end content.append(f"#define {define_name}{value}\n") - with open(file_path, 'w') as f: + with open(file_path, 'w', encoding='utf-8') as f: f.writelines(content) def enable(file_path, define_name, enable=True): @@ -68,7 +68,7 @@ def enable(file_path, define_name, enable=True): Returns True if the define was found, False otherwise. ''' # Read the contents of the file - with open(file_path, 'r') as f: + with open(file_path, 'r', encoding='utf-8') as f: content = f.readlines() # Prepare the regex @@ -96,7 +96,7 @@ def enable(file_path, define_name, enable=True): # Write the modified content back to the file only if changes were made if modified: - with open(file_path, 'w') as f: + with open(file_path, 'w', encoding='utf-8') as f: f.writelines(content) return found diff --git a/buildroot/share/PlatformIO/scripts/config.py b/buildroot/share/PlatformIO/scripts/config.py index 980c6ecc65..8d6cc5891a 100755 --- a/buildroot/share/PlatformIO/scripts/config.py +++ b/buildroot/share/PlatformIO/scripts/config.py @@ -16,7 +16,7 @@ def set(file_path, define_name, value): Returns True if the define was found and replaced, False otherwise. ''' # Read the contents of the file - with open(file_path, 'r') as f: + with open(file_path, 'r', encoding='utf-8') as f: content = f.readlines() modified = False @@ -32,7 +32,7 @@ def set(file_path, define_name, value): # Write the modified content back to the file only if changes were made if modified: - with open(file_path, 'w') as f: + with open(file_path, 'w', encoding='utf-8') as f: f.writelines(content) return True @@ -42,7 +42,7 @@ def add(file_path, define_name, value=""): ''' Insert a define on the first blank line in a file. ''' - with open(file_path, 'r') as f: + with open(file_path, 'r', encoding='utf-8') as f: content = f.readlines() # Prepend a space to the value if it's not empty @@ -59,7 +59,7 @@ def add(file_path, define_name, value=""): # If no blank line is found, append to the end content.append(f"#define {define_name}{value}\n") - with open(file_path, 'w') as f: + with open(file_path, 'w', encoding='utf-8') as f: f.writelines(content) def enable(file_path, define_name, enable=True): @@ -68,7 +68,7 @@ def enable(file_path, define_name, enable=True): Returns True if the define was found, False otherwise. ''' # Read the contents of the file - with open(file_path, 'r') as f: + with open(file_path, 'r', encoding='utf-8') as f: content = f.readlines() # Prepare the regex @@ -96,7 +96,7 @@ def enable(file_path, define_name, enable=True): # Write the modified content back to the file only if changes were made if modified: - with open(file_path, 'w') as f: + with open(file_path, 'w', encoding='utf-8') as f: f.writelines(content) return found diff --git a/buildroot/share/PlatformIO/scripts/mc-apply.py b/buildroot/share/PlatformIO/scripts/mc-apply.py index 52d2ad6387..4f341b0065 100755 --- a/buildroot/share/PlatformIO/scripts/mc-apply.py +++ b/buildroot/share/PlatformIO/scripts/mc-apply.py @@ -25,7 +25,7 @@ def report_version(conf): print(k + ': ' + v) def write_opt_file(conf, outpath='Marlin/apply_config.sh'): - with open(outpath, 'w') as outfile: + with open(outpath, 'w', encoding='utf-8') as outfile: for key, val in conf.items(): if key in ('__INITIAL_HASH', 'VERSION'): continue @@ -49,7 +49,7 @@ def write_opt_file(conf, outpath='Marlin/apply_config.sh'): def back_up_config(name): # Back up the existing file before modifying it conf_path = 'Marlin/' + name - with open(conf_path, 'r') as f: + with open(conf_path, 'r', encoding='utf-8') as f: # Write a filename.bak#.ext retaining the original extension parts = conf_path.split('.') nr = '' @@ -59,7 +59,7 @@ def back_up_config(name): nr = 1 if nr == '' else nr + 1 continue - with open(bak_path, 'w') as b: + with open(bak_path, 'w', encoding='utf-8') as b: b.writelines(f.readlines()) break @@ -83,7 +83,7 @@ def main(): args = parser.parse_args() try: - infile = open(args.config_file, 'r') + infile = open(args.config_file, 'r', encoding='utf-8') except: print(f'No {args.config_file} found.') sys.exit(1) diff --git a/buildroot/share/PlatformIO/scripts/preflight-checks.py b/buildroot/share/PlatformIO/scripts/preflight-checks.py index 7ccf86c486..94b39927e0 100644 --- a/buildroot/share/PlatformIO/scripts/preflight-checks.py +++ b/buildroot/share/PlatformIO/scripts/preflight-checks.py @@ -78,7 +78,7 @@ if pioutil.is_pio_build(): modified_text = text.replace("BOTH(", "ALL(").replace("EITHER(", "ANY(") if text != modified_text: conf_modified = True - with open(conf_path, 'w') as file: + with open(conf_path, 'w', encoding="utf8") as file: file.write(modified_text) if conf_modified: diff --git a/buildroot/share/PlatformIO/scripts/schema.py b/buildroot/share/PlatformIO/scripts/schema.py index d23e5c4716..fcfae998c4 100755 --- a/buildroot/share/PlatformIO/scripts/schema.py +++ b/buildroot/share/PlatformIO/scripts/schema.py @@ -70,7 +70,7 @@ def group_options(schema): def load_boards(): bpath = Path("Marlin/src/core/boards.h") if bpath.is_file(): - with bpath.open() as bfile: + with bpath.open(encoding='utf-8') as bfile: boards = [] for line in bfile: if line.startswith("#define BOARD_"): diff --git a/buildroot/share/scripts/pinsformat.py b/buildroot/share/scripts/pinsformat.py index 0260d3174e..c1d88934b7 100755 --- a/buildroot/share/scripts/pinsformat.py +++ b/buildroot/share/scripts/pinsformat.py @@ -71,7 +71,7 @@ def format_pins(argv): file_text = sys.stdin.read() else: # Open and read the file src_file - with open(src_file, 'r') as rf: file_text = rf.read() + with open(src_file, 'r', encoding='utf-8') as rf: file_text = rf.read() if len(file_text) == 0: print('No text to process') @@ -80,7 +80,7 @@ def format_pins(argv): # Read from file or STDIN until it terminates filtered = process_text(file_text) if dst_file: - with open(dst_file, 'w') as wf: wf.write(filtered) + with open(dst_file, 'w', encoding='utf-8') as wf: wf.write(filtered) else: print(filtered) diff --git a/buildroot/share/scripts/validate_boards.py b/buildroot/share/scripts/validate_boards.py index 8d5650d6c6..0e4ae3351a 100755 --- a/buildroot/share/scripts/validate_boards.py +++ b/buildroot/share/scripts/validate_boards.py @@ -40,7 +40,7 @@ def boards_checks(argv): logmsg('Checking boards file:', src_file) # Open the file - with open(src_file, 'r') as f: + with open(src_file, 'r', encoding='utf-8') as f: lines = f.readlines() # Get the board names and numbers @@ -85,7 +85,7 @@ def boards_checks(argv): # Validate that pins.h has all the boards mentioned in it # pins_boards = [] - with open('Marlin/src/pins/pins.h', 'r') as f: + with open('Marlin/src/pins/pins.h', 'r', encoding='utf-8') as f: lines = f.readlines() if_count = 0 for line in lines: