Skip to content

Config

AlembicSettings dataclass

Settings for alembic module.

Source code in saritasa_invocations/_config.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
@dataclasses.dataclass
class AlembicSettings:
    """Settings for alembic module."""

    connect_attempts: int = 10
    command: str = "-m alembic"
    migrations_folder: str = "db/migrations/versions"
    adjust_messages: collections.abc.Sequence[str] = (
        "# ### commands auto generated by Alembic - please adjust! ###",
        "# ### end Alembic commands ###",
    )
    db_config_mapping: dict[str, str] = dataclasses.field(
        default_factory=lambda: {
            "dbname": "rds_db_name",
            "host": "rds_db_host",
            "port": "rds_db_port",
            "username": "rds_db_user",
            "password": "rds_db_password",
        },
    )

CelerySettings dataclass

Settings for celery module.

Source code in saritasa_invocations/_config.py
120
121
122
123
124
125
126
127
128
129
130
131
132
@dataclasses.dataclass
class CelerySettings:
    """Settings for celery module."""

    app: str = "config.celery.app"
    scheduler: str = "django"
    service_name: str = "celery"
    loglevel: str = "info"
    extra_params: tuple[str] = ("--beat",)
    local_cmd: str = (
        "celery --app {app} "
        "worker --scheduler={scheduler} --loglevel={loglevel} {extra_params}"
    )

Config dataclass

Settings for saritasa invocations.

Source code in saritasa_invocations/_config.py
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
@dataclasses.dataclass(frozen=True)
class Config:
    """Settings for saritasa invocations."""

    project_name: str = ""
    default_k8s_env: str = "dev"

    system: SystemSettings = dataclasses.field(
        default_factory=SystemSettings,
    )
    git: GitSettings = dataclasses.field(
        default_factory=GitSettings,
    )
    docker: DockerSettings = dataclasses.field(
        default_factory=DockerSettings,
    )
    python: PythonSettings = dataclasses.field(
        default_factory=PythonSettings,
    )
    github_actions: GitHubActionsSettings = dataclasses.field(
        default_factory=GitHubActionsSettings,
    )
    django: DjangoSettings = dataclasses.field(
        default_factory=DjangoSettings,
    )
    celery: CelerySettings = dataclasses.field(
        default_factory=CelerySettings,
    )
    fastapi: FastAPISettings = dataclasses.field(
        default_factory=FastAPISettings,
    )
    alembic: AlembicSettings = dataclasses.field(
        default_factory=AlembicSettings,
    )
    cruft: CruftSettings = dataclasses.field(
        default_factory=CruftSettings,
    )
    db: DBSettings = dataclasses.field(
        default_factory=DBSettings,
    )
    k8s_defaults: K8SDefaultSettings = dataclasses.field(
        default_factory=K8SDefaultSettings,
    )
    k8s_configs: dict[str, K8SSettings] = dataclasses.field(
        default_factory=lambda: _K8S_CONFIGS,
    )
    pip: PIPSettings = dataclasses.field(
        default_factory=PIPSettings,
    )
    pre_commit: PreCommitSettings = dataclasses.field(
        default_factory=PreCommitSettings,
    )

    def __post_init__(self) -> None:
        """Set default values for settings that are dependant on others."""
        if not self.docker.build_image_tag:
            self.docker.build_image_tag = self.project_name

        if not self.github_actions.hosts:
            self.github_actions.hosts = self.docker.main_containers

    @classmethod
    def from_context(cls, context: invoke.Context) -> "Config":
        """Get config from invoke context."""
        return context.config.get(
            "saritasa_invocations",
            cls(),
        )

__post_init__()

Set default values for settings that are dependant on others.

Source code in saritasa_invocations/_config.py
443
444
445
446
447
448
449
def __post_init__(self) -> None:
    """Set default values for settings that are dependant on others."""
    if not self.docker.build_image_tag:
        self.docker.build_image_tag = self.project_name

    if not self.github_actions.hosts:
        self.github_actions.hosts = self.docker.main_containers

from_context(context) classmethod

Get config from invoke context.

Source code in saritasa_invocations/_config.py
451
452
453
454
455
456
457
@classmethod
def from_context(cls, context: invoke.Context) -> "Config":
    """Get config from invoke context."""
    return context.config.get(
        "saritasa_invocations",
        cls(),
    )

CruftSettings dataclass

Settings for cruft module.

Source code in saritasa_invocations/_config.py
169
170
171
172
173
@dataclasses.dataclass
class CruftSettings:
    """Settings for cruft module."""

    project_tmp_folder: str = ".tmp"

DBSettings dataclass

Settings for db module.

Source code in saritasa_invocations/_config.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
@dataclasses.dataclass
class DBSettings:
    """Settings for db module."""

    password_pattern: str = "Password.*"  # noqa: S105
    load_dump_command: str = (
        "psql "
        "{additional_params} "
        "--dbname={dbname} "
        "--host={host} "
        "--port={port} "
        "--username={username} "
        "--file={file}"
    )
    load_compressed_dump_command: str = (
        "pg_restore "
        "{additional_params} "
        "--dbname={dbname} "
        "--host={host} "
        "--port={port} "
        "--username={username} "
        "{file}"
    )
    dump_filename: str = "local-db-dump.sql"
    load_additional_params: str = "--quiet"
    load_compressed_additional_params: str = "--no-owner"
    dump_command: str = (
        "pg_dump "
        "{additional_params} "
        "--dbname={dbname} "
        "--host={host} "
        "--port={port} "
        "--username={username} "
        "--file={file}"
    )
    dump_additional_params: str = ""
    dump_no_owner: bool = True
    dump_compression_level: int = 6
    dump_include_table: str = ""
    dump_exclude_table: str = ""
    dump_exclude_table_data: str = ""
    dump_exclude_extension: str = ""

DjangoSettings dataclass

Settings for django module.

Source code in saritasa_invocations/_config.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@dataclasses.dataclass
class DjangoSettings:
    """Settings for django module."""

    runserver_command: str = "runserver_plus"
    runserver_host: str = "0.0.0.0"  # noqa: S104
    runserver_port: str = "8000"
    runserver_params: str = ""
    runserver_docker_params: str = "--rm --service-ports"
    migrate_command: str = "migrate"
    makemessages_params: str = "--all --ignore venv"
    compilemessages_params: str = ""
    verbose_email_name: str = "Email address"
    default_superuser_email: str = "root@localhost"
    verbose_username_name: str = "Username"
    default_superuser_username: str = "root"
    verbose_password_name: str = "Password"  # noqa: S105
    default_superuser_password: str = "root"  # noqa: S105
    shell_command: str = "shell_plus --ipython"
    path_to_remote_config_file: str = "/workspace/app/config/settings/.env"
    manage_file_path: str = "./manage.py"
    settings_path: str = "config.settings.local"
    app_boilerplate_link: str | None = None
    apps_path: str = "apps"
    remote_db_url_config_name: str = "DATABASE_URL"
    remote_db_config_mapping: dict[str, str] = dataclasses.field(
        default_factory=lambda: {
            "dbname": "RDS_DB_NAME",
            "host": "RDS_DB_HOST",
            "port": "RDS_DB_PORT",
            "username": "RDS_DB_USER",
            "password": "RDS_DB_PASSWORD",
        },
    )

DockerSettings dataclass

Settings for docker module.

Source code in saritasa_invocations/_config.py
62
63
64
65
66
67
68
69
70
71
72
73
74
@dataclasses.dataclass
class DockerSettings:
    """Settings for docker module."""

    compose_cmd = "docker compose"
    main_containers: collections.abc.Sequence[str] = (
        "postgres",
        "redis",
    )
    build_image_tag: str = ""
    buildpack_builder: str = "paketobuildpacks/builder-jammy-base:latest"
    buildpack_runner: str = "paketobuildpacks/run-jammy-base:latest"
    buildpack_requirements_path: str = "requirements"

FastAPISettings dataclass

Settings for fastapi module.

Source code in saritasa_invocations/_config.py
135
136
137
138
139
140
141
142
143
144
@dataclasses.dataclass
class FastAPISettings:
    """Settings for fastapi module."""

    uvicorn_command: str = "-m uvicorn"
    app: str = "config:fastapi_app"
    host: str = "0.0.0.0"  # noqa: S104
    port: str = "8000"
    params: str = "--reload"
    docker_params: str = "--rm --service-ports"

GitHubActionsSettings dataclass

Settings for github actions module.

Source code in saritasa_invocations/_config.py
77
78
79
80
81
@dataclasses.dataclass
class GitHubActionsSettings:
    """Settings for github actions module."""

    hosts: collections.abc.Sequence[str] = ()

