Files
uv/crates/uv-dev/src/compile.rs
T
Zanie Blue e783a79955 Add PythonEnvironment::find API (#4423)
Restores the `PythonEnvironment::find` API which was removed a while
back in favor of `Toolchain::find`. As mentioned in #4416, I'm
attempting to separate the case where you want an active environment
from the case where you want an installed toolchain in order to create
environments.

I wanted to drop `EnvironmentPreference` from `Toolchain::find` and just
have us consistently consider (or not consider) virtual environments
when discovering toolchains for creating environments. Unfortunately
this caused a few things to break so I reverted that change and will
explore it separately. Because I was exploring that change, there are
some minor changes to the `Toolchain` API here.
2024-06-20 17:54:17 +00:00

41 lines
1.0 KiB
Rust

use std::path::PathBuf;
use clap::Parser;
use tracing::info;
use uv_cache::{Cache, CacheArgs};
use uv_toolchain::{EnvironmentPreference, PythonEnvironment, ToolchainRequest};
#[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(
&ToolchainRequest::default(),
EnvironmentPreference::OnlyVirtual,
&cache,
)?
.into_interpreter();
interpreter.sys_executable().to_path_buf()
};
let files = uv_installer::compile_tree(
&fs_err::canonicalize(args.root)?,
&interpreter,
cache.root(),
)
.await?;
info!("Compiled {files} files");
Ok(())
}