Skip to content

Build should error if pyproject.toml does not contain (dynamic) version #2390

@stinodego

Description

@stinodego

Bug Description

Currently, maturin will fill in the version specifier if it is missing from pyproject.toml (it is available in Cargo.toml). However, this is prohibited in the official spec:
https://packaging.python.org/en/latest/specifications/pyproject-toml/#dynamic

If the metadata does not list a key in dynamic, then a build back-end CANNOT fill in the requisite metadata on behalf of the user

So rather than filling in the version, maturin should error and tell the user to add dynamic = ["version"] to their pyproject.toml.

This came up because uv is now enforcing this, and won't install any packages with a missing version specifier in the metadata: astral-sh/uv#9989

Your maturin version (maturin --version)

maturin 1.7.4

Your Python version (python -V)

Python 3.12.2

Your pip version (pip -V)

pip 24.3.1

What bindings you're using

pyo3

Does cargo build work?

  • Yes, it works

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

  • Yes

Steps to Reproduce

You can just go to the official docs:
https://www.maturin.rs/metadata

If you remove the version specifier in the pyproject.toml metadata, it will take the version from the Cargo.toml. This works, but it shouldn't!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions