debputy.integration_detection

src/debputy/integration_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import Optional
from collections.abc import Container, Mapping

from debputy.plugin.api.spec import (
    DebputyIntegrationMode,
    INTEGRATION_MODE_DH_DEBPUTY_RRR,
    INTEGRATION_MODE_DH_DEBPUTY,
    INTEGRATION_MODE_FULL,
)


def determine_debputy_integration_mode(
    source_fields: Mapping[str, str],
    all_sequences: Container[str],
) -> DebputyIntegrationMode | None:

    if source_fields.get("Build-Driver", "").lower() == "debputy":
        return INTEGRATION_MODE_FULL

    has_zz_debputy = "zz-debputy" in all_sequences or "debputy" in all_sequences
    has_zz_debputy_rrr = "zz-debputy-rrr" in all_sequences
    has_any_existing = has_zz_debputy or has_zz_debputy_rrr
    if has_zz_debputy_rrr:
        return INTEGRATION_MODE_DH_DEBPUTY_RRR
    if has_any_existing:
        return INTEGRATION_MODE_DH_DEBPUTY
    if source_fields.get("Source", "") == "debputy":
        # Self-hosting. We cannot set the Build-Driver field since that creates a self-circular dependency loop
        return INTEGRATION_MODE_FULL
    return None