Skip to content

Commit 2697d98

Browse files
committed
Add debugging to identify import issues in Azure deployment
1 parent b9f121f commit 2697d98

1 file changed

Lines changed: 39 additions & 12 deletions

File tree

main.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,48 @@
44
import os
55
import sys
66

7-
# Add the current directory to Python path
8-
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
7+
# Add the current directory to Python path FIRST
8+
current_dir = os.path.dirname(os.path.abspath(__file__))
9+
sys.path.insert(0, current_dir)
910

10-
# Import after path setup to avoid linting issues
11-
from src.app import create_app # noqa: E402
12-
from src.models import db # noqa: E402
11+
print(f"Python path: {sys.path}")
12+
print(f"Current directory: {current_dir}")
13+
print(f"Files in current directory: {os.listdir(current_dir)}")
1314

14-
# Create Flask app
15-
app = create_app()
16-
17-
# Initialize database tables
18-
with app.app_context():
19-
db.create_all()
15+
try:
16+
# Import after path setup to avoid linting issues
17+
from src.app import create_app # noqa: E402
18+
from src.models import db # noqa: E402
19+
print("Imports successful")
20+
21+
# Create Flask app (this happens when Gunicorn imports this file)
22+
app = create_app()
23+
print("Flask app created successfully")
24+
25+
# Initialize database tables (this needs to happen when the module loads)
26+
try:
27+
with app.app_context():
28+
db.create_all()
29+
print("Database tables created successfully")
30+
except Exception as e:
31+
print(f"Database initialization error: {e}")
32+
33+
except ImportError as e:
34+
print(f"Import error: {e}")
35+
print(f"sys.path: {sys.path}")
36+
# Fallback: create a simple Flask app
37+
from flask import Flask
38+
app = Flask(__name__)
39+
40+
@app.route('/')
41+
def hello():
42+
return "Hello, deployment debugging!"
43+
44+
@app.route('/health')
45+
def health():
46+
return {"status": "healthy", "message": "Basic Flask app running"}
2047

2148
if __name__ == '__main__':
22-
# Get port from environment variable (Azure sets this as WEBSITES_PORT)
49+
# This only runs when executed directly, not through Gunicorn
2350
port = int(os.environ.get('WEBSITES_PORT', os.environ.get('PORT', 8000)))
2451
app.run(debug=False, host='0.0.0.0', port=port)

0 commit comments

Comments
 (0)