f9b638a296
Instead of always using all available threads for bytecode compilation, respect `UV_CONCURRENT_INSTALLS`, so the parallelism is configurable instead of hardcoded. We reuse the install limit since bytecode compilation only runs after install.
44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use clap::Parser;
|
|
use tracing::info;
|
|
|
|
use uv_cache::{Cache, CacheArgs};
|
|
use uv_configuration::Concurrency;
|
|
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,
|
|
)?
|
|
.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(())
|
|
}
|