locality/scripts/run.py

45 lines
1.0 KiB
Python

import os
import shutil
import subprocess
import time
from .postgres_container import PostgresContainer
ROOT_DIR = None
def cargo(*args):
global ROOT_DIR
with PostgresContainer() as postgres:
locality_env = {
'LOCALITY_DATABASE_URL': postgres.get_url(),
'LOCALITY_TEST_DATABASE_URL': postgres.get_url(),
'LOCALITY_STATIC_FILE_PATH': os.path.join(
ROOT_DIR,
'static'),
'LOCALITY_HMAC_SECRET': 'iknf4390-8guvmr3'
}
locality_env = os.environ.copy() | locality_env
cargo_bin = shutil.which('cargo')
locality_process = subprocess.Popen(
[cargo_bin, *args], env=locality_env, cwd=ROOT_DIR
)
try:
while locality_process.poll() is None:
time.sleep(0.5)
except KeyboardInterrupt:
pass
finally:
if locality_process.poll() is None:
locality_process.terminate()
def run(args):
cargo('run')
def unit_tests(args):
cargo("test")