-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpatch.py
More file actions
46 lines (38 loc) · 1.68 KB
/
patch.py
File metadata and controls
46 lines (38 loc) · 1.68 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
from importlib import import_module
from pathlib import Path
def apply_patch():
try:
# Dynamically import the module and get its file path
try:
module = import_module('pyshexc.parser.ShExDocLexer')
except ModuleNotFoundError as e:
# Give a precise, actionable hint for installation in the active interpreter
print(
"Missing dependency: 'pyshexc' (PyShExC).\n"
"Install it in the same environment you're using to run this script.\n"
"Examples:\n"
" python -m pip install PyShExC\n"
" # or with uv: uv pip install PyShExC\n"
" # or poetry: poetry add PyShExC\n"
" # or conda: conda install -c conda-forge pyshexc\n"
)
return
file_path = Path(module.__file__)
if not file_path.exists():
raise FileNotFoundError(f"Could not find the file: {file_path}")
# Read the file content
file_content = file_path.read_text()
# Replace 'from typing.io import TextIO' with 'from typing import TextIO'
new_content = file_content.replace("from typing.io import TextIO", "from typing import TextIO")
# Only write if a change is needed
if new_content != file_content:
file_path.write_text(new_content)
print("Patch applied successfully!")
else:
print("No patch needed; target text not found (already patched or different version).")
except FileNotFoundError as e:
print(e)
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
apply_patch()