Skip to content

Commit

Permalink
Ignore errors in workspace discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 23, 2024
1 parent b149cbe commit d09097d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
9 changes: 3 additions & 6 deletions crates/uv/src/commands/project/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::{Context, Result};
use owo_colors::OwoColorize;
use pep440_rs::Version;
use pep508_rs::PackageName;
use tracing::debug;
use tracing::{debug, warn};
use uv_cache::Cache;
use uv_client::{BaseClientBuilder, Connectivity};
use uv_fs::{absolutize_path, Simplified, CWD};
Expand All @@ -14,7 +14,6 @@ use uv_python::{
VersionRequest,
};
use uv_resolver::RequiresPython;
use uv_warnings::warn_user_once;
use uv_workspace::pyproject_mut::{DependencyTarget, PyProjectTomlMut};
use uv_workspace::{check_nested_workspaces, DiscoveryOptions, Workspace, WorkspaceError};

Expand Down Expand Up @@ -184,16 +183,14 @@ async fn init_project(
Err(WorkspaceError::MissingPyprojectToml | WorkspaceError::NonWorkspace(_)) => {
// If the user runs with `--no-workspace` and we can't find a workspace, warn.
if no_workspace {
warn_user_once!("`--no-workspace` was provided, but no workspace was found");
warn!("`--no-workspace` was provided, but no workspace was found");
}
None
}
Err(err) => {
// If the user runs with `--no-workspace`, ignore the error.
if no_workspace {
warn_user_once!(
"Ignoring workspace discovery error due to `--no-workspace`: {err}"
);
warn!("Ignoring workspace discovery error due to `--no-workspace`: {err}");
None
} else {
return Err(err.into());
Expand Down
69 changes: 39 additions & 30 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use anyhow::{anyhow, bail, Context};
use itertools::Itertools;
use owo_colors::OwoColorize;
use tokio::process::Command;
use tracing::debug;
use tracing::{debug, warn};

use uv_cache::Cache;
use uv_cli::ExternalCommand;
Expand Down Expand Up @@ -264,19 +264,34 @@ pub(crate) async fn run(
))
} else {
match VirtualProject::discover(&CWD, &DiscoveryOptions::default()).await {
Ok(project) => Some(project),
Err(WorkspaceError::MissingPyprojectToml) => None,
Err(WorkspaceError::NonWorkspace(_)) => None,
Err(err) => return Err(err.into()),
Ok(project) => {
if no_project {
debug!("Ignoring discovered project due to `--no-project`");
None
} else {
Some(project)
}
}
Err(WorkspaceError::MissingPyprojectToml | WorkspaceError::NonWorkspace(_)) => {
// If the user runs with `--no-project` and we can't find a project, warn.
if no_project {
warn!("`--no-project` was provided, but no project was found");
}
None
}
Err(err) => {
// If the user runs with `--no-project`, ignore the error.
if no_project {
warn!("Ignoring project discovery error due to `--no-project`: {err}");
None
} else {
return Err(err.into());
}
}
}
};

let project = if no_project {
// If the user runs with `--no-project` and we can't find a project, warn.
if project.is_none() {
debug!("`--no-project` was provided, but no project was found; ignoring...");
}

if no_project {
// If the user ran with `--no-project` and provided a project-only setting, warn.
if !extras.is_empty() {
warn_user_once!("Extras have no effect when used alongside `--no-project`");
Expand All @@ -290,27 +305,21 @@ pub(crate) async fn run(
if frozen {
warn_user_once!("`--frozen` has no effect when used alongside `--no-project`");
}

None
} else {
} else if project.is_none() {
// If we can't find a project and the user provided a project-only setting, warn.
if project.is_none() {
if !extras.is_empty() {
warn_user_once!("Extras have no effect when used outside of a project");
}
if !dev {
warn_user_once!("`--no-dev` has no effect when used outside of a project");
}
if locked {
warn_user_once!("`--locked` has no effect when used outside of a project");
}
if frozen {
warn_user_once!("`--frozen` has no effect when used outside of a project");
}
if !extras.is_empty() {
warn_user_once!("Extras have no effect when used outside of a project");
}

project
};
if !dev {
warn_user_once!("`--no-dev` has no effect when used outside of a project");
}
if locked {
warn_user_once!("`--locked` has no effect when used outside of a project");
}
if frozen {
warn_user_once!("`--frozen` has no effect when used outside of a project");
}
}

let interpreter = if let Some(project) = project {
if let Some(project_name) = project.project_name() {
Expand Down

0 comments on commit d09097d

Please sign in to comment.