-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathpatch_keys.py
More file actions
58 lines (44 loc) · 1.52 KB
/
patch_keys.py
File metadata and controls
58 lines (44 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Patches @material/theme/_keys.scss to prevent build errors.
This script modifies the _keys.scss file within node_modules to replace
a specific error-throwing line with a return statement, working around
a build issue where duplicate links cause Sass compilation to fail.
Usage:
python patch_keys.py
"""
import pathlib
import sys
_SEARCH_STR = "@error '#{$key} already has a link';"
_REPLACE_STR = "@return $key;"
def _patch_file(file_path: pathlib.Path) -> None:
"""Patches the target file to replace the error string with a return string.
Args:
file_path: The path to the file to be patched.
Raises:
OSError: If reading or writing the file fails for reasons other than
FileNotFoundError.
"""
try:
with open(file_path, "r", encoding="utf-8") as f:
original_content = f.read()
except FileNotFoundError:
print(f"Warning: {file_path} not found")
return
if _SEARCH_STR not in original_content:
print(f"Warning: Search string not found in {file_path}. Already patched?")
return
patched_content = original_content.replace(_SEARCH_STR, _REPLACE_STR)
with open(file_path, "w", encoding="utf-8") as f:
f.write(patched_content)
print(f"Successfully patched {file_path}")
if __name__ == "__main__":
if len(sys.argv) > 1:
print("Error: Too many command-line arguments. Usage: python patch_keys.py")
sys.exit(1)
target = (
pathlib.Path(__file__).resolve().parent
/ "node_modules"
/ "@material"
/ "theme"
/ "_keys.scss"
)
_patch_file(target)