checkout/tasks.py

109 lines
3.1 KiB
Python
Raw Normal View History

2022-04-24 15:51:25 +02:00
from pathlib import Path
from invoke import Context, task
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}
2023-03-25 20:01:14 +01:00
TEST_ENV = {"ENV_FILE": BASE_DIR / "envs" / "test-envs.env"}
@task
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:22:36 +02:00
common_args = "-q --allow-unsafe"
2023-03-25 20:01:14 +01:00
if update:
common_args += " --upgrade"
with ctx.cd(BASE_DIR):
ctx.run(
2023-09-04 22:07:13 +02:00
f"pip-compile {common_args} --no-strip-extras requirements.in",
2023-03-25 20:01:14 +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:07:13 +02:00
f"pip-compile {common_args} --no-strip-extras requirements-dev.in",
2023-03-25 20:01:14 +01:00
pty=True,
echo=True,
)
if sync:
sync_dependencies(ctx)
@task
def sync_dependencies(ctx: Context):
with ctx.cd(BASE_DIR):
ctx.run("pip-sync requirements.txt requirements-dev.txt", pty=True, echo=True)
2022-04-24 15:51:25 +02:00
2022-04-26 18:19:53 +02:00
@task
def makemessages(ctx: Context) -> None:
with ctx.cd(SRC_DIR):
2023-04-02 18:32:35 +02:00
ctx.run(
"./manage.py makemessages -l en -l fr --add-location file",
pty=True,
echo=True,
)
2022-04-26 18:19:53 +02:00
@task
def compilemessages(ctx: Context) -> None:
with ctx.cd(SRC_DIR):
ctx.run("./manage.py compilemessages -l en -l fr", pty=True, echo=True)
2023-03-25 20:32:44 +01:00
@task(pre=[compilemessages])
2022-04-24 15:51:25 +02:00
def test(ctx: Context) -> None:
with ctx.cd(SRC_DIR):
ctx.run("pytest", pty=True, echo=True)
2023-03-25 20:32:44 +01:00
@task(pre=[compilemessages])
2022-04-24 15:51:25 +02:00
def test_cov(ctx: Context) -> None:
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
def download_db(ctx: Context) -> None:
with ctx.cd(BASE_DIR):
2022-07-06 00:06:06 +02:00
ctx.run("scp ubuntu:/mnt/data/checkout/db/db.sqlite3 ./db/db.sqlite3")
2022-04-24 15:51:25 +02:00
ctx.run("rm -rf src/media/")
2022-07-06 00:06:06 +02:00
ctx.run("scp -r ubuntu:/mnt/data/checkout/media/ ./src/media")
2022-04-24 15:51:25 +02:00
with ctx.cd(SRC_DIR):
ctx.run("./manage.py changepassword gaugendre", pty=True)
2023-04-02 19:54:35 +02:00
@task
def update_fixtures(ctx: Context) -> None:
with ctx.cd(SRC_DIR):
ctx.run(
"./manage.py dumpdata purchase.Product purchase.ProductCategory --natural-primary --natural-foreign -o ./purchase/fixtures/products.json",
echo=True,
pty=True,
)
ctx.run(
"./manage.py dumpdata purchase.PaymentMethod --natural-primary --natural-foreign -o ./purchase/fixtures/payment_methods.json",
echo=True,
pty=True,
)
ctx.run(
"pre-commit run --files ./purchase/fixtures/products.json ./purchase/fixtures/payment_methods.json",
echo=True,
pty=True,
)