Skip to content

Commit c98dda3

Browse files
committed
Clarify when we are subsetting the lockfile for 3rdparty dependencies (Cherry-pick of pantsbuild#12435)
[ci skip-rust] [ci skip-build-wheels]
1 parent cbabce9 commit c98dda3

File tree

2 files changed

+65
-12
lines changed

2 files changed

+65
-12
lines changed

src/python/pants/backend/python/util_rules/pex.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -654,24 +654,13 @@ async def build_pex(
654654
if request.pex_path:
655655
argv.extend(["--pex-path", ":".join(pex.name for pex in request.pex_path)])
656656

657-
description = request.description
658-
if description is None:
659-
if request.requirements:
660-
description = (
661-
f"Building {request.output_filename} with "
662-
f"{pluralize(len(request.requirements), 'requirement')}: "
663-
f"{', '.join(request.requirements)}"
664-
)
665-
else:
666-
description = f"Building {request.output_filename}"
667-
668657
process = await Get(
669658
Process,
670659
PexCliProcess(
671660
python=python,
672661
argv=argv,
673662
additional_input_digest=merged_digest,
674-
description=description,
663+
description=_build_pex_description(request),
675664
output_files=[request.output_filename],
676665
),
677666
)
@@ -699,6 +688,23 @@ async def build_pex(
699688
)
700689

701690

691+
def _build_pex_description(request: PexRequest) -> str:
692+
if request.description:
693+
return request.description
694+
if not request.requirements:
695+
return f"Building {request.output_filename}"
696+
if request.repository_pex:
697+
return (
698+
f"Extracting {pluralize(len(request.requirements), 'requirement')} "
699+
f"to build {request.output_filename} from {request.repository_pex.name}: "
700+
f"{', '.join(request.requirements)}"
701+
)
702+
return (
703+
f"Building {request.output_filename} with "
704+
f"{pluralize(len(request.requirements), 'requirement')}: {', '.join(request.requirements)}"
705+
)
706+
707+
702708
@rule
703709
async def create_pex(request: PexRequest) -> Pex:
704710
result = await Get(BuildPexResult, PexRequest, request)

src/python/pants/backend/python/util_rules/pex_test.py

+47
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
PexResolveInfo,
3434
VenvPex,
3535
VenvPexProcess,
36+
_build_pex_description,
3637
resolve_requirements_constraints_file,
3738
)
3839
from pants.backend.python.util_rules.pex import rules as pex_rules
@@ -681,3 +682,49 @@ def test_venv_pex_resolve_info(rule_runner: RuleRunner, pex_type: type[Pex | Ven
681682
assert dists[3].version == Version("2.23.0")
682683
assert Requirement.parse('PySocks!=1.5.7,>=1.5.6; extra == "socks"') in dists[3].requires_dists
683684
assert dists[4].project_name == "urllib3"
685+
686+
687+
def test_build_pex_description() -> None:
688+
def assert_description(
689+
requirements: PexRequirements,
690+
*,
691+
use_repo_pex: bool = False,
692+
description: str | None = None,
693+
expected: str,
694+
) -> None:
695+
repo_pex = Pex(EMPTY_DIGEST, "repo.pex", None) if use_repo_pex else None
696+
request = PexRequest(
697+
output_filename="new.pex",
698+
internal_only=True,
699+
requirements=requirements,
700+
description=description,
701+
repository_pex=repo_pex,
702+
)
703+
assert _build_pex_description(request) == expected
704+
705+
assert_description(PexRequirements(), description="Custom!", expected="Custom!")
706+
assert_description(
707+
PexRequirements(), description="Custom!", use_repo_pex=True, expected="Custom!"
708+
)
709+
710+
assert_description(PexRequirements(), expected="Building new.pex")
711+
assert_description(PexRequirements(), use_repo_pex=True, expected="Building new.pex")
712+
713+
assert_description(
714+
PexRequirements(["req"]), expected="Building new.pex with 1 requirement: req"
715+
)
716+
assert_description(
717+
PexRequirements(["req"]),
718+
use_repo_pex=True,
719+
expected="Extracting 1 requirement to build new.pex from repo.pex: req",
720+
)
721+
722+
assert_description(
723+
PexRequirements(["req1", "req2"]),
724+
expected="Building new.pex with 2 requirements: req1, req2",
725+
)
726+
assert_description(
727+
PexRequirements(["req1", "req2"]),
728+
use_repo_pex=True,
729+
expected="Extracting 2 requirements to build new.pex from repo.pex: req1, req2",
730+
)

0 commit comments

Comments
 (0)