• 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/dockerfile.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 os
×
7

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

15

UNCOV
16
class GenerateDockerfileRequest(GenerateSourcesRequest):
×
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.
UNCOV
19
    input = DockerImageSourceField
×
UNCOV
20
    output = DockerImageSourceField
×
21

22

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

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

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

60

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

© 2025 Coveralls, Inc