mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-02 04:48:18 +00:00
Disallow pyproject.toml files for non-project configuration (#3463)
## Summary We already _don't_ discover a `pyproject.toml` in `~/.config/uv` -- it must be `uv.toml`. This PR makes the same change for `--config-file` -- it _has_ to be a `uv.toml`. I think this is reasonable and more consistent, though I'm not sure. A `pyproject.toml` "means" something -- it defines a project itself, in which case we should be using project configuration. But creating a `pyproject.toml` outside the project and passing it via `--config-file` seems like an anti-pattern.
This commit is contained in:
parent
1aa8ff8268
commit
a3c98e8e52
2 changed files with 6 additions and 12 deletions
|
|
@ -60,7 +60,7 @@ impl Workspace {
|
|||
Ok(None)
|
||||
}
|
||||
|
||||
/// Load a [`Workspace`] from a `pyproject.toml` or `uv.toml` file.
|
||||
/// Load a [`Workspace`] from a `uv.toml` file.
|
||||
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, WorkspaceError> {
|
||||
Ok(Self {
|
||||
options: read_file(path.as_ref())?,
|
||||
|
|
@ -139,18 +139,12 @@ fn find_in_directory(dir: &Path) -> Result<Option<Options>, WorkspaceError> {
|
|||
Ok(None)
|
||||
}
|
||||
|
||||
/// Load [`Options`] from a `pyproject.toml` or `uv.toml` file.
|
||||
/// Load [`Options`] from a `uv.toml` file.
|
||||
fn read_file(path: &Path) -> Result<Options, WorkspaceError> {
|
||||
let content = fs_err::read_to_string(path)?;
|
||||
if path.ends_with("pyproject.toml") {
|
||||
let pyproject: PyProjectToml = toml::from_str(&content)
|
||||
.map_err(|err| WorkspaceError::PyprojectToml(path.user_display().to_string(), err))?;
|
||||
Ok(pyproject.tool.and_then(|tool| tool.uv).unwrap_or_default())
|
||||
} else {
|
||||
let options: Options = toml::from_str(&content)
|
||||
.map_err(|err| WorkspaceError::UvToml(path.user_display().to_string(), err))?;
|
||||
Ok(options)
|
||||
}
|
||||
let options: Options = toml::from_str(&content)
|
||||
.map_err(|err| WorkspaceError::UvToml(path.user_display().to_string(), err))?;
|
||||
Ok(options)
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ pub(crate) struct Cli {
|
|||
#[command(flatten)]
|
||||
pub(crate) cache_args: CacheArgs,
|
||||
|
||||
/// The path to a `pyproject.toml` or `uv.toml` file to use for configuration.
|
||||
/// The path to a `uv.toml` file to use for configuration.
|
||||
#[arg(long, env = "UV_CONFIG_FILE", hide = true)]
|
||||
pub(crate) config_file: Option<PathBuf>,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue