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

pantsbuild / pants / 22285099215

22 Feb 2026 08:52PM UTC coverage: 75.854% (-17.1%) from 92.936%
22285099215

Pull #23121

github

web-flow
Merge c7299df9c into ba8359840
Pull Request #23121: fix issue with optional fields in dependency validator

28 of 29 new or added lines in 2 files covered. (96.55%)

11174 existing lines in 400 files now uncovered.

53694 of 70786 relevant lines covered (75.85%)

1.88 hits per line

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

80.95
/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

4
from __future__ import annotations
3✔
5

6
import logging
3✔
7
from collections.abc import Mapping
3✔
8
from dataclasses import dataclass
3✔
9

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

21
logger = logging.getLogger(__name__)
3✔
22

23

24
class DockerBuildEnvironmentError(ValueError):
3✔
25
    @classmethod
3✔
26
    def from_key_error(cls, e: KeyError) -> DockerBuildEnvironmentError:
3✔
UNCOV
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

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

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

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

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

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

56

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

61

62
@rule
3✔
63
async def docker_build_environment_vars(
3✔
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())
2✔
69
    env_vars = KeyValueSequenceUtil.from_strings(
2✔
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())
2✔
74
    return DockerBuildEnvironment.create(env)
2✔
75

76

77
def rules():
3✔
78
    return collect_rules()
3✔
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

© 2026 Coveralls, Inc