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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 hits per line

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

0.0
/src/python/pants/backend/python/util_rules/pex_venv.py
1
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
from __future__ import annotations
×
4

5
from dataclasses import dataclass
×
6
from enum import Enum
×
7
from pathlib import Path
×
8

9
from pants.backend.python.util_rules import pex_cli
×
10
from pants.backend.python.util_rules.pex import CompletePlatforms, Pex, PexPlatforms
×
11
from pants.backend.python.util_rules.pex_cli import PexCliProcess
×
12
from pants.engine.fs import Digest
×
13
from pants.engine.internals.native_engine import MergeDigests
×
14
from pants.engine.intrinsics import merge_digests
×
15
from pants.engine.process import fallible_to_exec_result_or_raise
×
16
from pants.engine.rules import collect_rules, implicitly, rule
×
17

18

19
class PexVenvLayout(Enum):
×
20
    VENV = "venv"
×
21
    FLAT = "flat"
×
22
    FLAT_ZIPPED = "flat-zipped"
×
23

24

25
@dataclass(frozen=True)
×
26
class PexVenvRequest:
×
27
    pex: Pex
×
28
    layout: PexVenvLayout
×
29
    output_path: Path
×
30
    description: str
×
31

32
    platforms: PexPlatforms = PexPlatforms()
×
33
    complete_platforms: CompletePlatforms = CompletePlatforms()
×
34
    prefix: None | str = None
×
35
    extra_args: tuple[str, ...] = ()
×
36

37

38
@dataclass(frozen=True)
×
39
class PexVenv:
×
40
    digest: Digest
×
41
    path: Path
×
42

43

44
@rule
×
45
async def pex_venv(request: PexVenvRequest) -> PexVenv:
×
46
    # TODO: create the output with a fixed name and then rename
47
    # (https://github.com/pantsbuild/pants/issues/15102)
48
    if request.layout is PexVenvLayout.FLAT_ZIPPED:
×
49
        # --layout=flat-zipped takes --dest-dir=foo and zips it up to `foo.zip`, so we cannot
50
        # directly control the full path until we do a rename
51
        if request.output_path.suffix != ".zip":
×
52
            raise ValueError(
×
53
                f"layout=FLAT_ZIPPED requires output_path to end in '.zip', but found output_path='{request.output_path}' ending in {request.output_path.suffix!r}"
54
            )
55
        dest_dir = request.output_path.with_suffix("")
×
56
        output_files = [str(request.output_path)]
×
57
        output_directories = []
×
58
    else:
59
        dest_dir = request.output_path
×
60
        output_files = []
×
61
        output_directories = [str(request.output_path)]
×
62

63
    input_digest = await merge_digests(
×
64
        MergeDigests([request.pex.digest, request.complete_platforms.digest])
65
    )
66
    result = await fallible_to_exec_result_or_raise(
×
67
        **implicitly(
68
            PexCliProcess(
69
                subcommand=("venv", "create"),
70
                extra_args=(
71
                    f"--dest-dir={dest_dir}",
72
                    f"--pex-repository={request.pex.name}",
73
                    f"--layout={request.layout.value}",
74
                    *((f"--prefix={request.prefix}",) if request.prefix is not None else ()),
75
                    # NB. Specifying more than one of these args doesn't make sense for `venv
76
                    # create`. Incorrect usage will be surfaced as a subprocess failure.
77
                    *request.platforms.generate_pex_arg_list(),
78
                    *request.complete_platforms.generate_pex_arg_list(),
79
                    *request.extra_args,
80
                ),
81
                additional_input_digest=input_digest,
82
                output_files=output_files,
83
                output_directories=output_directories,
84
                description=request.description,
85
            )
86
        )
87
    )
88
    return PexVenv(digest=result.output_digest, path=request.output_path)
×
89

90

91
def rules():
×
92
    return [*collect_rules(), *pex_cli.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