GitSettings dataclass

Settings for git module.

Source code in saritasa_invocations/_config.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@dataclasses.dataclass
class GitSettings:
    """Settings for git module."""

    merge_ff: str = "false"
    pull_ff: str = "only"
    copy_commit_template: str = (
        "[automated-commit]: {action}\n\n"
        "copy: {original_path}\n"
        "to:\n* {destination_paths}\n\n"
        "{project_task}"
    )
    copy_init_message_template: str = (
        "Copy {original_path} to:\n"
        "* {destination_paths}\n\n"
        "Count of created commits: {commits_count}"
    )

K8SDBSettings dataclass

Description of k8s db config.

Source code in saritasa_invocations/_config.py
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
@dataclasses.dataclass(frozen=True)
class K8SDBSettings:
    """Description of k8s db config."""

    namespace: str
    pod_selector: str
    dump_filename_template: str = (
        "{project_name}-{env}-{timestamp:%Y-%m-%d}-db-dump.{extension}"
    )
    password_pattern: str = "Password: "  # noqa: S105
    get_pod_name_command: str = (
        "kubectl get pods --namespace {db_pod_namespace} "
        "--selector={db_pod_selector} "
        "--output jsonpath='{{.items[0].metadata.name}}'"
    )
    exec_command: str = (
        "kubectl exec -ti --namespace {db_pod_namespace} $({db_pod})"
    )
    dump_dir: str = "tmp"
    dump_command: str = (
        "pg_dump "
        "{additional_params} "
        "--dbname={dbname} "
        "--host={host} "
        "--port={port} "
        "--username={username} "
        "--file {file}"
    )
    dump_additional_params: str = ""
    dump_no_owner: bool = True
    dump_compression_level: int = 6
    dump_include_table: str = ""
    dump_exclude_table: str = ""
    dump_exclude_table_data: str = ""
    dump_exclude_extension: str = ""

K8SDefaultSettings dataclass

Default settings that could be shared among all env.

Source code in saritasa_invocations/_config.py
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
@dataclasses.dataclass(frozen=True)
class K8SDefaultSettings:
    """Default settings that could be shared among all env."""

    proxy: str | None = None
    db_config: K8SDBSettings | None = None
    port: str = "443"
    auth: str = "github"
    component_selector: str = "app.kubernetes.io/component"
    get_pod_name_command: str = (
        "kubectl get pods "
        "--selector {component_selector}={component} "
        "--no-headers --output jsonpath='{{.items[0].metadata.name}}'"
    )
    default_component: str = "backend"
    default_entry: str = "/cnb/lifecycle/launcher"
    default_command: str = "bash"
    python_shell: str = "shell_plus"
    health_check: str = "health_check"
    secret_file_path_in_pod: str | None = None
    temp_secret_file_path: str = ".env.to_delete"  # noqa: S105
    env_color: str = "cyan"

K8SGeneratedSettings dataclass

Merge of defaults and environment config.

Source code in saritasa_invocations/_config.py
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
@dataclasses.dataclass(frozen=True)
class K8SGeneratedSettings:
    """Merge of defaults and environment config."""

    name: str
    cluster: str
    proxy: str
    context: str
    namespace: str
    db_config: K8SDBSettings
    port: str
    auth: str
    component_selector: str
    get_pod_name_command: str
    default_component: str
    default_entry: str
    default_command: str
    python_shell: str
    health_check: str
    secret_file_path_in_pod: str
    temp_secret_file_path: str
    env_color: str

    @classmethod
    def merge_settings(
        cls,
        default: K8SDefaultSettings,
        env_settings: K8SSettings,
    ) -> "K8SGeneratedSettings":
        """Create settings from default and env settings."""
        generated_config = {}
        for field in dataclasses.asdict(env_settings):
            generated_config[field] = getattr(
                env_settings,
                field,
                None,
            ) or getattr(
                default,
                field,
                None,
            )
        return cls(**generated_config)  # type: ignore

merge_settings(default, env_settings) classmethod

Create settings from default and env settings.

Source code in saritasa_invocations/_config.py
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
@classmethod
def merge_settings(
    cls,
    default: K8SDefaultSettings,
    env_settings: K8SSettings,
) -> "K8SGeneratedSettings":
    """Create settings from default and env settings."""
    generated_config = {}
    for field in dataclasses.asdict(env_settings):
        generated_config[field] = getattr(
            env_settings,
            field,
            None,
        ) or getattr(
            default,
            field,
            None,
        )
    return cls(**generated_config)  # type: ignore

