-
-
Notifications
You must be signed in to change notification settings - Fork 698
refactor(pypi): reuse the same whl_library instances #3856
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
Draft
aignas
wants to merge
10
commits into
bazel-contrib:main
Choose a base branch
from
aignas:aignas.refactor.single_dep_whl_library
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.
+479
−25
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ab461fe
plan.md
aignas 21f9bc1
fix
aignas 5eb1566
wip
aignas 916634a
wip
aignas f1325de
wip
aignas fbee9d3
wip
aignas eedb2a9
wip
aignas 2c8d44a
feat(pypi): add whl_library_optimized mode behind env var gate
aignas 7f85449
feat(pypi): implement hub aliases for optimized whl_library extras
aignas f3fa6c9
feat(pypi): forward optimized whl extras to unified hub repo
aignas 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 hidden or 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 hidden or 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 hidden or 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,131 @@ | ||
| # Single dep for spoke repos per `whl_name`. | ||
|
|
||
| The goal is to have `whl_library` instances from wheels (where we pass `url` for a URL or we pass | ||
| a `whl_file` label which points to an actual wheel) to be reused across different python versions | ||
| and across different configurations where different extras are requested. This means that | ||
| if the user is using the same wheel in 2 different configurations, the wheel is reused, because | ||
| the extracted contents should not differ. This could be important for: | ||
| * platform-specific wheels for custom platforms defined by the user. Otherwise the | ||
| platform-specific wheel behaviour should remain unchanged. | ||
| * cross-platform wheels for are the main affected item here. | ||
|
|
||
| The code should be gated by a feature flag, which can be flipped to be enabled using an | ||
| environmental variable via | ||
|
|
||
| The file to modify `python/private/internal_config_repo.bzl`. Use the | ||
| `RULES_PYTHON_WHL_LIBRARY_OPTIMIZED=1` to enable the feature. Add it to the | ||
| `docs/readthedocs_build.sh` file so that we are exercising the code. And document this in | ||
| the `docs/environment-variables.md` file. | ||
| If the flag is off, then it is equivalent to the current | ||
| `main` branch behaviour, if it is on, then it is equivalent to turning all of the behaviour | ||
| implemented here on. | ||
|
|
||
| Since this is a refactor for users not using private APIs, the env variable will be switched/removed | ||
| later together with old code. | ||
|
|
||
| All of the code should be written in a TDD style where we add a failing test for a feature and then | ||
| we implement the new code. | ||
|
|
||
| ## Change the naming of the spoke repositories: | ||
|
|
||
| > The hub repositories should be named `<hub_name>_<wheel_name_suffix>. | ||
|
|
||
| The names should be changed: | ||
| * from `+pip+dev_pip_314_requests_py3_none_any_2a0d60c1_linux_x86_64_linux_x86_64_freethreaded` | ||
| to `+pip+dev_pip_requests_py3_none_any_2a0d60c1` | ||
| * from `+pip+dev_pip_314_roman_numerals_py3_none_any_647ba99c` | ||
| to `+pip+dev_pip_roman_numerals_py3_none_any_647ba99c` | ||
| * from `+pip+dev_pip_314_markupsafe_cp314_cp314t_manylinux_2_17_x86_64_fed51ac4` | ||
| to `+pip+dev_pip_markupsafe_cp314_cp314t_manylinux_2_17_x86_64_fed51ac4` | ||
|
|
||
| So the naming convention after the change is: | ||
| `<prefix>_<name>_<py_tag>_<abi_tag>_<platform_tag>_<sha256[:8]>` | ||
|
|
||
| Where `<prefix>` is the hub repository name and the rest of the segments come from the wheel name | ||
| itself. | ||
|
|
||
| The sdist building `whl_library` instances should change the naming to: | ||
| `<prefix>_<name>_<sha256[:8]>_<rules_python_target_platform>` | ||
|
|
||
| The file to modify `python/private/pypi/whl_repo_name.bzl` | ||
|
|
||
| ## Change the `whl_library_targets` | ||
|
|
||
| Using the `METADATA` file that is parsed from `whl_metadata` function where the `Provides-Extra` is | ||
| retrieved from the file. Right now we generate a single target which includes all of the extras that | ||
| are required. Instead do the following target generation: | ||
| * `pkg` (no extras) - target with no extras, this is the main target that includes the python sources, | ||
| the other targets just include extra dependencies. | ||
| * `pkg__extra` - target for each extra in the provides-extra list. If the target depends on | ||
| `self[another_extra]`, then explode the nodes so that the target only depends on `pkg` target + | ||
| extra dependencies. Use `py_library` for this. Also be smart about generating targets: | ||
| - If the only extra is in the env marker, but the dependency is not in the hub repo, then skip | ||
| generating the whole `pkg__extra` target. | ||
| - Propose any extra ideas here. | ||
|
|
||
| Related files: | ||
| * `python/private/pypi/whl_library.bzl` | ||
| * `python/private/pypi/whl_metadata.bzl` | ||
| * `python/private/pypi/whl_library_targets.bzl` | ||
|
|
||
| ## Change `hub_builder` and `hub_repository` | ||
|
|
||
| Instead of passing the `requirement[extra1,extra2]` to the `whl_library`, pass it to the | ||
| `hub_repository` via `whl_config_setting` so that the `render_pkg_aliases` is using the information to alias to the right | ||
| extra target based on what is requested. This should retain the behaviour where different target | ||
| platforms are allowed to target `foo[baz]` and `foo[bar]` and we select the | ||
| `@dev_pip_spoke_repo//:pkg__baz` and `@dev_pip_spoke_repo//:pkg__bar` appropriately. | ||
|
|
||
| We should also generate extra targets here: | ||
| * `pkg` should point to the target with all specified extras as passed to the `hub_repository`. This is to keep backwards compatibility with how it used to be done | ||
| previously. This also keeps compatibility with `rules_pycross`. Add this as a comment | ||
| when doing this. The spoke repos should not be used directly, so this difference in | ||
| behaviour is OK. | ||
| This reuses the targets declared in the hub repository described below. | ||
| It is backed by a `py_library` target if there are multiple extras, or an `alias` if it | ||
| is only a single extra. It is the same target as described below. | ||
| * `pkg[]` should point to the target in the spoke without extras | ||
| * `pkg[extra]` should point to the target in the spoke with particular extras. Do this for each | ||
| provided extra. So for `requirements[extra1,extra2]` passed to the hub repo, 2 extra targets will | ||
| be created. If the extras have not been specified for certain platforms via the | ||
| `whl_config_setting`, then the `select` statement should raise an `error` for no match. | ||
| Document the mapping explicitly: hub `pkg[]` → spoke `pkg`, hub `pkg[extra]` → spoke `pkg__extra`. | ||
| The fact that some of the targets in the spoke repos are unreachable is intentional - this is | ||
| because the hub repository contents are created before the `whl_library` downloads the whl and | ||
| inspects the METADATA. | ||
| The reverse direction is not a concern because the requirements file locking results in | ||
| consistent file. If something like this happens, then we should provide a message to the | ||
| user that something went wrong and that they should create a ticket in rules_python bug | ||
| tracker. | ||
| * If there is `requirement[extra1,extra2]` passed, that means that we should create a special alias | ||
| that includes both of the targets at once. For this use `py_library` instead of `alias` and pass | ||
| `:pkg[extra1]` and `:pkg[extra2]` to the `deps` of the `py_library`. This won't cause | ||
| a failure because for a particular platform that is requested this should work by | ||
| construction, because the dependency targets will be also defined for the particular platform. | ||
|
|
||
| * If the `requirement` is passed without any extras, then hub `pkg` should alias to `pkg[]`. | ||
| * If the target is `py_library`, then we should name it without `[]` to avoid any aspects traversing | ||
| `py_library` targets changing behaviour. Only alias targets can have `[]`. | ||
|
|
||
| Related files: | ||
| * `python/private/pypi/render_pkg_aliases.bzl` | ||
| * `python/private/pypi/hub_builder.bzl` | ||
| * `python/private/pypi/hub_repository.bzl` | ||
| * `python/private/pypi/whl_config_setting.bzl` - consider extending this struct to specify which | ||
| extras are requested for which platform. | ||
|
|
||
| ## Modify `pip_repository` | ||
|
|
||
| Do similar changes to the `WORKSPACE` code to ensure easier maintenance of `whl_library` so that all | ||
| code paths to `whl_library` remain consistent. | ||
|
|
||
| File: | ||
| * `python/private/pypi/pip_repository.bzl` | ||
|
|
||
| ## Modify `unified_hub_repo` | ||
|
|
||
| Pass the extras to the `unified_hub_repo` as well so that the extra targets are created. The target | ||
| topology in the unified hub repo should correspond to the hub_repository. | ||
|
|
||
| File: | ||
| * `python/private/pypi/unified_hub_repo.bzl` |
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
There is a naming mismatch between the unified hub alias name and the hub repository package name. The unified hub alias is generated with double underscores
__(e.g.,requests__security), whereasrender_pkg_aliases.bzlgenerates the hub repository package with a single underscore_(e.g.,requests_security). This mismatch will cause the unified hub aliases to point to non-existent packages. Update this to use a single underscore to match the hub repository package naming.