This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
generated from communitiesuk/funding-service-design-TEMPLATE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
68 lines (52 loc) · 2.27 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import venv
from pathlib import Path
from colored import attr, fg, stylize
from invoke import task
ECHO_STYLE = fg("light_gray") + attr("bold")
@task
def virtualenv(c):
if not os.getenv("VIRTUAL_ENV") and not Path(".venv").exists():
print(stylize("creating virtualenv at `.venv`", ECHO_STYLE))
venv.create("venv", with_pip=True)
c.virtual_env = Path(os.getenv("VIRTUAL_ENV", ".venv"))
venv_path = c.virtual_env.resolve() / "bin"
if not os.environ["PATH"].startswith(str(venv_path)):
print(stylize(f"entering virtualenv at `{c.virtual_env}`", ECHO_STYLE))
os.environ["PATH"] = f"{venv_path}:{os.getenv('PATH')}"
else:
print(stylize(f"In virtualenv at `{c.virtual_env}`", ECHO_STYLE))
# skip if dry run
if not c.config["run"].get("dry"):
# we want to be sure that we are going to use python/pip from the venv
which_python = Path(c.run("which python", hide=True).stdout.strip())
expected_python = c.virtual_env / "bin" / "python"
assert which_python.samefile(
expected_python
), f"expected `which python` to return {expected_python}, instead got {which_python}\nPATH={os.environ['PATH']}"
@task
def bootstrap_test_db(c, database_host="localhost"):
"""Create a clean database for testing"""
c.run(f"dropdb -h {database_host} --if-exists fsd_app_store_test")
print(
stylize(
f"fsd_app_store_test db dropped from {database_host}...",
ECHO_STYLE,
)
)
c.run(f"createdb -h {database_host} fsd_app_store_test")
print(stylize(f"fsd_app_store_test db created on {database_host}...", ECHO_STYLE))
# @task
# def seed_applications(c, database_host="localhost"):
# from flask import current_app
# account_id = "00000000-0000-0000-0000-000000000000"
# fund_id = ""
# round_id = ""
# language = "en"
# print("Available funds/rounds:")
# print(f"\tCOF:\t{UsefulConfig.COF_FUND_ID}")
# print(f"\t\tR2W1:\t{UsefulConfig.COF_ROUND_3_W1_ID}")
# fund_id = input("Enter fund ID: ")
# round_id = input("Enter round ID: ")
# app = seed_not_started_application(fund_id=fund_id, round_id=round_id, account_id=account_id, language=language)
# print(f"{app.id} - {app.reference} - {app.status}")