-
-
Notifications
You must be signed in to change notification settings - Fork 586
refactor(pypi): implement PEP508 compliant marker evaluation #2692
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
Merged
aignas
merged 10 commits into
bazel-contrib:main
from
aignas:feat/extension-eval-without-python
Mar 30, 2025
Merged
refactor(pypi): implement PEP508 compliant marker evaluation #2692
aignas
merged 10 commits into
bazel-contrib:main
from
aignas:feat/extension-eval-without-python
Mar 30, 2025
Conversation
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 implements the PEP508 compliant marker evaluation in starlark and removes the need for the Python interpreter when evaluating requirements files passed to `pip.parse`. This makes the evaluation faster and allows us to fix a few known issues (bazel-contrib#2690). In the future the intent is to move the `METADATA` parsing to pure starlark so that the `RequiresDist` could be parsed in starlark at the macro evaluation or analysis phases. This should make it possible to more easily solve the design problem that more and more things need to be passed to `whl_library` as args to have a robust dependency parsing: * bazel-contrib#2319 needs the full Python version to have correct cross-platform compatible METADATA parsing and passing it to `Python` and back makes it difficult/annoying to implement. * Parsing the `METADATA` file requires the precise list of target platform or the list of available packages in the `requirements.txt`. This means that without it we cannot trim the dependency tree in the `whl_library`. Doing this at macro loading phase allows us to depend on `.bzl` files in the `hub_repository` and more effectively pass information. Fixes bazel-contrib#2423
rickeylev
approved these changes
Mar 29, 2025
aignas
commented
Mar 29, 2025
Refreshed the lockfile before and after the change:
And saw no difference in entries except for the expected:
|
OK, I think this is ready to be merged. This is probably already higher fidelity/more robust than the Python impl of |
github-merge-queue bot
pushed a commit
that referenced
this pull request
Apr 13, 2025
This PR starts using the newly introduced (#2692) PEP508 compliant requirement marker parser in starlark and moves the dependency generation from the Python language (`whl_installer`) to the Starlark in the `whl_library` repository rule. This PR is (almost) a pure refactor where no bugs are fixed, but this is foundational work that also adds notes on how things will be moved to macros (i.e. analysis phase) so that we can fix a few long standing bugs and prepare for stabilizing the `experimental_index_url` (#260). Refactor: * I have migrated all of the unit tests from Python to starlark for deps generation from METADATA `Requires-Dist` fields. * Read the `METADATA` file itself in Starlark. Work towards #260, #2319, #2241 Fixes #2423
ewianda
pushed a commit
to ewianda/rules_python
that referenced
this pull request
Apr 14, 2025
…ontrib#2629) This PR starts using the newly introduced (bazel-contrib#2692) PEP508 compliant requirement marker parser in starlark and moves the dependency generation from the Python language (`whl_installer`) to the Starlark in the `whl_library` repository rule. This PR is (almost) a pure refactor where no bugs are fixed, but this is foundational work that also adds notes on how things will be moved to macros (i.e. analysis phase) so that we can fix a few long standing bugs and prepare for stabilizing the `experimental_index_url` (bazel-contrib#260). Refactor: * I have migrated all of the unit tests from Python to starlark for deps generation from METADATA `Requires-Dist` fields. * Read the `METADATA` file itself in Starlark. Work towards bazel-contrib#260, bazel-contrib#2319, bazel-contrib#2241 Fixes bazel-contrib#2423
ewianda
pushed a commit
to ewianda/rules_python
that referenced
this pull request
Apr 14, 2025
…ontrib#2629) This PR starts using the newly introduced (bazel-contrib#2692) PEP508 compliant requirement marker parser in starlark and moves the dependency generation from the Python language (`whl_installer`) to the Starlark in the `whl_library` repository rule. This PR is (almost) a pure refactor where no bugs are fixed, but this is foundational work that also adds notes on how things will be moved to macros (i.e. analysis phase) so that we can fix a few long standing bugs and prepare for stabilizing the `experimental_index_url` (bazel-contrib#260). Refactor: * I have migrated all of the unit tests from Python to starlark for deps generation from METADATA `Requires-Dist` fields. * Read the `METADATA` file itself in Starlark. Work towards bazel-contrib#260, bazel-contrib#2319, bazel-contrib#2241 Fixes bazel-contrib#2423
ewianda
pushed a commit
to ewianda/rules_python
that referenced
this pull request
Apr 14, 2025
…ontrib#2629) This PR starts using the newly introduced (bazel-contrib#2692) PEP508 compliant requirement marker parser in starlark and moves the dependency generation from the Python language (`whl_installer`) to the Starlark in the `whl_library` repository rule. This PR is (almost) a pure refactor where no bugs are fixed, but this is foundational work that also adds notes on how things will be moved to macros (i.e. analysis phase) so that we can fix a few long standing bugs and prepare for stabilizing the `experimental_index_url` (bazel-contrib#260). Refactor: * I have migrated all of the unit tests from Python to starlark for deps generation from METADATA `Requires-Dist` fields. * Read the `METADATA` file itself in Starlark. Work towards bazel-contrib#260, bazel-contrib#2319, bazel-contrib#2241 Fixes bazel-contrib#2423
ewianda
pushed a commit
to ewianda/rules_python
that referenced
this pull request
Apr 14, 2025
…ontrib#2629) This PR starts using the newly introduced (bazel-contrib#2692) PEP508 compliant requirement marker parser in starlark and moves the dependency generation from the Python language (`whl_installer`) to the Starlark in the `whl_library` repository rule. This PR is (almost) a pure refactor where no bugs are fixed, but this is foundational work that also adds notes on how things will be moved to macros (i.e. analysis phase) so that we can fix a few long standing bugs and prepare for stabilizing the `experimental_index_url` (bazel-contrib#260). Refactor: * I have migrated all of the unit tests from Python to starlark for deps generation from METADATA `Requires-Dist` fields. * Read the `METADATA` file itself in Starlark. Work towards bazel-contrib#260, bazel-contrib#2319, bazel-contrib#2241 Fixes bazel-contrib#2423 fix(toolchain) Override coverage rc
ewianda
pushed a commit
to ewianda/rules_python
that referenced
this pull request
Apr 14, 2025
…ontrib#2629) This PR starts using the newly introduced (bazel-contrib#2692) PEP508 compliant requirement marker parser in starlark and moves the dependency generation from the Python language (`whl_installer`) to the Starlark in the `whl_library` repository rule. This PR is (almost) a pure refactor where no bugs are fixed, but this is foundational work that also adds notes on how things will be moved to macros (i.e. analysis phase) so that we can fix a few long standing bugs and prepare for stabilizing the `experimental_index_url` (bazel-contrib#260). Refactor: * I have migrated all of the unit tests from Python to starlark for deps generation from METADATA `Requires-Dist` fields. * Read the `METADATA` file itself in Starlark. Work towards bazel-contrib#260, bazel-contrib#2319, bazel-contrib#2241 Fixes bazel-contrib#2423 fix(toolchain) Override coverage rc
ewianda
pushed a commit
to ewianda/rules_python
that referenced
this pull request
Apr 14, 2025
…ontrib#2629) This PR starts using the newly introduced (bazel-contrib#2692) PEP508 compliant requirement marker parser in starlark and moves the dependency generation from the Python language (`whl_installer`) to the Starlark in the `whl_library` repository rule. This PR is (almost) a pure refactor where no bugs are fixed, but this is foundational work that also adds notes on how things will be moved to macros (i.e. analysis phase) so that we can fix a few long standing bugs and prepare for stabilizing the `experimental_index_url` (bazel-contrib#260). Refactor: * I have migrated all of the unit tests from Python to starlark for deps generation from METADATA `Requires-Dist` fields. * Read the `METADATA` file itself in Starlark. Work towards bazel-contrib#260, bazel-contrib#2319, bazel-contrib#2241 Fixes bazel-contrib#2423
ewianda
pushed a commit
to ewianda/rules_python
that referenced
this pull request
Apr 14, 2025
…ontrib#2629) This PR starts using the newly introduced (bazel-contrib#2692) PEP508 compliant requirement marker parser in starlark and moves the dependency generation from the Python language (`whl_installer`) to the Starlark in the `whl_library` repository rule. This PR is (almost) a pure refactor where no bugs are fixed, but this is foundational work that also adds notes on how things will be moved to macros (i.e. analysis phase) so that we can fix a few long standing bugs and prepare for stabilizing the `experimental_index_url` (bazel-contrib#260). Refactor: * I have migrated all of the unit tests from Python to starlark for deps generation from METADATA `Requires-Dist` fields. * Read the `METADATA` file itself in Starlark. Work towards bazel-contrib#260, bazel-contrib#2319, bazel-contrib#2241 Fixes bazel-contrib#2423
ewianda
pushed a commit
to ewianda/rules_python
that referenced
this pull request
Apr 14, 2025
…ontrib#2629) This PR starts using the newly introduced (bazel-contrib#2692) PEP508 compliant requirement marker parser in starlark and moves the dependency generation from the Python language (`whl_installer`) to the Starlark in the `whl_library` repository rule. This PR is (almost) a pure refactor where no bugs are fixed, but this is foundational work that also adds notes on how things will be moved to macros (i.e. analysis phase) so that we can fix a few long standing bugs and prepare for stabilizing the `experimental_index_url` (bazel-contrib#260). Refactor: * I have migrated all of the unit tests from Python to starlark for deps generation from METADATA `Requires-Dist` fields. * Read the `METADATA` file itself in Starlark. Work towards bazel-contrib#260, bazel-contrib#2319, bazel-contrib#2241 Fixes bazel-contrib#2423
ewianda
pushed a commit
to ewianda/rules_python
that referenced
this pull request
Apr 14, 2025
…ontrib#2629) This PR starts using the newly introduced (bazel-contrib#2692) PEP508 compliant requirement marker parser in starlark and moves the dependency generation from the Python language (`whl_installer`) to the Starlark in the `whl_library` repository rule. This PR is (almost) a pure refactor where no bugs are fixed, but this is foundational work that also adds notes on how things will be moved to macros (i.e. analysis phase) so that we can fix a few long standing bugs and prepare for stabilizing the `experimental_index_url` (bazel-contrib#260). Refactor: * I have migrated all of the unit tests from Python to starlark for deps generation from METADATA `Requires-Dist` fields. * Read the `METADATA` file itself in Starlark. Work towards bazel-contrib#260, bazel-contrib#2319, bazel-contrib#2241 Fixes bazel-contrib#2423
aignas
added a commit
to aignas/rules_python
that referenced
this pull request
Apr 28, 2025
Summary: - Revert to using Python for marker evaluation during parsing of requirements (partial revert of bazel-contrib#2692). - Use Python to parse whl METADATA. Fixes bazel-contrib#2830
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This implements the PEP508 compliant marker evaluation in starlark and
removes the need for the Python interpreter when evaluating requirements
files passed to
pip.parse
. This makes the evaluation faster and allowsus to fix a few known issues (#2690).
In the future the intent is to move the
METADATA
parsing to purestarlark so that the
RequiresDist
could be parsed in starlark at themacro evaluation or analysis phases. This should make it possible to
more easily solve the design problem that more and more things need to
be passed to
whl_library
as args to have a robust dependency parsing:compatible
METADATA
parsing and passing it toPython
and back makesit difficult/annoying to implement.
METADATA
file requires the precise list of targetplatform or the list of available packages in the
requirements.txt
.This means that without it we cannot trim the dependency tree in the
whl_library
. Doing this at macro loading phase allows us to dependon
.bzl
files in thehub_repository
and more effectively passinformation.
I can remotely see that this could become useful in
py_wheel
or an buildingwheels from sdists as the environment markers may be present in various source
metadata as well. What is more
uv.lock
file has the env markers as part ofthe lock file information, so this might be useful there.
Work towards #2423
Work towards #260
Split from #2629