File size: 1,467 Bytes
c922f8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Simple script to check app.py file length and syntax
"""
import os
import sys
import ast

def check_file(file_path):
    try:
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
            lines = content.splitlines()
            print(f"Total lines in {file_path}: {len(lines)}")
            
            # Try to parse the content to check for syntax errors
            try:
                ast.parse(content)
                print(f"✓ No syntax errors found in {file_path}")
            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}")
                
                # Print context around the error
                start_line = max(0, e.lineno - 5)
                end_line = min(len(lines), e.lineno + 5)
                print("\nContext around error:")
                for i in range(start_line, end_line):
                    line_marker = ">" if i + 1 == e.lineno else " "
                    print(f"{line_marker} {i+1:4d} | {lines[i]}")
                    
    except Exception as e:
        print(f"Error reading or parsing {file_path}: {e}")

if __name__ == "__main__":
    file_path = "app.py"
    if not os.path.exists(file_path):
        print(f"File not found: {file_path}")
        sys.exit(1)
        
    check_file(file_path)