• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/python/pants/backend/docker/util_rules/docker_build_env.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

UNCOV
4
from __future__ import annotations
×
5

UNCOV
6
import logging
×
UNCOV
7
from collections.abc import Mapping
×
UNCOV
8
from dataclasses import dataclass
×
9

UNCOV
10
from pants.backend.docker.subsystems.docker_options import DockerOptions
×
UNCOV
11
from pants.backend.docker.util_rules.docker_build_args import (
×
12
    DockerBuildArgsRequest,
13
    docker_build_args,
14
)
UNCOV
15
from pants.backend.docker.utils import KeyValueSequenceUtil
×
UNCOV
16
from pants.core.util_rules.env_vars import environment_vars_subset
×
UNCOV
17
from pants.engine.env_vars import EnvironmentVars, EnvironmentVarsRequest
×
UNCOV
18
from pants.engine.rules import collect_rules, implicitly, rule
×
UNCOV
19
from pants.engine.target import Target
×
20

UNCOV
21
logger = logging.getLogger(__name__)
×
22

23

UNCOV
24
class DockerBuildEnvironmentError(ValueError):
×
UNCOV
25
    @classmethod
×
UNCOV
26
    def from_key_error(cls, e: KeyError) -> DockerBuildEnvironmentError:
×
27
        return cls(
×
28
            f"The Docker environment variable {e} is undefined. You may provide a value for "
29
            "this variable either in `[docker].env_vars` or in Pants's own environment."
30
        )
31

32

UNCOV
33
@dataclass(frozen=True)
×
UNCOV
34
class DockerBuildEnvironment:
×
UNCOV
35
    environment: EnvironmentVars
×
36

UNCOV
37
    @classmethod
×
UNCOV
38
    def create(
×
39
        cls,
40
        env: Mapping[str, str],
41
    ) -> DockerBuildEnvironment:
UNCOV
42
        return cls(EnvironmentVars(env))
×
43

UNCOV
44
    def __getitem__(self, key: str) -> str:
×
UNCOV
45
        try:
×
UNCOV
46
            return self.environment[key]
×
47
        except KeyError as e:
×
48
            raise DockerBuildEnvironmentError.from_key_error(e) from e
×
49

UNCOV
50
    def get(self, key: str, default: str | None = None) -> str:
×
UNCOV
51
        if default is None:
×
UNCOV
52
            return self[key]
×
53

54
        return self.environment.get(key, default)
×
55

56

UNCOV
57
@dataclass(frozen=True)
×
UNCOV
58
class DockerBuildEnvironmentRequest:
×
UNCOV
59
    target: Target
×
60

61

UNCOV
62
@rule
×
UNCOV
63
async def docker_build_environment_vars(
×
64
    request: DockerBuildEnvironmentRequest,
65
    docker_options: DockerOptions,
66
    docker_env_aware: DockerOptions.EnvironmentAware,
67
) -> DockerBuildEnvironment:
68
    build_args = await docker_build_args(DockerBuildArgsRequest(request.target), **implicitly())
×
69
    env_vars = KeyValueSequenceUtil.from_strings(
×
70
        *{build_arg for build_arg in build_args if "=" not in build_arg},
71
        *docker_env_aware.env_vars,
72
    )
73
    env = await environment_vars_subset(EnvironmentVarsRequest(tuple(env_vars)), **implicitly())
×
74
    return DockerBuildEnvironment.create(env)
×
75

76

UNCOV
77
def rules():
×
UNCOV
78
    return collect_rules()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc