restructure the project for packaging
This commit is contained in:
62
main_mock.py
62
main_mock.py
@@ -1,6 +1,5 @@
|
||||
"""
|
||||
Main entry point for the Airport Announcement System.
|
||||
This script starts both the backend API and the Streamlit frontend.
|
||||
Main entry point for the Airport Announcement System mock backend.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -21,27 +20,44 @@ def stream_output(process, prefix):
|
||||
def start_backend():
|
||||
"""Start the backend API server."""
|
||||
print("Starting backend API server...")
|
||||
backend_process = subprocess.Popen(
|
||||
[sys.executable, "-m", "uvicorn", "mock_backend.mock_api:app", "--host", "0.0.0.0", "--port", "7999", "--reload"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
bufsize=1 # Line buffered
|
||||
)
|
||||
|
||||
# Start a thread to stream the backend output
|
||||
backend_thread = threading.Thread(target=stream_output, args=(backend_process, "BACKEND"), daemon=True)
|
||||
backend_thread.start()
|
||||
|
||||
# Wait a moment to ensure the backend has started
|
||||
time.sleep(2)
|
||||
return backend_process
|
||||
try:
|
||||
# Add verbose output for debugging
|
||||
print("Current working directory:", os.getcwd())
|
||||
print("Python path:", sys.path)
|
||||
|
||||
backend_process = subprocess.Popen(
|
||||
[sys.executable, "-m", "uvicorn", "mock_backend.mock_api:app", "--host", "0.0.0.0", "--port", "7999", "--reload", "--log-level", "debug"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
bufsize=1 # Line buffered
|
||||
)
|
||||
|
||||
# Start a thread to stream the backend output
|
||||
backend_thread = threading.Thread(target=stream_output, args=(backend_process, "BACKEND"), daemon=True)
|
||||
backend_thread.start()
|
||||
|
||||
# Wait a moment to ensure the backend has started
|
||||
time.sleep(2)
|
||||
|
||||
# Try to ping the API to make sure it's up
|
||||
try:
|
||||
import requests
|
||||
response = requests.get("http://localhost:7999/groups", timeout=1)
|
||||
print(f"Backend API check: status code {response.status_code}")
|
||||
except Exception as e:
|
||||
print(f"Warning: Backend API check failed: {str(e)}")
|
||||
|
||||
return backend_process
|
||||
except Exception as e:
|
||||
print(f"Error starting backend: {str(e)}")
|
||||
raise
|
||||
|
||||
def start_frontend():
|
||||
"""Start the Streamlit frontend."""
|
||||
print("Starting Streamlit frontend...")
|
||||
frontend_process = subprocess.Popen(
|
||||
[sys.executable, "-m", "streamlit", "run", "auracaster-webui.py"],
|
||||
[sys.executable, "-m", "streamlit", "run", "./src/auracaster_webui/app.py"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
@@ -54,10 +70,8 @@ def start_frontend():
|
||||
|
||||
return frontend_process
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Ensure we're in the correct directory
|
||||
os.chdir(Path(__file__).parent)
|
||||
|
||||
def run_mock():
|
||||
"""Run the mock backend and frontend."""
|
||||
# Start the backend and frontend
|
||||
backend_process = start_backend()
|
||||
frontend_process = start_frontend()
|
||||
@@ -75,3 +89,7 @@ if __name__ == "__main__":
|
||||
backend_process.terminate()
|
||||
frontend_process.terminate()
|
||||
print("Shutdown complete.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
run_mock()
|
||||
|
||||
Reference in New Issue
Block a user