K8SSettings dataclass

Description of environment config.

Source code in saritasa_invocations/_config.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
@dataclasses.dataclass(frozen=True)
class K8SSettings(metaclass=K8SSettingsMeta):
    """Description of environment config."""

    name: str
    namespace: str
    context: str
    proxy: str | None = None
    cluster: str | None = None
    db_config: K8SDBSettings | None = None
    port: str | None = None
    auth: str | None = None
    component_selector: str | None = None
    get_pod_name_command: str | None = None
    default_component: str | None = None
    default_entry: str | None = None
    default_command: str | None = None
    python_shell: str | None = None
    health_check: str | None = None
    secret_file_path_in_pod: str | None = None
    temp_secret_file_path: str | None = None
    env_color: str | None = None

K8SSettingsMeta

Bases: type

Meta class for K8SSettings.

Source code in saritasa_invocations/_config.py
225
226
227
228
229
230
231
232
233
234
class K8SSettingsMeta(type):
    """Meta class for K8SSettings."""

    def __call__(cls, *args, **kwargs) -> "K8SSettings":  # noqa: ANN002
        """Update mapping of environments."""
        instance: K8SSettings = super().__call__(*args, **kwargs)
        if instance.name in _K8S_CONFIGS:
            raise ValueError(f"{instance.name} config is already defined")
        _K8S_CONFIGS[instance.name] = instance
        return instance

__call__(*args, **kwargs)

Update mapping of environments.

Source code in saritasa_invocations/_config.py
228
229
230
231
232
233
234
def __call__(cls, *args, **kwargs) -> "K8SSettings":  # noqa: ANN002
    """Update mapping of environments."""
    instance: K8SSettings = super().__call__(*args, **kwargs)
    if instance.name in _K8S_CONFIGS:
        raise ValueError(f"{instance.name} config is already defined")
    _K8S_CONFIGS[instance.name] = instance
    return instance

PIPSettings dataclass

Settings for pip module.

Source code in saritasa_invocations/_config.py
366
367
368
369
370
371
372
373
374
@dataclasses.dataclass(frozen=True)
class PIPSettings:
    """Settings for pip module."""

    dependencies_folder: str = "requirements"
    in_files: collections.abc.Sequence[str] = (
        "production.in",
        "development.in",
    )

PreCommitSettings dataclass

Settings to run pre-commit hooks.

By default, run by pre-commit https://github.com/pre-commit/pre-commit But can be changed to prek https://github.com/j178/prek

Source code in saritasa_invocations/_config.py
377
378
379
380
381
382
383
384
385
386
387
@dataclasses.dataclass(frozen=True)
class PreCommitSettings:
    """Settings to run pre-commit hooks.

    By default, run by pre-commit https://github.com/pre-commit/pre-commit
    But can be changed to prek https://github.com/j178/prek

    """

    entry: typing.Literal["pre-commit", "prek"] = "pre-commit"
    default_hook_stage: str = "push"

PythonSettings dataclass

Settings for python module.

Source code in saritasa_invocations/_config.py
51
52
53
54
55
56
57
58
59
@dataclasses.dataclass
class PythonSettings:
    """Settings for python module."""

    entry: str = "python"
    docker_service: str = "web"
    docker_service_params: str = "--rm"
    mypy_entry: str = "-m mypy"
    pytest_entry: str = "-m pytest"

SystemSettings dataclass

Settings for system module.

Source code in saritasa_invocations/_config.py
23
24
25
26
27
28
29
@dataclasses.dataclass
class SystemSettings:
    """Settings for system module."""

    settings_template: str = "config/settings/local.template.py"
    save_settings_from_template_to: str = "config/settings/local.py"
    vs_code_settings_template: str = ".vscode/recommended_settings.json"

context_override(context, **config)

Temporary override context settings.

Source code in saritasa_invocations/_config.py
 9
10
11
12
13
14
15
16
17
18
19
20
@contextlib.contextmanager
def context_override(
    context: invoke.Context,
    **config,
) -> collections.abc.Generator[invoke.Context, typing.Any, None]:
    """Temporary override context settings."""
    old_context_config = {key: context.config.get(key) for key in config}
    context.config.update(**config)
    try:
        yield context
    finally:
        context.config.update(**old_context_config)