Skip to content

feat: add python-implementation condition to conditional features - #3038

Merged
messense merged 1 commit into
PyO3:mainfrom
messense:feature/conditional-feature-python-implementation
Feb 24, 2026
Merged

messense merged 1 commit into
PyO3:mainfrom
messense:feature/conditional-feature-python-implementation

Conversation

@messense

@messense messense commented Feb 24, 2026 •

Copy link
Copy Markdown
Member

Allow conditional cargo features to also filter on the Python implementation (cpython, pypy, graalpy) in addition to python-version.

Both fields are now optional — at least one must be present for a conditional entry, otherwise treated as a plain entry. Matching is case-insensitive.

Example:

  features = [
    { feature = "pyo3/abi3-py311", python-version = ">=3.11", python-implementation = "cpython" },
    { feature = "pypy-compat", python-implementation = "pypy" },
  ]

Closes #3037

@messense
messense force-pushed the feature/conditional-feature-python-implementation branch 2 times, most recently from b52c94a to 4944733 Compare February 24, 2026 11:45
Allow conditional cargo features to also filter on the Python
implementation (cpython, pypy, graalpy) in addition to python-version.

Both fields are now optional — at least one must be present for a
conditional entry. Matching is case-insensitive.

Example:
  features = [
    { feature = "pyo3/abi3-py311", python-version = ">=3.11", python-implementation = "cpython" },
    { feature = "pypy-compat", python-implementation = "pypy" },
  ]

Closes PyO3#3037
@messense
messense force-pushed the feature/conditional-feature-python-implementation branch from 4944733 to 56933d4 Compare February 24, 2026 11:54
@messense
messense requested a review from Copilot February 24, 2026 12:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds support for conditioning Cargo features on the Python implementation (cpython/pypy/graalpy) in addition to Python version, making conditional matching case-insensitive.

Changes:

  • Extend FeatureSpec::Conditional to accept optional python-version and optional python-implementation.
  • Update conditional feature resolution to filter by both version and implementation.
  • Update JSON schema and add tests for implementation-based matching/deserialization.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/pyproject_toml.rs Adds python-implementation support, introduces ConditionalFeature + FeatureConditionEnv, updates resolution logic, and expands tests.
src/compile.rs Builds a condition environment (version + implementation) and updates logging for resolved conditional features.
src/build_options.rs Refactors extraction of pyo3 features to ignore plain specs while handling conditional specs uniformly.
src/build_context.rs Replaces (String, VersionSpecifiers) with ConditionalFeature in build context.
maturin.schema.json Documents python-implementation and relaxes required fields for conditional feature entries.
Comments suppressed due to low confidence (1)

maturin.schema.json:1

  • The schema currently allows a conditional object with only feature and neither python-version nor python-implementation, but the PR description states at least one of those must be present. To align the schema with the documented contract, add a constraint (e.g., anyOf requiring python-version or requiring python-implementation) so invalid conditional entries are rejected by schema validation.
{

Comment thread src/pyproject_toml.rs Resolved
Comment thread src/pyproject_toml.rs Resolved
@messense
messense enabled auto-merge (squash) February 24, 2026 12:16
@messense
messense merged commit e64f903 into PyO3:main Feb 24, 2026
120 of 127 checks passed
@messense
messense deleted the feature/conditional-feature-python-implementation branch February 24, 2026 13:29
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Mar 31, 2026
https://build.opensuse.org/request/show/1343551
by user mia + anag_factory
- Drop CVE-2026-25727.patch (handled in _service)
- Update to 1.12.6
  * Sync legacy_py.rs with upstream PyPI warehouse legacy.py
    gh#PyO3/maturin#3053
  * Keep cargo build artifact at original path after staging
    gh#PyO3/maturin#3054
- Update to 1.12.5
  * feat: include debug info files (.pdb, .dSYM, .dwp) in wheels
    gh#PyO3/maturin#3024
  * Fix wrong abi3 tag for conditional cargo features enabled pyo3
    abi3 feature
    gh#PyO3/maturin#3029
  * fix: maturin build --sdist wheel name/layout for excluded
    workspace crates
    gh#PyO3/maturin#3031
  * fix: preserve wheel output dir when building from unpacked
    sdist
    gh#PyO3/maturin#3036
  * feat: add python-implementation condition to conditional
    features
    gh#PyO3/maturin#3038
  * Fix non-existent comment tag
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.

more dynamic feature condition ?

2 participants