Files
uv/crates/uv-dev/src/compile.rs
T
Zanie Blue bfb4bc2aeb Split preview mode into separate feature flags (#14823)
I think this would give us better hygiene than a global flag. It makes
it easier for users to opt-in to overlapping features, such as Python
upgrades and Python bin installations and to disable warnings for
preview mode without opting in to a bunch of other features. In general,
I want to reduce the burden for putting something under preview.

The `--preview` and `--no-preview` flags are retained as global
overrides. A new `--preview-features` option is added which accepts
comma separated features or can be passed multiple times, e.g.,
`--preview-features add-bounds,pylock`. There's a `UV_PREVIEW_FEATURES`
environment variable for that option (I'm not sure if we should overload
`UV_PREVIEW`, but could be convinced).
2025-07-25 11:01:57 -05:00

45 lines
1.1 KiB
Rust

use std::path::PathBuf;
use clap::Parser;
use tracing::info;
use uv_cache::{Cache, CacheArgs};
use uv_configuration::{Concurrency, Preview};
use uv_python::{EnvironmentPreference, PythonEnvironment, PythonRequest};
#[derive(Parser)]
pub(crate) struct CompileArgs {
/// Compile all `.py` in this or any subdirectory to bytecode
root: PathBuf,
python: Option<PathBuf>,
#[command(flatten)]
cache_args: CacheArgs,
}
pub(crate) async fn compile(args: CompileArgs) -> anyhow::Result<()> {
let cache = Cache::try_from(args.cache_args)?.init()?;
let interpreter = if let Some(python) = args.python {
python
} else {
let interpreter = PythonEnvironment::find(
&PythonRequest::default(),
EnvironmentPreference::OnlyVirtual,
&cache,
Preview::default(),
)?
.into_interpreter();
interpreter.sys_executable().to_path_buf()
};
let files = uv_installer::compile_tree(
&fs_err::canonicalize(args.root)?,
&interpreter,
&Concurrency::default(),
cache.root(),
)
.await?;
info!("Compiled {files} files");
Ok(())
}