• 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

85.19
/src/python/pants/backend/docker/util_rules/dockerfile.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 os
3✔
7

8
from pants.backend.docker.target_types import DockerImageInstructionsField, DockerImageSourceField
3✔
9
from pants.engine.fs import CreateDigest, FileContent
3✔
10
from pants.engine.intrinsics import digest_to_snapshot
3✔
11
from pants.engine.rules import collect_rules, implicitly, rule
3✔
12
from pants.engine.target import GeneratedSources, GenerateSourcesRequest, InvalidFieldException
3✔
13
from pants.engine.unions import UnionRule
3✔
14

15

16
class GenerateDockerfileRequest(GenerateSourcesRequest):
3✔
17
    # This will always run codegen when hydrating `docker_image`s, performing source validations but
18
    # does not generate anything if there are no `instructions` defined on the target.
19
    input = DockerImageSourceField
3✔
20
    output = DockerImageSourceField
3✔
21

22

23
@rule
3✔
24
async def hydrate_dockerfile(request: GenerateDockerfileRequest) -> GeneratedSources:
3✔
25
    target = request.protocol_target
3✔
26
    address = target.address
3✔
27
    instructions = target[DockerImageInstructionsField].value
3✔
28

29
    if instructions and request.protocol_sources.files:
3✔
UNCOV
30
        raise InvalidFieldException(
×
31
            f"The `{target.alias}` {address} provides both a Dockerfile with the `source` field, "
32
            "and Dockerfile contents with the `instructions` field, which is not supported.\n\n"
33
            "To fix, please either set `source=None` or `instructions=None`."
34
        )
35

36
    if not (instructions or request.protocol_sources.files):
3✔
UNCOV
37
        raise InvalidFieldException(
×
38
            f"The `{target.alias}` {address} does not specify any Dockerfile.\n\n"
39
            "Provide either the filename to a Dockerfile in your workspace as the `source` field "
40
            "value, or the Dockerfile content to the `instructions` field."
41
        )
42

43
    def dockerfile_path():
3✔
UNCOV
44
        name_parts = ["Dockerfile", address.target_name, address.generated_name]
×
UNCOV
45
        return os.path.join(address.spec_path, ".".join(filter(bool, name_parts)))
×
46

47
    output = (
3✔
48
        await digest_to_snapshot(
49
            **implicitly(
50
                CreateDigest(
51
                    (FileContent(dockerfile_path(), "\n".join([*instructions, ""]).encode()),)
52
                ),
53
            )
54
        )
55
        if instructions
56
        else request.protocol_sources
57
    )
58
    return GeneratedSources(output)
3✔
59

60

61
def rules():
3✔
62
    return (
3✔
63
        *collect_rules(),
64
        UnionRule(GenerateSourcesRequest, GenerateDockerfileRequest),
65
    )
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