Coverage for databases/_serve.py: 42%
15 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1from __future__ import annotations
3import shlex
4from pathlib import Path
6import nox
8from ._types import SupportedDatabase
10DOCKER_COMPOSE_FILE = Path(__file__).parent / 'docker-compose.yml'
13def start_database(
14 database: SupportedDatabase,
15 *,
16 version: str | None,
17 session: nox.Session,
18) -> None:
19 """Start a docker-compose database service"""
20 if database == 'sqlite':
21 raise ValueError('Cannot start a server for SQLite.')
23 args = shlex.split(f'docker compose -f {DOCKER_COMPOSE_FILE} up -d --remove-orphans')
24 session.run_always(
25 *args,
26 f'{database}{_format_version(version)}',
27 external=True,
28 )
31def _format_version(version: str | None) -> str:
32 if version is None:
33 return ''
35 return '-' + version.replace('.', '-')