-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect python version from python project by default in uv venv
#5592
Changes from 3 commits
1594e3b
c704aee
c27cc36
5edae5d
d7e9059
f12a994
f85fc6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ use anyhow::Result; | |
use assert_cmd::prelude::*; | ||
use assert_fs::prelude::*; | ||
use uv_python::{PYTHON_VERSIONS_FILENAME, PYTHON_VERSION_FILENAME}; | ||
use indoc::indoc; | ||
|
||
use crate::common::{uv_snapshot, TestContext}; | ||
|
||
|
@@ -171,6 +172,173 @@ fn create_venv_reads_request_from_python_versions_file() { | |
context.venv.assert(predicates::path::is_dir()); | ||
} | ||
|
||
#[test] | ||
fn create_venv_reads_request_from_pyproject_toml() -> Result<()> { | ||
let context = TestContext::new_with_versions(&["3.11", "3.10", "3.12"]); | ||
|
||
// Without the file, we should use the first on the PATH | ||
uv_snapshot!(context.filters(), context.venv() | ||
.arg("--preview"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Using Python 3.11.[X] interpreter at: [PYTHON-3.11] | ||
Creating virtualenv at: .venv | ||
Activate with: source .venv/bin/activate | ||
"### | ||
); | ||
|
||
// With `requires-python = "<3.11"`, we should prefer newest possible version 3.10 | ||
let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
pyproject_toml.write_str(indoc! { r###" | ||
[project] | ||
name = "foo" | ||
version = "1.0.0" | ||
requires-python = "<3.11" | ||
dependencies = [] | ||
"### | ||
})?; | ||
|
||
uv_snapshot!(context.filters(), context.venv() | ||
.arg("--preview"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Using Python 3.10.[X] interpreter at: [PYTHON-3.10] | ||
Creating virtualenv at: .venv | ||
Activate with: source .venv/bin/activate | ||
"### | ||
); | ||
|
||
// With `requires-python = "==3.11.*"`, we should prefer exact version 3.11 | ||
let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
pyproject_toml.write_str(indoc! { r###" | ||
[project] | ||
name = "foo" | ||
version = "1.0.0" | ||
requires-python = "==3.11.*" | ||
dependencies = [] | ||
"### | ||
})?; | ||
|
||
uv_snapshot!(context.filters(), context.venv() | ||
.arg("--preview"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Using Python 3.11.[X] interpreter at: [PYTHON-3.11] | ||
Creating virtualenv at: .venv | ||
Activate with: source .venv/bin/activate | ||
"### | ||
); | ||
|
||
// With `requires-python = ">=3.11,<3.12"`, we should prefer exact version 3.11 | ||
let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
pyproject_toml.write_str(indoc! { r###" | ||
[project] | ||
name = "foo" | ||
version = "1.0.0" | ||
requires-python = "==3.11.*" | ||
dependencies = [] | ||
"### | ||
})?; | ||
|
||
uv_snapshot!(context.filters(), context.venv() | ||
.arg("--preview"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Using Python 3.11.[X] interpreter at: [PYTHON-3.11] | ||
Creating virtualenv at: .venv | ||
Activate with: source .venv/bin/activate | ||
"### | ||
); | ||
|
||
// With `requires-python = ">=3.10"`, we should prefer first possible version 3.11 | ||
let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
pyproject_toml.write_str(indoc! { r###" | ||
[project] | ||
name = "foo" | ||
version = "1.0.0" | ||
requires-python = ">=3.10" | ||
dependencies = [] | ||
"### | ||
})?; | ||
|
||
uv_snapshot!(context.filters(), context.venv() | ||
.arg("--preview"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Using Python 3.11.[X] interpreter at: [PYTHON-3.11] | ||
Creating virtualenv at: .venv | ||
Activate with: source .venv/bin/activate | ||
"### | ||
); | ||
|
||
// With `requires-python = ">=3.11"`, we should prefer first possible version 3.11 | ||
let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
pyproject_toml.write_str(indoc! { r###" | ||
[project] | ||
name = "foo" | ||
version = "1.0.0" | ||
requires-python = ">=3.10" | ||
dependencies = [] | ||
"### | ||
})?; | ||
|
||
uv_snapshot!(context.filters(), context.venv() | ||
.arg("--preview"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Using Python 3.11.[X] interpreter at: [PYTHON-3.11] | ||
Creating virtualenv at: .venv | ||
Activate with: source .venv/bin/activate | ||
"### | ||
); | ||
|
||
// With `requires-python = ">=3.12"`, we should prefer first possible version 3.12 | ||
let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
pyproject_toml.write_str(indoc! { r###" | ||
[project] | ||
name = "foo" | ||
version = "1.0.0" | ||
requires-python = ">=3.10" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be 3.12? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, I got these tests code totally wrong! Since the commit is pushed near my bed time I did not check them carefully after pasting. Good news that tests still pass after correction. Apology for my carelessness. |
||
dependencies = [] | ||
"### | ||
})?; | ||
|
||
uv_snapshot!(context.filters(), context.venv() | ||
.arg("--preview"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Using Python 3.11.[X] interpreter at: [PYTHON-3.11] | ||
Creating virtualenv at: .venv | ||
Activate with: source .venv/bin/activate | ||
"### | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found that the default behavior for
|
||
|
||
context.venv.assert(predicates::path::is_dir()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn create_venv_explicit_request_takes_priority_over_python_version_file() { | ||
let context = TestContext::new_with_versions(&["3.11", "3.12"]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be 3.11?