Skip to content

Conversation

hcho3
Copy link

@hcho3 hcho3 commented Aug 14, 2025

WheelNext & Wheel Variants

Caution

This is an an experimental feature currently being formalized as a PEP.
This is not an official feature of the Python Ecosystem & Standards.

This PR is part of the work being conducted by the WheelNext open-source initiative.

This PR introduces the feature of "Wheel Variant" into hatch & hatchling as a proof-of-concept.

Hopefully, this will give a good idea on:

  • How it works
  • How to use it
  • How it could be implemented

How do "Wheel Variants" work ?

Wheel Variant is a proposed extension to the wheel specification designed to make platform-specific package distribution easier for package maintainers, and installation more smooth for end users. The key concepts are:

  • A Provider Plugin system, allowing vendors and communities to ship small, install-time packages that can detect system capabilities (e.g., CUDA version, CPU features).

  • A declarative metadata format for wheels to express their specific requirements (e.g., nvidia :: cuda_version_lower_bound :: 12.8). Yes, absolutely inspired by Python classifier format.

  • A mechanism for installers to automatically run these plugins to match the user's system with the best-fitting variant wheel, simplifying the user experience to a familiar [uv] pip install torch.

We have carefully designed this system to ensure that installers unaware of variants will safely ignore them, maintaining backward compatibility with the existing ecosystem.

Links and Resources:

PR Details

  • Add CLI option --variant-property to allow users to build variant wheels with a given variant specifier. Example:
hatch build -t wheel \
    --variant-property "fictional_tech :: quantum :: foam" \
    --variant-property "fictional_tech :: risk_exposure :: 1000000000" \
    --variant-property "fictional_tech :: technology :: improb_drive"

# Using build
python -m build --no-isolation --wheel \
    --config-setting 'variant-property=fictional_tech :: quantum :: foam' \
    --config-setting 'variant-property=fictional_tech :: risk_exposure :: 1000000000' \
    --config-setting 'variant-property=fictional_tech :: technology :: improb_drive'
  • Hatchling now inserts variant.json into the wheel, whenever the wheel is variant-enabled.

TODOs

cc @DEKHTIARJonathan, @warsaw

@hcho3 hcho3 changed the title [WIP] Wheel Variant Experimental Support Wheel Variant Experimental Support Sep 15, 2025
@hcho3 hcho3 marked this pull request as ready for review September 15, 2025 23:06
hcho3 added a commit to hcho3/pep_xxx_wheel_variants that referenced this pull request Sep 15, 2025
hcho3 added a commit to hcho3/pep_xxx_wheel_variants that referenced this pull request Sep 15, 2025
Comment on lines 14 to 37
# 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_PLUGIN_USE_KEY: Literal["plugin-use"] = "plugin-use"
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/v0.0.2.json"
VARIANTS_JSON_VARIANT_DATA_KEY: Literal["variants"] = "variants"

VALIDATION_VARIANT_LABEL_REGEX = re.compile(rf"[0-9a-z._]{{1,{VARIANT_LABEL_LENGTH}}}")

VALIDATION_NAMESPACE_REGEX = re.compile(r"[a-z0-9_]+")
VALIDATION_FEATURE_NAME_REGEX = re.compile(r"[a-z0-9_]+")
VALIDATION_VALUE_REGEX = re.compile(r"[a-z0-9_.]+")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use variantlib itself to obtain these?

konstin pushed a commit to hcho3/pep_xxx_wheel_variants that referenced this pull request Oct 7, 2025
konstin added a commit to wheelnext/pep_xxx_wheel_variants that referenced this pull request Oct 7, 2025
* Sync to pypa/hatch#2037

* .

---------

Co-authored-by: konstin <konstin@mailbox.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants