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

allow codegened sources for pex_binary.complete_platforms #22059

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion docs/notes/2.26.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/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

Expand Down Expand Up @@ -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).

Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/python/util_rules/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async def digest_complete_platform_addresses(
FileSourceField,
ResourceSourceField,
),
enable_codegen=True,
),
)
for tgt in original_file_targets
Expand Down
31 changes: 31 additions & 0 deletions src/python/pants/backend/python/util_rules/pex_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,)),
Expand All @@ -102,6 +104,7 @@ def rule_runner() -> RuleRunner:
target_types=[
ResourceTarget,
FileTarget,
*wrap_as_resources.target_types,
],
)

Expand Down Expand Up @@ -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
Loading