| Server IP : 3.147.158.171 / Your IP : 216.73.216.216 Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.21 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /tsai/repo/api/app/utilities/ |
Upload File : |
"""
Environment utilities for handling MAMP paths and other environment configuration.
"""
import os
from typing import Optional
def get_mamp_env() -> Optional[dict]:
"""
Get an environment dict with MAMP paths prepended to PATH.
Reads MAMP_PHP_BIN and MAMP_MYSQL_BIN from environment variables.
Returns None on production (EC2) where MAMP doesn't exist.
Falls back gracefully if variables aren't set.
Returns:
dict: Copy of os.environ with MAMP paths prepended to PATH, or None if no MAMP paths configured.
"""
mamp_php_bin = os.getenv('MAMP_PHP_BIN')
mamp_mysql_bin = os.getenv('MAMP_MYSQL_BIN')
# If neither MAMP variable is set, we're likely on production
if not mamp_php_bin and not mamp_mysql_bin:
return None
# Build the MAMP paths string
mamp_paths = []
if mamp_php_bin:
mamp_paths.append(mamp_php_bin)
if mamp_mysql_bin:
mamp_paths.append(mamp_mysql_bin)
mamp_path_str = ':'.join(mamp_paths)
# Create a copy of the environment with MAMP paths prepended
env = os.environ.copy()
env['PATH'] = f"{mamp_path_str}:{env.get('PATH', '')}"
return env
def get_subprocess_env() -> dict:
"""
Get an environment dict suitable for subprocess calls.
Returns an environment with MAMP paths if available (local development),
or just a copy of the current environment (production).
Returns:
dict: Environment dict for subprocess calls.
"""
mamp_env = get_mamp_env()
return mamp_env if mamp_env is not None else os.environ.copy()