-
Notifications
You must be signed in to change notification settings - Fork 559
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
Add support for multi-platform pip download
to pip_parse
#510
Closed
Closed
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -100,6 +100,11 @@ def _pip_repository_impl(rctx): | |||||
"--timeout", | ||||||
str(rctx.attr.timeout), | ||||||
] | ||||||
if rctx.attr.pip_platform_definitions: | ||||||
args.extend([ | ||||||
"--pip_platform_definitions", | ||||||
struct(arg = {str(k): v for k, v in rctx.attr.pip_platform_definitions.items()}).to_json(), | ||||||
]) | ||||||
else: | ||||||
args = [ | ||||||
python_interpreter, | ||||||
|
@@ -178,6 +183,11 @@ pip_repository_attrs = { | |||||
default = False, | ||||||
doc = "Create the repository in incremental mode.", | ||||||
), | ||||||
"pip_platform_definitions": attr.label_keyed_string_dict( | ||||||
doc = """ | ||||||
A map of select keys to platform definitions in the form <platform>-<python_version>-<implementation>-<abi>" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Just a nit, but helpful to distinguish from a Bazel |
||||||
""", | ||||||
), | ||||||
"requirements": attr.label( | ||||||
allow_single_file = True, | ||||||
doc = "A 'requirements.txt' pip requirements file.", | ||||||
|
@@ -252,6 +262,12 @@ def _impl_whl_library(rctx): | |||||
] | ||||||
args = _parse_optional_attrs(rctx, args) | ||||||
|
||||||
if rctx.attr.pip_platform_definition: | ||||||
args.extend([ | ||||||
"--pip_platform_definition", | ||||||
rctx.attr.pip_platform_definition, | ||||||
]) | ||||||
|
||||||
result = rctx.execute( | ||||||
args, | ||||||
# Manually construct the PYTHONPATH since we cannot use the toolchain here | ||||||
|
@@ -266,6 +282,9 @@ def _impl_whl_library(rctx): | |||||
return | ||||||
|
||||||
whl_library_attrs = { | ||||||
"pip_platform_definition": attr.string( | ||||||
doc = "A pip platform definition in the form <platform>-<python_version>-<implementation>-<abi>", | ||||||
), | ||||||
"repo": attr.string( | ||||||
mandatory = True, | ||||||
doc = "Pointer to parent repo name. Used to make these rules rerun if the parent repo changes.", | ||||||
|
@@ -285,3 +304,29 @@ Download and extracts a single wheel based into a bazel repo based on the requir | |||||
Instantiated from pip_repository and inherits config options from there.""", | ||||||
implementation = _impl_whl_library, | ||||||
) | ||||||
|
||||||
_PLATFORM_ALIAS_TMPL = """ | ||||||
alias( | ||||||
name = "pkg", | ||||||
actual = select({select_items}), | ||||||
visibility = ["//visibility:public"], | ||||||
) | ||||||
""" | ||||||
|
||||||
def _impl_platform_alias(rctx): | ||||||
rctx.file( | ||||||
"BUILD", | ||||||
content = _PLATFORM_ALIAS_TMPL.format( | ||||||
select_items = rctx.attr.select_items, | ||||||
), | ||||||
executable = False, | ||||||
) | ||||||
|
||||||
platform_alias = repository_rule( | ||||||
attrs = { | ||||||
"select_items": attr.string_dict(), | ||||||
}, | ||||||
implementation = _impl_platform_alias, | ||||||
doc = """ | ||||||
An internal rule used to create an alias for a pip package for the appropriate platform.""", | ||||||
) |
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.
Q: why this format instead of the format listed here in PEP 425?
{python tag}-{abi tag}-{platform tag}
The extra bit in this PR's string is
{implementation}
,cp = CPython
, but this is covered by the{python tag}
from PEP 425.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.
It's because
pip download
takes four flags:--platform
,--python-version
,--implementation
,--abi
. I'm not sure why pip doesn't line up with the PEP 425 format.