-
-
Notifications
You must be signed in to change notification settings - Fork 636
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
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
68511b4
refactor(pypi): implement PEP508 compliant marker evaluation
aignas 435b9d2
fix tests
aignas f7edb9e
fix more tests
aignas 2f34976
Merge branch 'main' into feat/extension-eval-without-python
aignas d4b19b4
Fix ppc handling
aignas 9f63485
Merge branch 'main' into feat/extension-eval-without-python
aignas 0585c0d
wip
aignas a17aa55
normalize the platform_machine during evaluation
aignas aa4e055
wip
aignas f2ec55e
refactor
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
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,23 @@ | ||
| # Copyright 2025 The Bazel Authors. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """This module is for implementing PEP508 in starlark as FeatureFlagInfo | ||
| """ | ||
|
|
||
| load(":pep508_env.bzl", _env = "env") | ||
| load(":pep508_evaluate.bzl", _evaluate = "evaluate", _to_string = "to_string") | ||
|
|
||
| to_string = _to_string | ||
| evaluate = _evaluate | ||
| env = _env |
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,109 @@ | ||
| # Copyright 2025 The Bazel Authors. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """This module is for implementing PEP508 environment definition. | ||
| """ | ||
|
|
||
| _platform_machine_values = { | ||
| "aarch64": "arm64", | ||
| "ppc": "ppc64le", | ||
| "s390x": "s390x", | ||
| "x86_32": "i386", | ||
| "x86_64": "x86_64", | ||
| } | ||
| _platform_system_values = { | ||
| "linux": "Linux", | ||
| "osx": "Darwin", | ||
| "windows": "Windows", | ||
| } | ||
| _sys_platform_values = { | ||
| "linux": "posix", | ||
| "osx": "darwin", | ||
| "windows": "win32", | ||
| } | ||
| _os_name_values = { | ||
| "linux": "posix", | ||
| "osx": "posix", | ||
| "windows": "nt", | ||
| } | ||
|
|
||
| def env(target_platform, *, extra = None): | ||
| """Return an env target platform | ||
|
|
||
| Args: | ||
| target_platform: {type}`str` the target platform identifier, e.g. | ||
| `cp33_linux_aarch64` | ||
| extra: {type}`str` the extra value to be added into the env. | ||
|
|
||
| Returns: | ||
| A dict that can be used as `env` in the marker evaluation. | ||
| """ | ||
|
|
||
| # TODO @aignas 2025-02-13: consider moving this into config settings. | ||
|
|
||
| env = {"extra": extra} if extra != None else {} | ||
| env = env | { | ||
| "implementation_name": "cpython", | ||
| "platform_python_implementation": "CPython", | ||
| "platform_release": "", | ||
| "platform_version": "", | ||
| } | ||
| if target_platform.abi: | ||
| minor_version, _, micro_version = target_platform.abi[3:].partition(".") | ||
| micro_version = micro_version or "0" | ||
| env = env | { | ||
| "implementation_version": "3.{}.{}".format(minor_version, micro_version), | ||
| "python_full_version": "3.{}.{}".format(minor_version, micro_version), | ||
| "python_version": "3.{}".format(minor_version), | ||
| } | ||
| if target_platform.os and target_platform.arch: | ||
| os = target_platform.os | ||
| arch = target_platform.arch | ||
| env = env | { | ||
| "os_name": _os_name_values.get(os, ""), | ||
| "platform_machine": "aarch64" if (os, arch) == ("linux", "aarch64") else _platform_machine_values.get(arch, ""), | ||
| "platform_system": _platform_system_values.get(os, ""), | ||
| "sys_platform": _sys_platform_values.get(os, ""), | ||
| } | ||
|
|
||
| # This is split by topic | ||
| return env | ||
|
|
||
| def _platform(*, abi = None, os = None, arch = None): | ||
| return struct( | ||
| abi = abi, | ||
| os = os, | ||
| arch = arch, | ||
| ) | ||
|
|
||
| def platform_from_str(p, python_version): | ||
| """Return a platform from a string. | ||
|
|
||
| Args: | ||
| p: {type}`str` the actual string. | ||
| python_version: {type}`str` the python version to add to platform if needed. | ||
|
|
||
| Returns: | ||
| A struct that is returned by the `_platform` function. | ||
| """ | ||
| if p.startswith("cp"): | ||
| abi, _, p = p.partition("_") | ||
| elif python_version: | ||
| major, _, tail = python_version.partition(".") | ||
| abi = "cp{}{}".format(major, tail) | ||
| else: | ||
| abi = None | ||
|
|
||
| os, _, arch = p.partition("_") | ||
| return _platform(abi = abi, os = os or None, arch = arch or None) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.