From 25623dcccd0081f2a9c53b443bd29d24d4488a46 Mon Sep 17 00:00:00 2001 From: Tom Solberg Date: Sun, 9 Mar 2025 01:01:59 +0100 Subject: [PATCH 1/2] allow codegened sources for pex_binary.complete_platforms --- docs/notes/2.26.x.md | 3 +- .../pants/backend/python/util_rules/pex.py | 1 + .../backend/python/util_rules/pex_test.py | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/notes/2.26.x.md b/docs/notes/2.26.x.md index 32ded7fc82b..b22b109987b 100644 --- a/docs/notes/2.26.x.md +++ b/docs/notes/2.26.x.md @@ -25,6 +25,7 @@ New kubernetes backend! See [docs](https://www.pantsbuild.org/stable/docs/kubern - [Fixed](https://github.com/pantsbuild/pants/pull/21959) a bug where exponential backoff of file downloads could wait up to 18 days between retries under the default settings. [The `[GLOBAL].file_downloads_retry_delay ` option](https://www.pantsbuild.org/2.26/reference/global-options#file_downloads_retry_delay) is now used as a multiplier (previously it was the exponential base), and so any customisation of this option may need reconsideration for the new behaviour. - [Fixed](https://github.com/pantsbuild/pants/pull/22024) handling of non-absolute paths in PATH (see [#21954](https://github.com/pantsbuild/pants/issues/21954) for more info). +- [Fixed](https://github.com/pantsbuild/pants/pull/XXXXX) `pex_binary.complete_platforms` can now accept a codegened source, such as the result of an `shell_command`. #### New call-by-name syntax for @rules @@ -100,7 +101,7 @@ The Pants repo now uses Ruff format in lieu of Black. This was not a drop-in rep `@rule` decorators have been re-typed, which should allow better call site return-type visibility (fewer `Unknown`s and `Any`s). Decorator factories of the form `@rule(desc=..., level=..., ...)` have also been strongly typed. This may cause typechecking errors for plugin authors, if the plugin is using incorrect types. However, this likely would have manifested as a runtime crash, otherwise. -A bug in the Django backend has been fixed so that a repo may have no Django apps without error. +A bug in the Django backend has been fixed so that a repo may have no Django apps without error. [Pytype](https://www.pantsbuild.org/stable/reference/subsystems/pytype) was updated to version 2024.9.13 - which is the [last to support Python 3.8 and Python 3.9](https://github.com/google/pytype/blob/main/CHANGELOG). diff --git a/src/python/pants/backend/python/util_rules/pex.py b/src/python/pants/backend/python/util_rules/pex.py index ba88b8a26e3..310ddc3c237 100644 --- a/src/python/pants/backend/python/util_rules/pex.py +++ b/src/python/pants/backend/python/util_rules/pex.py @@ -143,6 +143,7 @@ async def digest_complete_platform_addresses( FileSourceField, ResourceSourceField, ), + enable_codegen=True, ), ) for tgt in original_file_targets diff --git a/src/python/pants/backend/python/util_rules/pex_test.py b/src/python/pants/backend/python/util_rules/pex_test.py index 4ee809ee895..9c14a02d6fe 100644 --- a/src/python/pants/backend/python/util_rules/pex_test.py +++ b/src/python/pants/backend/python/util_rules/pex_test.py @@ -59,6 +59,7 @@ parse_requirements, ) from pants.core.goals.generate_lockfiles import GenerateLockfileResult +from pants.core.register import wrap_as_resources from pants.core.target_types import FileTarget, ResourceTarget from pants.core.util_rules.lockfile_metadata import InvalidLockfileError from pants.engine.fs import ( @@ -93,6 +94,7 @@ def rule_runner() -> RuleRunner: rules=[ *pex_test_utils.rules(), *pex_rules(), + *wrap_as_resources.rules, QueryRule(GlobalOptions, []), QueryRule(ProcessResult, (Process,)), QueryRule(PexResolveInfo, (Pex,)), @@ -102,6 +104,7 @@ def rule_runner() -> RuleRunner: target_types=[ ResourceTarget, FileTarget, + *wrap_as_resources.target_types, ], ) @@ -946,3 +949,31 @@ def test_digest_complete_platforms(rule_runner: RuleRunner, target_type: str) -> # Verify the result assert len(complete_platforms) == 1 assert complete_platforms.digest != EMPTY_DIGEST + + +def test_digest_complete_platforms_codegen(rule_runner: RuleRunner) -> None: + # Read the complete_platforms content using pkgutil + complete_platforms_content = pkgutil.get_data(__name__, "complete_platform_pex_test.json") + assert complete_platforms_content is not None + + # Create a target with the complete platforms file + rule_runner.write_files( + { + "BUILD": """\ +file(name='complete_platforms', source='complete_platforms.json') +experimental_wrap_as_resources(name="codegen", inputs=[':complete_platforms'], ) + """, + "complete_platforms.json": complete_platforms_content, + } + ) + + # Get the CompletePlatforms object + target = rule_runner.get_target(Address("", target_name="codegen")) + complete_platforms = rule_runner.request( + CompletePlatforms, + [PexCompletePlatformsField([":codegen"], target.address)], + ) + + # Verify the result + assert len(complete_platforms) == 1 + assert complete_platforms.digest != EMPTY_DIGEST From e42df339a300c062d43b8fb1002e58b957144348 Mon Sep 17 00:00:00 2001 From: Tom Solberg Date: Sun, 9 Mar 2025 11:51:18 +0100 Subject: [PATCH 2/2] notes path --- docs/notes/2.26.x.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/notes/2.26.x.md b/docs/notes/2.26.x.md index b22b109987b..1122fbce4c1 100644 --- a/docs/notes/2.26.x.md +++ b/docs/notes/2.26.x.md @@ -25,7 +25,7 @@ New kubernetes backend! See [docs](https://www.pantsbuild.org/stable/docs/kubern - [Fixed](https://github.com/pantsbuild/pants/pull/21959) a bug where exponential backoff of file downloads could wait up to 18 days between retries under the default settings. [The `[GLOBAL].file_downloads_retry_delay ` option](https://www.pantsbuild.org/2.26/reference/global-options#file_downloads_retry_delay) is now used as a multiplier (previously it was the exponential base), and so any customisation of this option may need reconsideration for the new behaviour. - [Fixed](https://github.com/pantsbuild/pants/pull/22024) handling of non-absolute paths in PATH (see [#21954](https://github.com/pantsbuild/pants/issues/21954) for more info). -- [Fixed](https://github.com/pantsbuild/pants/pull/XXXXX) `pex_binary.complete_platforms` can now accept a codegened source, such as the result of an `shell_command`. +- [Fixed](https://github.com/pantsbuild/pants/pull/22059) `pex_binary.complete_platforms` can now accept a codegened source, such as the result of an `shell_command`. #### New call-by-name syntax for @rules