Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions crates/uv/src/commands/project/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,15 @@ async fn init_project(
// This can be arbitrary, i.e., not a version — in which case we may need to resolve the
// interpreter
match python_request {
PythonRequest::Version(VersionRequest::MajorMinor(
major,
minor,
PythonVariant::Default,
)) => {
PythonRequest::Version(VersionRequest::MajorMinor(major, minor, variant)) => {
let requires_python = RequiresPython::greater_than_equal_version(&Version::new([
u64::from(major),
u64::from(minor),
]));

let python_request = if pin_python {
Some(PythonRequest::Version(VersionRequest::MajorMinor(
major,
minor,
PythonVariant::Default,
major, minor, variant,
)))
} else {
None
Expand All @@ -396,7 +390,7 @@ async fn init_project(
major,
minor,
patch,
PythonVariant::Default,
variant,
)) => {
let requires_python = RequiresPython::greater_than_equal_version(&Version::new([
u64::from(major),
Expand All @@ -406,19 +400,18 @@ async fn init_project(

let python_request = if pin_python {
Some(PythonRequest::Version(VersionRequest::MajorMinorPatch(
major,
minor,
patch,
PythonVariant::Default,
major, minor, patch, variant,
)))
} else {
None
};

(requires_python, python_request)
}
ref
python_request @ PythonRequest::Version(VersionRequest::Range(ref specifiers, _)) => {
ref python_request @ PythonRequest::Version(VersionRequest::Range(
ref specifiers,
variant,
)) => {
let requires_python = RequiresPython::from_specifiers(specifiers);

let python_request = if pin_python {
Expand All @@ -439,7 +432,7 @@ async fn init_project(
Some(PythonRequest::Version(VersionRequest::MajorMinor(
interpreter.python_major(),
interpreter.python_minor(),
PythonVariant::Default,
variant,
)))
} else {
None
Expand Down
19 changes: 19 additions & 0 deletions crates/uv/tests/it/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3713,3 +3713,22 @@ fn init_without_description() -> Result<()> {

Ok(())
}

/// Run `uv init --python 3.13t` to create a pin to a freethreaded Python.
#[test]
fn init_python_variant() -> Result<()> {
let context = TestContext::new("3.13");
uv_snapshot!(context.filters(), context.init().arg("foo").arg("--python").arg("3.13t"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Initialized project `foo` at `[TEMP_DIR]/foo`
"###);

let python_version = fs_err::read_to_string(context.temp_dir.join("foo/.python-version"))?;
assert_eq!(python_version, "3.13t\n");

Ok(())
}
Loading