charasheet/tasks.py

121 lines
3.4 KiB
Python
Raw Permalink Normal View History

2022-10-28 22:16:23 +02:00
from pathlib import Path
2023-01-18 20:40:41 +01:00
from invoke import Context, task
2022-10-28 22:16:23 +02:00
BASE_DIR = Path(__file__).parent.resolve(strict=True)
SRC_DIR = BASE_DIR / "src"
COMPOSE_BUILD_FILE = BASE_DIR / "docker-compose-build.yaml"
COMPOSE_BUILD_ENV = {"COMPOSE_FILE": COMPOSE_BUILD_FILE}
TEST_ENV = {"ENV_FILE": BASE_DIR / "envs" / "test-envs.env"}
2022-12-10 01:00:10 +01:00
@task
2023-01-30 14:53:44 +01:00
def update_dependencies(ctx: Context, *, sync: bool = True):
return compile_dependencies(ctx, update=True, sync=sync)
@task
def compile_dependencies(ctx: Context, *, update: bool = False, sync: bool = False):
2023-07-17 22:16:16 +02:00
common_args = "-q --allow-unsafe"
2023-01-18 20:40:41 +01:00
if update:
common_args += " --upgrade"
2022-12-10 01:00:10 +01:00
with ctx.cd(BASE_DIR):
ctx.run(
2023-09-04 22:02:12 +02:00
f"pip-compile {common_args} --no-strip-extras requirements.in",
2022-12-10 01:00:10 +01:00
pty=True,
echo=True,
)
ctx.run(
f"pip-compile {common_args} --strip-extras -o constraints.txt requirements.in",
pty=True,
echo=True,
)
ctx.run(
2023-09-04 22:02:12 +02:00
f"pip-compile {common_args} --no-strip-extras requirements-dev.in",
2022-12-10 01:00:10 +01:00
pty=True,
echo=True,
)
2023-01-30 14:53:44 +01:00
if sync:
sync_dependencies(ctx)
2022-12-10 01:00:10 +01:00
2023-01-21 09:14:44 +01:00
@task
2023-01-30 14:53:44 +01:00
def sync_dependencies(ctx: Context):
with ctx.cd(BASE_DIR):
ctx.run("pip-sync requirements.txt requirements-dev.txt", pty=True, echo=True)
2023-01-21 09:14:44 +01:00
2022-10-28 22:16:23 +02:00
@task
2023-01-18 20:40:41 +01:00
def makemessages(ctx: Context):
2022-10-28 22:16:23 +02:00
with ctx.cd(SRC_DIR):
ctx.run("./manage.py makemessages -l en -l fr", pty=True, echo=True)
@task
2023-01-18 20:40:41 +01:00
def compilemessages(ctx: Context):
2022-10-28 22:16:23 +02:00
with ctx.cd(SRC_DIR):
ctx.run("./manage.py compilemessages -l en -l fr", pty=True, echo=True)
@task
2023-01-18 20:40:41 +01:00
def test(ctx: Context):
2022-10-28 22:16:23 +02:00
with ctx.cd(SRC_DIR):
ctx.run("pytest", pty=True, echo=True, env=TEST_ENV)
@task
2023-01-18 20:40:41 +01:00
def test_cov(ctx: Context):
2022-10-28 22:16:23 +02:00
with ctx.cd(SRC_DIR):
ctx.run(
"pytest --cov=. --cov-branch --cov-report term-missing:skip-covered",
pty=True,
echo=True,
env={"COVERAGE_FILE": BASE_DIR / ".coverage"},
)
@task
2023-01-18 20:40:41 +01:00
def download_db(ctx: Context):
2022-10-28 22:16:23 +02:00
with ctx.cd(BASE_DIR):
ctx.run(
"scp ubuntu:/mnt/data/charasheet/db/db.sqlite3 ./db/db.sqlite3",
pty=True,
echo=True,
)
ctx.run("rm -rf src/media/", pty=True, echo=True)
ctx.run(
2023-02-28 12:34:45 +01:00
"scp -r ubuntu:/mnt/data/charasheet/media/ ./src/media",
pty=True,
echo=True,
)
2022-10-28 22:16:23 +02:00
with ctx.cd(SRC_DIR):
ctx.run("./manage.py changepassword gaugendre", pty=True, echo=True)
@task
2023-01-18 20:40:41 +01:00
def dump_initial(ctx: Context):
with ctx.cd(SRC_DIR):
path = "./character/fixtures/initial_data.json"
ctx.run(
2022-11-01 09:28:48 +01:00
f"./manage.py dumpdata character --natural-primary --natural-foreign -e character.Character -o {path} --indent 2",
pty=True,
echo=True,
)
ctx.run(f"pre-commit run pretty-format-json --file {path}", pty=True, echo=True)
@task
2023-01-18 20:40:41 +01:00
def import_from_co_drs(ctx: Context):
with ctx.cd(SRC_DIR):
ctx.run("./manage.py import_races", pty=True, echo=True)
ctx.run("./manage.py import_profiles", pty=True, echo=True)
ctx.run("./manage.py import_paths", pty=True, echo=True)
ctx.run("./manage.py import_capabilities", pty=True, echo=True)
2022-11-02 21:41:06 +01:00
ctx.run("./manage.py import_harmful_states", pty=True, echo=True)
2022-11-02 22:07:33 +01:00
ctx.run("./manage.py import_weapons", pty=True, echo=True)
@task(pre=[import_from_co_drs, dump_initial])
2023-01-29 10:38:41 +01:00
def update_fixtures(_: Context):
pass