Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify when we are subsetting the lockfile for 3rdparty dependencies (Cherry-pick of #12435) #12439

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/python/pants/backend/python/util_rules/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,24 +359,13 @@ async def build_pex(
if request.pex_path:
argv.extend(["--pex-path", ":".join(pex.name for pex in request.pex_path)])

description = request.description
if description is None:
if request.requirements:
description = (
f"Building {request.output_filename} with "
f"{pluralize(len(request.requirements), 'requirement')}: "
f"{', '.join(request.requirements)}"
)
else:
description = f"Building {request.output_filename}"

process = await Get(
Process,
PexCliProcess(
python=python,
argv=argv,
additional_input_digest=merged_digest,
description=description,
description=_build_pex_description(request),
output_files=[request.output_filename],
),
)
Expand Down Expand Up @@ -404,6 +393,23 @@ async def build_pex(
)


def _build_pex_description(request: PexRequest) -> str:
if request.description:
return request.description
if not request.requirements:
return f"Building {request.output_filename}"
if request.repository_pex:
return (
f"Extracting {pluralize(len(request.requirements), 'requirement')} "
f"to build {request.output_filename} from {request.repository_pex.name}: "
f"{', '.join(request.requirements)}"
)
return (
f"Building {request.output_filename} with "
f"{pluralize(len(request.requirements), 'requirement')}: {', '.join(request.requirements)}"
)


@rule
async def create_pex(request: PexRequest) -> Pex:
result = await Get(BuildPexResult, PexRequest, request)
Expand Down
49 changes: 48 additions & 1 deletion src/python/pants/backend/python/util_rules/pex_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
PexResolveInfo,
VenvPex,
VenvPexProcess,
_build_pex_description,
)
from pants.backend.python.util_rules.pex import rules as pex_rules
from pants.backend.python.util_rules.pex_cli import PexPEX
from pants.engine.fs import CreateDigest, Digest, FileContent
from pants.engine.fs import EMPTY_DIGEST, CreateDigest, Digest, FileContent
from pants.engine.process import Process, ProcessResult
from pants.testutil.rule_runner import QueryRule, RuleRunner

Expand Down Expand Up @@ -402,3 +403,49 @@ def test_venv_pex_resolve_info(rule_runner: RuleRunner, pex_type: type[Pex | Ven
assert dists[3].version == Version("2.23.0")
assert Requirement.parse('PySocks!=1.5.7,>=1.5.6; extra == "socks"') in dists[3].requires_dists
assert dists[4].project_name == "urllib3"


def test_build_pex_description() -> None:
def assert_description(
requirements: PexRequirements,
*,
use_repo_pex: bool = False,
description: str | None = None,
expected: str,
) -> None:
repo_pex = Pex(EMPTY_DIGEST, "repo.pex", None) if use_repo_pex else None
request = PexRequest(
output_filename="new.pex",
internal_only=True,
requirements=requirements,
description=description,
repository_pex=repo_pex,
)
assert _build_pex_description(request) == expected

assert_description(PexRequirements(), description="Custom!", expected="Custom!")
assert_description(
PexRequirements(), description="Custom!", use_repo_pex=True, expected="Custom!"
)

assert_description(PexRequirements(), expected="Building new.pex")
assert_description(PexRequirements(), use_repo_pex=True, expected="Building new.pex")

assert_description(
PexRequirements(["req"]), expected="Building new.pex with 1 requirement: req"
)
assert_description(
PexRequirements(["req"]),
use_repo_pex=True,
expected="Extracting 1 requirement to build new.pex from repo.pex: req",
)

assert_description(
PexRequirements(["req1", "req2"]),
expected="Building new.pex with 2 requirements: req1, req2",
)
assert_description(
PexRequirements(["req1", "req2"]),
use_repo_pex=True,
expected="Extracting 2 requirements to build new.pex from repo.pex: req1, req2",
)