forked from pypa/hatch
-
Notifications
You must be signed in to change notification settings - Fork 1
[WIP] Add variant support #1
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
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 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,143 @@ | ||
| # This file is copied from variantlib/variantlib/constants.py | ||
| # Do not edit this file directly, instead edit variantlib/variantlib/constants.py | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| from typing import Literal, TypedDict | ||
|
|
||
| VARIANT_HASH_LEN = 8 | ||
| CONFIG_FILENAME = "variants.toml" | ||
| VARIANT_DIST_INFO_FILENAME = "variant.json" | ||
|
|
||
| # Common variant info keys (used in pyproject.toml and variants.json) | ||
| VARIANT_INFO_DEFAULT_PRIO_KEY: Literal["default-priorities"] = "default-priorities" | ||
| VARIANT_INFO_FEATURE_KEY: Literal["feature"] = "feature" | ||
| VARIANT_INFO_NAMESPACE_KEY: Literal["namespace"] = "namespace" | ||
| VARIANT_INFO_PROPERTY_KEY: Literal["property"] = "property" | ||
| VARIANT_INFO_PROVIDER_DATA_KEY: Literal["providers"] = "providers" | ||
| VARIANT_INFO_PROVIDER_ENABLE_IF_KEY: Literal["enable-if"] = "enable-if" | ||
| VARIANT_INFO_PROVIDER_OPTIONAL_KEY: Literal["optional"] = "optional" | ||
| VARIANT_INFO_PROVIDER_PLUGIN_API_KEY: Literal["plugin-api"] = "plugin-api" | ||
| VARIANT_INFO_PROVIDER_REQUIRES_KEY: Literal["requires"] = "requires" | ||
|
|
||
| PYPROJECT_TOML_TOP_KEY = "variant" | ||
|
|
||
| VARIANTS_JSON_SCHEMA_KEY: Literal["$schema"] = "$schema" | ||
| VARIANTS_JSON_SCHEMA_URL = "https://variants-schema.wheelnext.dev/" | ||
| VARIANTS_JSON_VARIANT_DATA_KEY: Literal["variants"] = "variants" | ||
|
|
||
| VALIDATION_VARIANT_HASH_REGEX = re.compile(rf"[0-9a-f]{{{VARIANT_HASH_LEN}}}") | ||
|
|
||
| VALIDATION_NAMESPACE_REGEX = re.compile(r"[a-z0-9_]+") | ||
| VALIDATION_FEATURE_NAME_REGEX = re.compile(r"[a-z0-9_]+") | ||
|
|
||
| # For `Property value` there is two regexes: | ||
| # 1. `VALIDATION_VALUE_VSPEC_REGEX` - if `packaging.specifiers.SpecifierSet` is used | ||
| # Note: for clarity - only "full version" are allowed | ||
| # i.e. so no "a|b|alpha|beta|rc|post|etc." versions | ||
| VALIDATION_VALUE_VSPEC_REGEX = re.compile(r"[0-9_.,!>~<=]+") | ||
| # 2. `VALIDATION_VALUE_STR_REGEX` - if string matching is used | ||
| VALIDATION_VALUE_STR_REGEX = re.compile(r"[a-z0-9_.]+") | ||
| VALIDATION_VALUE_REGEX = re.compile( | ||
| rf"{VALIDATION_VALUE_VSPEC_REGEX.pattern}|{VALIDATION_VALUE_STR_REGEX.pattern}" | ||
| ) | ||
|
|
||
| VALIDATION_FEATURE_REGEX = re.compile( | ||
| rf""" | ||
| (?P<namespace>{VALIDATION_NAMESPACE_REGEX.pattern}) | ||
| \s* :: \s* | ||
| (?P<feature>{VALIDATION_FEATURE_NAME_REGEX.pattern}) | ||
| """, | ||
| re.VERBOSE, | ||
| ) | ||
|
|
||
| VALIDATION_PROPERTY_REGEX = re.compile( | ||
| rf""" | ||
| (?P<namespace>{VALIDATION_NAMESPACE_REGEX.pattern}) | ||
| \s* :: \s* | ||
| (?P<feature>{VALIDATION_FEATURE_NAME_REGEX.pattern}) | ||
| \s* :: \s* | ||
| (?P<value>{VALIDATION_VALUE_REGEX.pattern}) | ||
| """, | ||
| re.VERBOSE, | ||
| ) | ||
|
|
||
| VALIDATION_PROVIDER_ENABLE_IF_REGEX = re.compile(r"[\S ]+") | ||
| VALIDATION_PROVIDER_PLUGIN_API_REGEX = re.compile( | ||
| r""" | ||
| (?P<module> [\w.]+) | ||
| (?: \s* : \s* | ||
| (?P<attr> [\w.]+) | ||
| )? | ||
| """, | ||
| re.VERBOSE, | ||
| ) | ||
| VALIDATION_PROVIDER_REQUIRES_REGEX = re.compile(r"[\S ]+") | ||
|
|
||
|
|
||
| # VALIDATION_PYTHON_PACKAGE_NAME_REGEX = re.compile(r"[^\s-]+?") | ||
| # Per PEP 508: https://peps.python.org/pep-0508/#names | ||
| VALIDATION_PYTHON_PACKAGE_NAME_REGEX = re.compile( | ||
| r"[A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9]", re.IGNORECASE | ||
| ) | ||
| VALIDATION_WHEEL_NAME_REGEX = re.compile( | ||
| r"(?P<base_wheel_name> " # <base_wheel_name> group (without variant) | ||
| r" (?P<namever> " # "namever" group contains <name>-<ver> | ||
| r" (?P<name>[^\s-]+?) " # <name> | ||
| r" - (?P<ver>[^\s-]*?) " # "-" <ver> | ||
| r" ) " # close "namever" group | ||
| r" ( - (?P<build>\d[^-]*?) )? " # optional "-" <build> | ||
| r" - (?P<pyver>[^\s-]+?) " # "-" <pyver> tag | ||
| r" - (?P<abi>[^\s-]+?) " # "-" <abi> tag | ||
| r" - (?P<plat>[^\s-]+?) " # "-" <plat> tag | ||
| r") " # end of <base_wheel_name> group | ||
| r"( - (?P<variant_hash> " # optional <variant_hash> | ||
| rf" [0-9a-f]{{{VARIANT_HASH_LEN}}} " | ||
| r" ) " | ||
| r")? " | ||
| r"\.whl " # ".whl" suffix | ||
| r" ", | ||
| re.VERBOSE, | ||
| ) | ||
|
|
||
|
|
||
| # ======================== Json TypedDict for the JSON format ======================== # | ||
|
|
||
| # NOTE: Unfortunately, it is not possible as of today to use variables in the definition | ||
| # of TypedDict. Similarly also impossible to use the normal "class format" if a | ||
| # key uses the characted `-`. | ||
| # | ||
| # For all these reasons and easier future maintenance - these classes have been | ||
| # added to this file instead of a more "format definition" file. | ||
|
|
||
|
|
||
| class PriorityJsonDict(TypedDict, total=False): | ||
| namespace: list[str] | ||
| feature: dict[str, list[str]] | ||
| property: dict[str, dict[str, list[str]]] | ||
|
|
||
|
|
||
| ProviderPluginJsonDict = TypedDict( | ||
| "ProviderPluginJsonDict", | ||
| { | ||
| "plugin-api": str, | ||
| "requires": list[str], | ||
| "enable-if": str, | ||
| }, | ||
| total=False, | ||
| ) | ||
|
|
||
| VariantInfoJsonDict = dict[str, dict[str, list[str]]] | ||
|
|
||
|
|
||
| VariantsJsonDict = TypedDict( | ||
| "VariantsJsonDict", | ||
| { | ||
| "$schema": str, | ||
| "default-priorities": PriorityJsonDict, | ||
| "providers": dict[str, ProviderPluginJsonDict], | ||
| "variants": dict[str, VariantInfoJsonDict], | ||
| }, | ||
| total=False, | ||
| ) |
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.
Uh oh!
There was an error while loading. Please reload this page.