"""Development entry point for the Team Tryouts application. Usage (from the project root): python run.py Production uses Waitress, from the project root as well: python wsgi.py These two are the only entry points. app/app.py exposes the factory and nothing else. Environment variables: FLASK_DEBUG: 'true' turns on the reloader and the interactive debugger. Off by default — the Werkzeug debugger executes code submitted through the browser, so a process left running with it on is a remote shell. Opt in per session, never in a deployed .env. DEV_HOST: interface to bind (default 127.0.0.1, loopback only). DEV_PORT: port to listen on (default 5000). """ import os import sys # Ensure the project root is on sys.path so 'app' is importable as a package sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from app.app import create_app # noqa: E402 from app.extensions import db as _db # noqa: E402 from app.extensions import hash_password # noqa: E402 from app.local_postgres import start as start_local_pg # noqa: E402 from app.models import Admin, Coach, Manager, Player # noqa: E402 # ========================================================================== # Local PostgreSQL (development only) # ========================================================================== if os.getenv('LOCAL_PG', '').lower() == 'true': os.environ['DATABASE_URL'] = start_local_pg() # ========================================================================== if __name__ == '__main__': app = create_app() # --- Seed the database with default test users (idempotent) --------- with app.app_context(): if not Admin.query.first(): print('[INFO] Seeding database with default test users ...') users = [ Admin(username='admin', role='admin', full_name='Admin', email='admin@teampro.com'), Coach( username='coach', role='coach', full_name='Coach Test', email='coach@teampro.com', ), Manager( username='manager', role='manager', full_name='Manager Test', email='manager@teampro.com', ), Player( username='player', role='player', full_name='Player Test', email='player@teampro.com', ), ] for u in users: u.password_hash = hash_password('password') _db.session.add(u) _db.session.commit() print('[INFO] Seeded 4 default users (password for all: password).') # Seed default objective templates (idempotent) from app.routes.objectives import seed_default_templates seed_default_templates() debug_mode = os.getenv('FLASK_DEBUG', 'false').lower() == 'true' if debug_mode: app.logger.warning( 'Running in DEBUG mode with the Flask built-in server. The ' 'interactive debugger accepts code from the browser: do not ' 'leave this reachable from anywhere but this machine.' ) app.run( debug=debug_mode, host=os.getenv('DEV_HOST', '127.0.0.1'), port=int(os.getenv('DEV_PORT', 5000)), )