Skip to content

Add requires-python to uv init - #5322

Merged
charliermarsh merged 2 commits into
mainfrom
charlie/init-requires-python
Jul 23, 2024
Merged

charliermarsh merged 2 commits into
mainfrom
charlie/init-requires-python

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jul 23, 2024 •

Copy link
Copy Markdown
Member

Summary

Prefers, in order:

  • The major-minor version of an interpreter discovered via --python.
  • The requires-python from the workspace.
  • The major-minor version of the default interpreter.

If the --python request is a version or a version range, we use that without fetching an interpreter.

Closes #5299.

@charliermarsh
charliermarsh force-pushed the charlie/init-requires-python branch from b5f7ae0 to d861b5d Compare July 23, 2024 01:09
@charliermarsh charliermarsh added bug Something isn't working preview Experimental behavior labels Jul 23, 2024
Comment thread crates/uv/src/commands/project/init.rs Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@zanieb - Can you review that what I'm doing with the discovery here is reasonable?

@charliermarsh
charliermarsh force-pushed the charlie/init-requires-python branch from d861b5d to 6760f51 Compare July 23, 2024 01:10
@FishAlchemist

FishAlchemist commented Jul 23, 2024 •

Copy link
Copy Markdown
Contributor

image
Should we avoid creating pyproject.toml when providing python version causes an error?
This is because creating it would lead to Project is already initialized.
image
A failed creation will result in pyproject.toml being created, but missing requires-python
e.g.

[project]
name = "www"
version = "0.1.0"

@charliermarsh

Copy link
Copy Markdown
Member Author

Yeah... Though unfortunately we need to create the pyproject.toml to discover the workspace :(

I'll figure something out.

@j178

j178 commented Jul 23, 2024

Copy link
Copy Markdown
Contributor

Just a heads-up,cargo init checks workspace.members glob pattern before creating the project:

https://github.com/rust-lang/cargo/blob/7f2079838ac6e0a3cb05b1b9dac4401a76572855/src/cargo/ops/cargo_new.rs#L978-L996

@charliermarsh

Copy link
Copy Markdown
Member Author

@j178 - We also check that before modifying the workspace manifest.

@charliermarsh
charliermarsh force-pushed the charlie/init-requires-python branch from 6760f51 to 81205d4 Compare July 23, 2024 15:53
@charliermarsh
charliermarsh enabled auto-merge (squash) July 23, 2024 15:54
@charliermarsh
charliermarsh merged commit 0f8186d into main Jul 23, 2024
@charliermarsh
charliermarsh deleted the charlie/init-requires-python branch July 23, 2024 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working preview Experimental behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv init creates project with warning about Requires-Python

5 participants