fix: replace sys.path.insert(0) with safe sys.path.append (issue #7)
- Append project root instead of inserting at position 0 - Prevents import shadowing of system packages - Check for duplicates before adding to sys.path - Add __init__.py to models package
This commit is contained in:
parent
b25fb3c1c6
commit
fde9ab9b39
7
main.py
7
main.py
@ -8,8 +8,11 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Add the current directory to Python path
|
# Ensure project root is in path for direct execution (python main.py)
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
# Use a set to avoid duplicates and don't insert at position 0 to avoid shadowing
|
||||||
|
_project_root = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
if _project_root not in sys.path:
|
||||||
|
sys.path.append(_project_root)
|
||||||
|
|
||||||
from cli.commands import handle_command
|
from cli.commands import handle_command
|
||||||
from cli.parser import parse_args, print_help
|
from cli.parser import parse_args, print_help
|
||||||
|
|||||||
0
models/__init__.py
Normal file
0
models/__init__.py
Normal file
Loading…
x
Reference in New Issue
Block a user