-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_syntax.py
More file actions
42 lines (35 loc) · 1.15 KB
/
Copy pathcheck_syntax.py
File metadata and controls
42 lines (35 loc) · 1.15 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
#!/usr/bin/env python
"""
Script to check the syntax of dxf_meta_app.py
"""
import ast
import os
import sys
file_path = "src/gui/dxf_meta_app.py"
try:
# Read the content of the file
with open(file_path, 'r', encoding='utf-8') as f:
code = f.read()
# Parse the code to check for syntax errors
tree = ast.parse(code, filename=file_path)
print(f"File {file_path} has valid Python syntax")
except SyntaxError as e:
print(f"Syntax error in {file_path}:")
print(f" Line {e.lineno}, column {e.offset}")
print(f" {e.text.strip()}")
print(f" {' ' * (e.offset - 1)}^")
print(f" {e.msg}")
# Read the problematic section
with open(file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
# Display the context around the error
start_line = max(e.lineno - 5, 0)
end_line = min(e.lineno + 5, len(lines))
print("\nContext:")
for i in range(start_line, end_line):
prefix = ">" if i + 1 == e.lineno else " "
print(f"{prefix} {i+1}: {lines[i].rstrip()}")
sys.exit(1)
except Exception as e:
print(f"Error checking syntax: {str(e)}")
sys.exit(1)