diff --git a/.vscode/project-related-words.txt b/.vscode/project-related-words.txt index f565820..6ae8276 100644 --- a/.vscode/project-related-words.txt +++ b/.vscode/project-related-words.txt @@ -1,10 +1,19 @@ +alembicbackup +alembicload +alembicwait autoupdate buildpack buildpacks +celeryrun +celerysend charliermarsh compilemessages createsuperuser dbshell +djangobackup +djangoload +djangowait +fastapirun FURB htmlcov Khlud @@ -18,10 +27,10 @@ paketobuildpacks Pylance Renderable resetdb +RUF runserver saritasa snok Stanislav startapp TASKNUMBER -RUF diff --git a/CHANGELOG.md b/CHANGELOG.md index 942b4a1..31ea637 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ We follow [Semantic Versions](https://semver.org/). ## unreleased - Replace usage of cmd commands with python +- Make `django.wait_for_database` as task +- Make `alembic.wait_for_database` as task +- Make `docker.up` check for compose file +- Make `pytest.run`, `celery.run` use `docker.up` ## 1.1.1 diff --git a/README.md b/README.md index b7563a6..d68ceb4 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Collection of [invoke](https://www.pyinvoke.org/) commands used by Saritasa * [django.backup-local-db](#djangobackup-local-db) * [django.backup-remote-db](#djangobackup-remote-db) * [django.load-remote-db](#djangoload-remote-db) + * [django.wait-for-database](#djangowait-for-database) * [fastapi](#fastapi) * [fastapi.run](#fastapirun) * [alembic](#alembic) @@ -67,6 +68,7 @@ Collection of [invoke](https://www.pyinvoke.org/) commands used by Saritasa * [alembic.backup-local-db](#alembicbackup-local-db) * [alembic.backup-remote-db](#alembicbackup-remote-db) * [alembic.load-remote-db](#alembicload-remote-db) + * [alembic.wait-for-database](#alembicwait-for-database) * [celery](#celery) * [celery.run](#celeryrun) * [celery.send-task](#celerysend-task) @@ -260,10 +262,10 @@ Clone repo or pull latest changes to specified repo Command for creating copies of a file with git blame history saving. -Original script written in bash: -https://dev.to/deckstar/how-to-git-copy-copying-files-while-keeping-git-history-1c9j +Original script written in bash [here](https://dev.to/deckstar/how-to-git-copy-copying-files-while-keeping-git-history-1c9j) Usage: + ```shell inv git.blame-copy ,... ``` @@ -301,14 +303,18 @@ The `action` variable stores the header of the intermediate action. If no task found in branch, then will be empty Default values for templates: + * `copy_commit_template`: + ```python "[automated-commit]: {action}\n\n" "copy: {original_path}\n" "to:\n* {destination_paths}\n\n" "{project_task}" ``` + * `copy_init_message_template`: + ```python "Copy {original_path} to:\n" "* {destination_paths}\n\n" @@ -567,6 +573,10 @@ Settings: * `app_template_directory` path to app template in project template (Default: `.`) * `apps_path` path to apps folder in project (Default: `apps`) +#### django.wait-for-database + +Launch docker compose and wait for database connection. + ### fastapi #### fastapi.run @@ -727,6 +737,10 @@ Settings: } ``` +#### alembic.wait-for-database + +Launch docker compose and wait for database connection. + ### celery #### celery.run diff --git a/saritasa_invocations/alembic.py b/saritasa_invocations/alembic.py index 220fbe2..b4e40a9 100644 --- a/saritasa_invocations/alembic.py +++ b/saritasa_invocations/alembic.py @@ -6,6 +6,7 @@ from . import _config, db, db_k8s, docker, k8s, printing, python +@invoke.task def wait_for_database(context: invoke.Context) -> None: """Ensure that database is up and ready to accept connections. diff --git a/saritasa_invocations/celery.py b/saritasa_invocations/celery.py index 10ba1e0..c4a121c 100644 --- a/saritasa_invocations/celery.py +++ b/saritasa_invocations/celery.py @@ -12,6 +12,7 @@ def run( config = _config.Config.from_context(context).celery match python.get_python_env(): case python.PythonEnv.LOCAL: + docker.up(context) context.run( config.local_cmd.format( app=config.app, diff --git a/saritasa_invocations/django.py b/saritasa_invocations/django.py index 471dec6..a57225e 100644 --- a/saritasa_invocations/django.py +++ b/saritasa_invocations/django.py @@ -7,6 +7,7 @@ from . import _config, db, db_k8s, docker, k8s, printing, python, system +@invoke.task def wait_for_database(context: invoke.Context) -> None: """Ensure that database is up and ready to accept connections. diff --git a/saritasa_invocations/docker.py b/saritasa_invocations/docker.py index b606f2f..501359e 100644 --- a/saritasa_invocations/docker.py +++ b/saritasa_invocations/docker.py @@ -156,7 +156,15 @@ def stop_containers( def up(context: invoke.Context) -> None: """Bring up main containers and start them.""" config = _config.Config.from_context(context) - if not config.docker.main_containers: + if not any( + pathlib.Path(compose_file).exists() + for compose_file in ( + "compose.yaml", + "compose.yml", + "docker-compose.yaml", + "docker-compose.yml", + ) + ): return up_containers( context, diff --git a/saritasa_invocations/pytest.py b/saritasa_invocations/pytest.py index c256d98..55f4fce 100644 --- a/saritasa_invocations/pytest.py +++ b/saritasa_invocations/pytest.py @@ -1,6 +1,6 @@ import invoke -from . import _config, printing, python +from . import _config, docker, printing, python @invoke.task @@ -10,6 +10,7 @@ def run( params: str = "", ) -> None: """Run pytest in `path` with `params`.""" + docker.up(context) printing.print_success("Running PyTest") pytest_entry = _config.Config.from_context(context).python.pytest_entry python.run(context, f"{pytest_entry} {path} {params}")