mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Add preview mode and use for warning in uv run
(#3192)
Adds hidden `--preview` / `--no-preview` flags with `UV_PREVIEW` environment variable support. Copies the `PreviewMode` type from Ruff. Does a little bit of extra work to port `uv run` to the new settings model. Note we allow `uv run` invocations without preview and only use its presence to toggle an experimental warning. ## Test plan ``` ❯ cargo run -q -- run --no-workspace -- python --version warning: `uv run` is experimental and may change without warning. Python 3.12.2 ❯ cargo run -q -- run --no-workspace --preview -- python --version Python 3.12.2 ❯ UV_PREVIEW=1 cargo run -q -- run --no-workspace -- python --version Python 3.12.2 ```
This commit is contained in:
parent
11c6a07bb5
commit
b9419e67aa
8 changed files with 109 additions and 3 deletions
|
@ -5,6 +5,7 @@ pub use constraints::*;
|
|||
pub use name_specifiers::*;
|
||||
pub use overrides::*;
|
||||
pub use package_options::*;
|
||||
pub use preview::*;
|
||||
pub use target_triple::*;
|
||||
|
||||
mod authentication;
|
||||
|
@ -14,4 +15,5 @@ mod constraints;
|
|||
mod name_specifiers;
|
||||
mod overrides;
|
||||
mod package_options;
|
||||
mod preview;
|
||||
mod target_triple;
|
||||
|
|
37
crates/uv-configuration/src/preview.rs
Normal file
37
crates/uv-configuration/src/preview.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum PreviewMode {
|
||||
#[default]
|
||||
Disabled,
|
||||
Enabled,
|
||||
}
|
||||
|
||||
impl PreviewMode {
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
matches!(self, Self::Enabled)
|
||||
}
|
||||
|
||||
pub fn is_disabled(&self) -> bool {
|
||||
matches!(self, Self::Disabled)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bool> for PreviewMode {
|
||||
fn from(version: bool) -> Self {
|
||||
if version {
|
||||
PreviewMode::Enabled
|
||||
} else {
|
||||
PreviewMode::Disabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for PreviewMode {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Disabled => write!(f, "disabled"),
|
||||
Self::Enabled => write!(f, "enabled"),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue