Skip to content

Commit 94021c6

Browse files
authored
Remove deprecated fallback to underspecified "platforms" for FaaS targets (#21928)
This removes the fallback to using PEX's `--platform` argument for AWS Lambda or Google Cloud Functions targets that don't have a built-in complete platforms, if the user doesn't provide a complete platforms. This has been deprecated since 2.23 (#21342). This removal also unblocks some removal of the support code for this FaaS functionality.
1 parent bda875d commit 94021c6

File tree

3 files changed

+63
-32
lines changed

3 files changed

+63
-32
lines changed

docs/notes/2.26.x.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Thank you to [Klayvio](https://www.klaviyo.com/) and [Normal Computing](https://
2929
Some deprecations have expired and been removed:
3030

3131
- the `[export].py_hermetic_scripts` option has been replaced by [the `[export].py_non_hermetic_scripts_in_resolve` option](https://www.pantsbuild.org/2.25/reference/goals/export#py_non_hermetic_scripts_in_resolve)
32+
- for FaaS targets (AWS Lambda and Google Cloud Functions), automatic fallback to underspecified "platforms" for unknown runtimes without a pre-packaged complete-platforms has been replaced by requiring an [explicit `complete_platforms` value](https://www.pantsbuild.org/2.25/reference/targets/python_aws_lambda_function#complete_platforms)
3233

3334
#### Terraform
3435

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

+4-14
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929
PythonResolveField,
3030
)
3131
from pants.backend.python.util_rules.interpreter_constraints import InterpreterConstraints
32-
from pants.backend.python.util_rules.pex import CompletePlatforms, Pex, PexPlatforms
32+
from pants.backend.python.util_rules.pex import CompletePlatforms, Pex
3333
from pants.backend.python.util_rules.pex_from_targets import (
3434
InterpreterConstraintsRequest,
3535
PexFromTargetsRequest,
3636
)
3737
from pants.backend.python.util_rules.pex_from_targets import rules as pex_from_targets_rules
3838
from pants.backend.python.util_rules.pex_venv import PexVenv, PexVenvLayout, PexVenvRequest
3939
from pants.backend.python.util_rules.pex_venv import rules as pex_venv_rules
40-
from pants.base.deprecated import warn_or_error
4140
from pants.core.goals.package import BuiltPackage, BuiltPackageArtifact, OutputPathField
4241
from pants.engine.addresses import Address, UnparsedAddressInputs
4342
from pants.engine.fs import (
@@ -369,7 +368,6 @@ class RuntimePlatformsRequest:
369368
@dataclass(frozen=True)
370369
class RuntimePlatforms:
371370
interpreter_version: None | tuple[int, int]
372-
pex_platforms: PexPlatforms = PexPlatforms()
373371
complete_platforms: CompletePlatforms = CompletePlatforms()
374372

375373

@@ -445,10 +443,7 @@ async def infer_runtime_platforms(request: RuntimePlatformsRequest) -> RuntimePl
445443
known_runtimes_str = ", ".join(
446444
FrozenOrderedSet(r.name for r in request.runtime.known_runtimes)
447445
)
448-
warn_or_error(
449-
# Replace this with an unconditional `InvalidTargetException`
450-
"2.26.0.dev0",
451-
"implicitly resolving platforms for unknown FaaS runtimes",
446+
raise InvalidTargetException(
452447
softwrap(
453448
f"""
454449
Could not find a known runtime for the {version_adjective} Python version and machine architecture!
@@ -465,11 +460,8 @@ async def infer_runtime_platforms(request: RuntimePlatformsRequest) -> RuntimePl
465460
architecture.
466461
"""
467462
),
468-
)
469-
return RuntimePlatforms(
470-
interpreter_version=version,
471-
pex_platforms=PexPlatforms((_format_platform_from_major_minor(*version),)),
472-
)
463+
description_of_origin=f"In the {request.target_name!r} target",
464+
) from None
473465

474466
module = request.runtime.known_runtimes_complete_platforms_module()
475467

@@ -567,7 +559,6 @@ async def build_python_faas(
567559
include_requirements=request.include_requirements,
568560
include_source_files=request.include_sources,
569561
output_filename=repository_filename,
570-
platforms=platforms.pex_platforms,
571562
complete_platforms=platforms.complete_platforms,
572563
layout=PexLayout.PACKED,
573564
additional_args=additional_pex_args,
@@ -589,7 +580,6 @@ async def build_python_faas(
589580
PexVenvRequest(
590581
pex=pex_result,
591582
layout=layout,
592-
platforms=platforms.pex_platforms,
593583
complete_platforms=platforms.complete_platforms,
594584
extra_args=request.pex3_venv_create_extra_args.value or (),
595585
prefix=request.prefix_in_artifact,

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

+58-18
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
RuntimePlatformsRequest,
3636
build_python_faas,
3737
)
38-
from pants.backend.python.util_rules.pex import CompletePlatforms, Pex, PexPlatforms
38+
from pants.backend.python.util_rules.pex import CompletePlatforms, Pex
3939
from pants.backend.python.util_rules.pex_from_targets import PexFromTargetsRequest
4040
from pants.backend.python.util_rules.pex_venv import PexVenv, PexVenvLayout, PexVenvRequest
4141
from pants.build_graph.address import Address
@@ -269,21 +269,17 @@ def from_interpreter_version(cls, py_major: int, py_minor: int) -> str:
269269

270270

271271
@pytest.mark.parametrize(
272-
("value", "expected_interpreter_version", "expected_platforms", "expected_complete_platforms"),
272+
("value", "expected_interpreter_version", "expected_complete_platforms"),
273273
[
274+
pytest.param("3.45", (3, 45), ["complete_platform_faas-test-3-45.json"], id="known 3.45"),
274275
pytest.param(
275-
"3.45", (3, 45), [], ["complete_platform_faas-test-3-45.json"], id="known 3.45"
276+
"67.89", (67, 89), ["complete_platform_faas-test-67-89.json"], id="known 67.89"
276277
),
277-
pytest.param(
278-
"67.89", (67, 89), [], ["complete_platform_faas-test-67-89.json"], id="known 67.89"
279-
),
280-
pytest.param("98.76", (98, 76), ["linux_x86_64-cp-9876-cp9876"], [], id="unknown 98.76"),
281278
],
282279
)
283-
def test_infer_runtime_platforms_when_runtime_and_no_complete_platforms(
280+
def test_infer_runtime_platforms_when_known_runtime_and_no_complete_platforms(
284281
value: str,
285282
expected_interpreter_version: tuple[int, int],
286-
expected_platforms: list[str],
287283
expected_complete_platforms: list[str],
288284
rule_runner: RuleRunner,
289285
) -> None:
@@ -301,11 +297,30 @@ def test_infer_runtime_platforms_when_runtime_and_no_complete_platforms(
301297

302298
assert platforms == RuntimePlatforms(
303299
expected_interpreter_version,
304-
PexPlatforms(expected_platforms),
305300
CompletePlatforms(expected_complete_platforms),
306301
)
307302

308303

304+
def test_infer_runtime_platforms_errors_when_unknown_runtime_and_no_complete_platforms(
305+
rule_runner: RuleRunner,
306+
) -> None:
307+
address = Address("path", target_name="target")
308+
309+
request = RuntimePlatformsRequest(
310+
address=address,
311+
target_name="unused",
312+
runtime=TestRuntimeField("98.76", address),
313+
complete_platforms=PythonFaaSCompletePlatforms(None, address),
314+
architecture=FaaSArchitecture.X86_64,
315+
)
316+
317+
with pytest.raises(
318+
ExecutionError,
319+
match=r"(?s).*Could not find a known runtime for the specified Python version",
320+
):
321+
rule_runner.request(RuntimePlatforms, [request])
322+
323+
309324
def test_infer_runtime_platforms_when_complete_platforms(
310325
rule_runner: RuleRunner,
311326
) -> None:
@@ -321,26 +336,26 @@ def test_infer_runtime_platforms_when_complete_platforms(
321336

322337
platforms = rule_runner.request(RuntimePlatforms, [request])
323338

324-
assert platforms == RuntimePlatforms(None, PexPlatforms(), CompletePlatforms(["path/cp.json"]))
339+
assert platforms == RuntimePlatforms(None, CompletePlatforms(["path/cp.json"]))
325340

326341

327342
@pytest.mark.parametrize(
328-
("ics", "expected_interpreter_version", "expected_platforms", "expected_complete_platforms"),
343+
("ics", "expected_interpreter_version", "expected_complete_platforms"),
329344
[
330345
pytest.param(
331346
"==3.45.*",
332347
(3, 45),
333-
[],
334348
["complete_platform_faas-test-3-45.json"],
335-
id="known 3.45",
349+
id="star",
350+
),
351+
pytest.param(
352+
">=3.45,<3.46", (3, 45), ["complete_platform_faas-test-3-45.json"], id="range"
336353
),
337-
pytest.param(">=3.33,<3.34", (3, 33), ["linux_x86_64-cp-333-cp333"], [], id="unknown 3.33"),
338354
],
339355
)
340-
def test_infer_runtime_platforms_when_narrow_ics_only(
356+
def test_infer_runtime_platforms_when_known_narrow_ics_only(
341357
ics: str,
342358
expected_interpreter_version: tuple[int, int],
343-
expected_platforms: list[str],
344359
expected_complete_platforms: list[str],
345360
rule_runner: RuleRunner,
346361
) -> None:
@@ -364,11 +379,36 @@ def test_infer_runtime_platforms_when_narrow_ics_only(
364379

365380
assert platforms == RuntimePlatforms(
366381
expected_interpreter_version,
367-
PexPlatforms(expected_platforms),
368382
CompletePlatforms(expected_complete_platforms),
369383
)
370384

371385

386+
def test_infer_runtime_platforms_errors_when_unknown_narrow_ics(
387+
rule_runner: RuleRunner,
388+
) -> None:
389+
rule_runner.write_files(
390+
{
391+
"path/BUILD": "python_sources(name='target', interpreter_constraints=['==3.33.*'])",
392+
"path/x.py": "",
393+
}
394+
)
395+
396+
address = Address("path", target_name="target")
397+
request = RuntimePlatformsRequest(
398+
address=address,
399+
target_name="example_target",
400+
runtime=TestRuntimeField(None, address),
401+
complete_platforms=PythonFaaSCompletePlatforms(None, address),
402+
architecture=FaaSArchitecture.X86_64,
403+
)
404+
405+
with pytest.raises(
406+
ExecutionError,
407+
match=r"(?s).*Could not find a known runtime for the inferred Python version",
408+
):
409+
rule_runner.request(RuntimePlatforms, [request])
410+
411+
372412
@pytest.mark.parametrize(
373413
"ics",
374414
[

0 commit comments

Comments
 (0)