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

pantsbuild / pants / 22893710013

10 Mar 2026 08:29AM UTC coverage: 91.148% (-1.8%) from 92.932%
22893710013

Pull #23032

github

web-flow
Merge c09ecdff4 into 2804a4673
Pull Request #23032: Bugfix: Add support for pull option in podman

87 of 93 new or added lines in 4 files covered. (93.55%)

1432 existing lines in 69 files now uncovered.

84014 of 92173 relevant lines covered (91.15%)

3.91 hits per line

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

92.59
/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
8✔
5

6
import os
8✔
7

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

15

16
class GenerateDockerfileRequest(GenerateSourcesRequest):
8✔
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
8✔
20
    output = DockerImageSourceField
8✔
21

22

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

29
    if instructions and request.protocol_sources.files:
7✔
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):
7✔
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():
7✔
44
        name_parts = ["Dockerfile", address.target_name, address.generated_name]
2✔
45
        return os.path.join(address.spec_path, ".".join(filter(bool, name_parts)))
2✔
46

47
    output = (
7✔
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)
7✔
59

60

61
def rules():
8✔
62
    return (
8✔
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