def project(name, database=None, driver=None): if argv.list_projects: print(f"{name}") return if argv.project and name != argv.project: return print(f"\x1b[2m # {name}\x1b[0m") env = {} cwd = path.join(dir_workspace, "examples", name) if database is not None: database_url = start_database(driver, database, cwd=cwd) env["DATABASE_URL"] = database_url # show the database url print(f"\x1b[94m @ {database_url}\x1b[0m") # database drop (if exists) sqlx("db drop -y", database_url, cwd=cwd) # database create sqlx("db create", database_url, cwd=cwd) # migrate sqlx("migrate run", database_url, cwd=cwd) # check run("cargo check", cwd=cwd, env=env)
def run(command, comment=None, env=None, service=None, tag=None, args=None, database_url_args=None): if argv.list_targets: if tag: print(f"{tag}") return if argv.target and not tag.startswith(argv.target): return if argv.target_exact and tag != argv.target_exact: return if comment is not None: print(f"\x1b[2m # {comment}\x1b[0m") environ = env or {} if service is not None: database_url = start_database( service, database="sqlite/sqlite.db" if service == "sqlite" else "sqlx", cwd=dir_tests) if database_url_args: database_url += "?" + database_url_args environ["DATABASE_URL"] = database_url # show the database url print(f"\x1b[94m @ {database_url}\x1b[0m") command_args = [] if argv.test: command_args.extend(["--test", argv.test]) if unknown: command_args.extend(["--", *unknown]) if args is not None: command_args.extend(args) print(f"\x1b[93m $ {command} {' '.join(command_args)}\x1b[0m") cwd = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) res = subprocess.run( [*command.split(" "), *command_args], env=dict(**os.environ, **environ), cwd=cwd, ) if res.returncode != 0: sys.exit(res.returncode)