Add a --project argument to run a command from a project (#7603)

## Summary

`uv run --project ./path/to/project` now uses the provided directory as
the starting point for any file discovery. However, relative paths are
still resolved relative to the current working directory.

Closes https://github.com/astral-sh/uv/issues/5613.
This commit is contained in:
Charlie Marsh 2024-09-21 16:19:49 -04:00 committed by GitHub
parent d9a5f5ca1c
commit 35d6274c31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 591 additions and 88 deletions

View file

@ -235,6 +235,19 @@ pub struct GlobalArgs {
/// Change to the given directory prior to running the command.
#[arg(global = true, long, hide = true)]
pub directory: Option<PathBuf>,
/// Run the command within the given project directory.
///
/// All `pyproject.toml`, `uv.toml`, and `.python-version` files will be discovered by walking
/// up the directory tree from the project root, as will the project's virtual environment
/// (`.venv`).
///
/// Other command-line arguments (such as relative paths) will be resolved relative
/// to the current working directory.
///
/// This setting has no effect when used in the `uv pip` interface.
#[arg(global = true, long)]
pub project: Option<PathBuf>,
}
#[derive(Debug, Copy, Clone, clap::ValueEnum)]