Avoid requires-python warning in virtual-only workspace (#5895)

## Summary

There's no way for the user to address this, so we shouldn't show it.
This commit is contained in:
Charlie Marsh 2024-08-07 20:43:19 -04:00 committed by GitHub
parent 4b2b2d2870
commit 9081509715
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 4 deletions

View file

@ -239,6 +239,7 @@ impl Workspace {
}
}
/// Returns `true` if the workspace has a virtual root.
pub fn is_virtual(&self) -> bool {
!self
.packages
@ -246,6 +247,11 @@ impl Workspace {
.any(|member| *member.root() == self.install_path)
}
/// Returns `true` if the workspace consists solely of a virtual root.
pub fn only_virtual(&self) -> bool {
self.packages.is_empty()
}
/// Returns the set of requirements that include all packages in the workspace.
pub fn members_requirements(&self) -> impl Iterator<Item = Requirement> + '_ {
self.packages.values().filter_map(|member| {

View file

@ -265,7 +265,13 @@ async fn do_lock(
} else {
let default =
RequiresPython::greater_than_equal_version(&interpreter.python_minor_version());
warn_user!("No `requires-python` value found in the workspace. Defaulting to `{default}`.");
if workspace.only_virtual() {
debug!("No `requires-python` in virtual-only workspace. Defaulting to `{default}`.");
} else {
warn_user!(
"No `requires-python` value found in the workspace. Defaulting to `{default}`."
);
}
default
};

View file

@ -2771,7 +2771,6 @@ fn add_virtual() -> Result<()> {
----- stderr -----
warning: `uv add` is experimental and may change without warning
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]

View file

@ -183,7 +183,6 @@ fn empty() -> Result<()> {
----- stderr -----
warning: `uv sync` is experimental and may change without warning
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
Resolved 0 packages in [TIME]
Audited 0 packages in [TIME]
"###);
@ -198,7 +197,6 @@ fn empty() -> Result<()> {
----- stderr -----
warning: `uv sync` is experimental and may change without warning
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
Resolved 0 packages in [TIME]
Audited 0 packages in [TIME]
"###);