mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-14 02:33:55 +01:00
Cleanup invoke tasks
This commit is contained in:
parent
018462ffc8
commit
9f2cd849bd
4 changed files with 15 additions and 87 deletions
|
@ -87,6 +87,6 @@ repos:
|
||||||
args: [-q, --allow-unsafe, --resolver=backtracking, --strip-extras, --output-file=constraints.txt, requirements.in]
|
args: [-q, --allow-unsafe, --resolver=backtracking, --strip-extras, --output-file=constraints.txt, requirements.in]
|
||||||
files: ^requirements\.in|constraints\.txt$
|
files: ^requirements\.in|constraints\.txt$
|
||||||
- id: pip-compile
|
- id: pip-compile
|
||||||
name: pip-compile requirements-dev.in
|
name: pip-compile requirements-dev.txt
|
||||||
args: [-q, --allow-unsafe, --resolver=backtracking, --generate-hashes, requirements-dev.in]
|
args: [-q, --allow-unsafe, --resolver=backtracking, --generate-hashes, requirements-dev.in]
|
||||||
files: ^requirements-dev\.(in|txt)$
|
files: ^requirements-dev\.(in|txt)$
|
||||||
|
|
|
@ -9,9 +9,8 @@ pre-commit>=2.1
|
||||||
model-bakery>=1.3.1
|
model-bakery>=1.3.1
|
||||||
freezegun>=1.1.0
|
freezegun>=1.1.0
|
||||||
bpython>=0.22.1
|
bpython>=0.22.1
|
||||||
invoke>=1.7.3
|
invoke>=2.0.0
|
||||||
hypothesis>=6.56.4
|
hypothesis>=6.56.4
|
||||||
django-browser-reload>=1.6.0
|
django-browser-reload>=1.6.0
|
||||||
black>=22.12.0
|
black>=22.12.0
|
||||||
pip-tools>=6.0
|
pip-tools>=6.0
|
||||||
patchy>=2.0
|
|
||||||
|
|
|
@ -400,10 +400,6 @@ packaging==23.0 \
|
||||||
# via
|
# via
|
||||||
# build
|
# build
|
||||||
# pytest
|
# pytest
|
||||||
patchy==2.6.1 \
|
|
||||||
--hash=sha256:1bbbd907b2cd7df7c55210a210172f3d1a5e943c7727f66446d298c9024b6518 \
|
|
||||||
--hash=sha256:c71e99242c9d2467143d5b8200459e5a2e848608c7cfb7a35121f1744979de8a
|
|
||||||
# via -r requirements-dev.in
|
|
||||||
pathspec==0.10.3 \
|
pathspec==0.10.3 \
|
||||||
--hash=sha256:3c95343af8b756205e2aba76e843ba9520a24dd84f68c22b9f93251507509dd6 \
|
--hash=sha256:3c95343af8b756205e2aba76e843ba9520a24dd84f68c22b9f93251507509dd6 \
|
||||||
--hash=sha256:56200de4077d9d0791465aa9095a01d421861e405b5096955051deefd697d6f6
|
--hash=sha256:56200de4077d9d0791465aa9095a01d421861e405b5096955051deefd697d6f6
|
||||||
|
|
93
tasks.py
93
tasks.py
|
@ -1,23 +1,6 @@
|
||||||
import time
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import patchy
|
from invoke import Context, task
|
||||||
import requests
|
|
||||||
from invoke import task
|
|
||||||
|
|
||||||
patchy.patch(
|
|
||||||
"invoke.tasks.Task.argspec",
|
|
||||||
"""\
|
|
||||||
@@ -16,7 +16,7 @@
|
|
||||||
# TODO: __call__ exhibits the 'self' arg; do we manually nix 1st result
|
|
||||||
# in argspec, or is there a way to get the "really callable" spec?
|
|
||||||
func = body if isinstance(body, types.FunctionType) else body.__call__
|
|
||||||
- spec = inspect.getargspec(func)
|
|
||||||
+ spec = inspect.getfullargspec(func)
|
|
||||||
arg_names = spec.args[:]
|
|
||||||
matched_args = [reversed(x) for x in [spec.args, spec.defaults or []]]
|
|
||||||
spec_dict = dict(zip_longest(*matched_args, fillvalue=NO_DEFAULT))""",
|
|
||||||
)
|
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).parent.resolve(strict=True)
|
BASE_DIR = Path(__file__).parent.resolve(strict=True)
|
||||||
SRC_DIR = BASE_DIR / "src"
|
SRC_DIR = BASE_DIR / "src"
|
||||||
|
@ -27,8 +10,10 @@ TEST_ENV = {"ENV_FILE": BASE_DIR / "envs" / "test-envs.env"}
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def update_dependencies(ctx):
|
def sync_dependencies(ctx: Context, update: bool = False):
|
||||||
common_args = "-q --allow-unsafe --resolver=backtracking --upgrade"
|
common_args = "-q --allow-unsafe --resolver=backtracking"
|
||||||
|
if update:
|
||||||
|
common_args += " --upgrade"
|
||||||
with ctx.cd(BASE_DIR):
|
with ctx.cd(BASE_DIR):
|
||||||
ctx.run(
|
ctx.run(
|
||||||
f"pip-compile {common_args} --generate-hashes requirements.in",
|
f"pip-compile {common_args} --generate-hashes requirements.in",
|
||||||
|
@ -49,25 +34,25 @@ def update_dependencies(ctx):
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def makemessages(ctx):
|
def makemessages(ctx: Context):
|
||||||
with ctx.cd(SRC_DIR):
|
with ctx.cd(SRC_DIR):
|
||||||
ctx.run("./manage.py makemessages -l en -l fr", pty=True, echo=True)
|
ctx.run("./manage.py makemessages -l en -l fr", pty=True, echo=True)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def compilemessages(ctx):
|
def compilemessages(ctx: Context):
|
||||||
with ctx.cd(SRC_DIR):
|
with ctx.cd(SRC_DIR):
|
||||||
ctx.run("./manage.py compilemessages -l en -l fr", pty=True, echo=True)
|
ctx.run("./manage.py compilemessages -l en -l fr", pty=True, echo=True)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def test(ctx):
|
def test(ctx: Context):
|
||||||
with ctx.cd(SRC_DIR):
|
with ctx.cd(SRC_DIR):
|
||||||
ctx.run("pytest", pty=True, echo=True, env=TEST_ENV)
|
ctx.run("pytest", pty=True, echo=True, env=TEST_ENV)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def test_cov(ctx):
|
def test_cov(ctx: Context):
|
||||||
with ctx.cd(SRC_DIR):
|
with ctx.cd(SRC_DIR):
|
||||||
ctx.run(
|
ctx.run(
|
||||||
"pytest --cov=. --cov-branch --cov-report term-missing:skip-covered",
|
"pytest --cov=. --cov-branch --cov-report term-missing:skip-covered",
|
||||||
|
@ -78,59 +63,7 @@ def test_cov(ctx):
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def pre_commit(ctx):
|
def download_db(ctx: Context):
|
||||||
with ctx.cd(BASE_DIR):
|
|
||||||
ctx.run("pre-commit run --all-files", pty=True, echo=True)
|
|
||||||
|
|
||||||
|
|
||||||
@task(pre=[pre_commit, test_cov])
|
|
||||||
def check(ctx):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@task
|
|
||||||
def build(ctx):
|
|
||||||
with ctx.cd(BASE_DIR):
|
|
||||||
ctx.run(
|
|
||||||
"docker-compose build django", pty=True, echo=True, env=COMPOSE_BUILD_ENV
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@task
|
|
||||||
def publish(ctx):
|
|
||||||
with ctx.cd(BASE_DIR):
|
|
||||||
ctx.run(
|
|
||||||
"docker-compose push django", pty=True, echo=True, env=COMPOSE_BUILD_ENV
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@task
|
|
||||||
def deploy(ctx):
|
|
||||||
ctx.run("ssh ubuntu /mnt/data/checkout/update", pty=True, echo=True)
|
|
||||||
|
|
||||||
|
|
||||||
@task
|
|
||||||
def check_alive(ctx):
|
|
||||||
exception = None
|
|
||||||
for _ in range(5):
|
|
||||||
try:
|
|
||||||
res = requests.get("https://charasheet.augendre.info")
|
|
||||||
res.raise_for_status()
|
|
||||||
print("Server is up & running")
|
|
||||||
return
|
|
||||||
except requests.exceptions.HTTPError as e:
|
|
||||||
time.sleep(2)
|
|
||||||
exception = e
|
|
||||||
raise RuntimeError("Failed to reach the server") from exception
|
|
||||||
|
|
||||||
|
|
||||||
@task(pre=[check, build, publish, deploy], post=[check_alive])
|
|
||||||
def beam(ctx):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@task
|
|
||||||
def download_db(ctx):
|
|
||||||
with ctx.cd(BASE_DIR):
|
with ctx.cd(BASE_DIR):
|
||||||
ctx.run(
|
ctx.run(
|
||||||
"scp ubuntu:/mnt/data/charasheet/db/db.sqlite3 ./db/db.sqlite3",
|
"scp ubuntu:/mnt/data/charasheet/db/db.sqlite3 ./db/db.sqlite3",
|
||||||
|
@ -146,7 +79,7 @@ def download_db(ctx):
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def dump_initial(ctx):
|
def dump_initial(ctx: Context):
|
||||||
with ctx.cd(SRC_DIR):
|
with ctx.cd(SRC_DIR):
|
||||||
path = "./character/fixtures/initial_data.json"
|
path = "./character/fixtures/initial_data.json"
|
||||||
ctx.run(
|
ctx.run(
|
||||||
|
@ -158,7 +91,7 @@ def dump_initial(ctx):
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def import_from_co_drs(ctx):
|
def import_from_co_drs(ctx: Context):
|
||||||
with ctx.cd(SRC_DIR):
|
with ctx.cd(SRC_DIR):
|
||||||
ctx.run("./manage.py import_races", pty=True, echo=True)
|
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_profiles", pty=True, echo=True)
|
||||||
|
@ -169,5 +102,5 @@ def import_from_co_drs(ctx):
|
||||||
|
|
||||||
|
|
||||||
@task(pre=[import_from_co_drs, dump_initial])
|
@task(pre=[import_from_co_drs, dump_initial])
|
||||||
def update_fixtures(ctx):
|
def update_fixtures(ctx: Context):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue