-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
resolve pants plugins using direct pex
invocations
#21986
Open
tdyas
wants to merge
2
commits into
pantsbuild:main
Choose a base branch
from
shoalsoft:plugins/resolve-using-pex-directly
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/python/pants/backend/python/util_rules/pex_cli_tool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from pants.core.goals.resolves import ExportableTool | ||
from pants.core.util_rules import external_tool | ||
from pants.core.util_rules.external_tool import ( | ||
DownloadedExternalTool, | ||
ExternalToolRequest, | ||
TemplatedExternalTool, | ||
) | ||
from pants.engine.platform import Platform | ||
from pants.engine.rules import Get, collect_rules, rule | ||
from pants.engine.unions import UnionRule | ||
from pants.option.option_types import ArgsListOption | ||
from pants.util.meta import classproperty | ||
from pants.util.strutil import softwrap | ||
|
||
# Note: These rules were separated from `pex_cli.py` so that the plugin resolution code in | ||
# src/python/pants/init/plugin_resolver.py can rely on a downloaded `pex` tool without | ||
# bringing in other parts of the Python backend. | ||
|
||
|
||
class PexCli(TemplatedExternalTool): | ||
options_scope = "pex-cli" | ||
name = "pex" | ||
help = "The PEX (Python EXecutable) tool (https://github.com/pex-tool/pex)." | ||
|
||
default_version = "v2.33.1" | ||
default_url_template = "https://github.com/pex-tool/pex/releases/download/{version}/pex" | ||
version_constraints = ">=2.13.0,<3.0" | ||
|
||
# extra args to be passed to the pex tool; note that they | ||
# are going to apply to all invocations of the pex tool. | ||
global_args = ArgsListOption( | ||
example="--check=error --no-compile", | ||
extra_help=softwrap( | ||
""" | ||
Note that these apply to all invocations of the pex tool, including building `pex_binary` | ||
targets, preparing `python_test` targets to run, and generating lockfiles. | ||
""" | ||
), | ||
) | ||
|
||
@classproperty | ||
def default_known_versions(cls): | ||
return [ | ||
"|".join( | ||
( | ||
cls.default_version, | ||
plat, | ||
"5ebed0e2ba875983a72b4715ee3b2ca6ae5fedbf28d738634e02e30e3bb5ed28", | ||
"4559974", | ||
) | ||
) | ||
for plat in ["macos_arm64", "macos_x86_64", "linux_x86_64", "linux_arm64"] | ||
] | ||
|
||
|
||
class PexPEX(DownloadedExternalTool): | ||
"""The Pex PEX binary.""" | ||
|
||
|
||
@rule | ||
async def download_pex_pex(pex_cli: PexCli, platform: Platform) -> PexPEX: | ||
pex_pex = await Get(DownloadedExternalTool, ExternalToolRequest, pex_cli.get_request(platform)) | ||
return PexPEX(digest=pex_pex.digest, exe=pex_pex.exe) | ||
|
||
|
||
def rules(): | ||
return ( | ||
*collect_rules(), | ||
*external_tool.rules(), | ||
UnionRule(ExportableTool, PexCli), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this class to
pex_cli_tool.py
so that plugin resolution could depend directly on the Pex download rules.