浏览代码

🔨 Fix configuration.py with encoding UTF-8 (#24719)

- Opening files with Windows-1252 encoding.
ButchMonkey 2 年前
父节点
当前提交
328f6d9aff
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 5 次插入5 次删除
  1. 5
    5
      buildroot/share/PlatformIO/scripts/configuration.py

+ 5
- 5
buildroot/share/PlatformIO/scripts/configuration.py 查看文件

10
     if verbose >= level: print(f"[config] {str}")
10
     if verbose >= level: print(f"[config] {str}")
11
 
11
 
12
 def config_path(cpath):
12
 def config_path(cpath):
13
-    return Path("Marlin", cpath)
13
+    return Path("Marlin", cpath, encoding='utf-8')
14
 
14
 
15
 # Apply a single name = on/off ; name = value ; etc.
15
 # Apply a single name = on/off ; name = value ; etc.
16
 # TODO: Limit to the given (optional) configuration
16
 # TODO: Limit to the given (optional) configuration
23
     # Find and enable and/or update all matches
23
     # Find and enable and/or update all matches
24
     for file in ("Configuration.h", "Configuration_adv.h"):
24
     for file in ("Configuration.h", "Configuration_adv.h"):
25
         fullpath = config_path(file)
25
         fullpath = config_path(file)
26
-        lines = fullpath.read_text().split('\n')
26
+        lines = fullpath.read_text(encoding='utf-8').split('\n')
27
         found = False
27
         found = False
28
         for i in range(len(lines)):
28
         for i in range(len(lines)):
29
             line = lines[i]
29
             line = lines[i]
46
 
46
 
47
         # If the option was found, write the modified lines
47
         # If the option was found, write the modified lines
48
         if found:
48
         if found:
49
-            fullpath.write_text('\n'.join(lines))
49
+            fullpath.write_text('\n'.join(lines), encoding='utf-8')
50
             break
50
             break
51
 
51
 
52
     # If the option didn't appear in either config file, add it
52
     # If the option didn't appear in either config file, add it
67
 
67
 
68
         # Prepend the new option after the first set of #define lines
68
         # Prepend the new option after the first set of #define lines
69
         fullpath = config_path("Configuration.h")
69
         fullpath = config_path("Configuration.h")
70
-        with fullpath.open() as f:
70
+        with fullpath.open(encoding='utf-8') as f:
71
             lines = f.readlines()
71
             lines = f.readlines()
72
             linenum = 0
72
             linenum = 0
73
             gotdef = False
73
             gotdef = False
79
                     break
79
                     break
80
                 linenum += 1
80
                 linenum += 1
81
             lines.insert(linenum, f"{prefix}#define {added} // Added by config.ini\n")
81
             lines.insert(linenum, f"{prefix}#define {added} // Added by config.ini\n")
82
-            fullpath.write_text('\n'.join(lines))
82
+            fullpath.write_text('\n'.join(lines), encoding='utf-8')
83
 
83
 
84
 # Fetch configuration files from GitHub given the path.
84
 # Fetch configuration files from GitHub given the path.
85
 # Return True if any files were fetched.
85
 # Return True if any files were fetched.

正在加载...
取消
保存