From b76f4367ce5732bdca5d4f63417be563252f74cd Mon Sep 17 00:00:00 2001 From: Naz Quadri Date: Mon, 22 Jul 2024 09:23:10 -0400 Subject: [PATCH] Clean rebase from main --- rye/src/cli/build.rs | 25 +++++++++++++++++++++++-- rye/src/pyproject.rs | 7 ------- rye/src/uv.rs | 1 + rye/tests/test_add.rs | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/rye/src/cli/build.rs b/rye/src/cli/build.rs index 88c6813164..170531c124 100644 --- a/rye/src/cli/build.rs +++ b/rye/src/cli/build.rs @@ -2,13 +2,14 @@ use std::fs; use std::path::PathBuf; use std::process::{Command, Stdio}; -use anyhow::{anyhow, bail, Error}; +use anyhow::{anyhow, bail, Context, Error}; use clap::Parser; use console::style; -use crate::bootstrap::ensure_self_venv; +use crate::bootstrap::{ensure_self_venv, fetch, FetchOptions}; use crate::config::Config; +use crate::platform::get_toolchain_python_bin; use crate::pyproject::{locate_projects, PyProject}; use crate::utils::{get_venv_python_bin, prepend_path_to_path_env, CommandOutput, IoPathContext}; use crate::uv::UvBuilder; @@ -52,6 +53,7 @@ pub fn execute(cmd: Args) -> Result<(), Error> { let output = CommandOutput::from_quiet_and_verbose(cmd.quiet, cmd.verbose); let self_venv = ensure_self_venv(output)?; let project = PyProject::load_or_discover(cmd.pyproject.as_deref(), cmd.venv.as_ref())?; + let py_ver = project.venv_python_version()?; let out = match cmd.out { Some(path) => path, @@ -81,6 +83,25 @@ pub fn execute(cmd: Args) -> Result<(), Error> { warn!("skipping build, all projects are virtual"); return Ok(()); } + + // Make sure we have a compatible Python version. + let py_ver = fetch(&py_ver.into(), FetchOptions::with_output(output)) + .context("failed fetching toolchain ahead of sync")?; + echo!(if output, "Python version: {}", style(&py_ver).cyan()); + let py_bin = get_toolchain_python_bin(&py_ver)?; + + // Create a virtual environment in which to perform the builds. + let uv = UvBuilder::new() + .with_output(CommandOutput::Quiet) + .ensure_exists()? + .with_output(output); + let venv_dir = tempfile::tempdir().context("failed to create temporary directory")?; + let uv_venv = uv + .venv(venv_dir.path(), &py_bin, &py_ver, None) + .context("failed to create build environment")?; + uv_venv.write_marker()?; + uv_venv.bootstrap()?; + for project in projects { // skip over virtual packages on build if project.is_virtual() { diff --git a/rye/src/pyproject.rs b/rye/src/pyproject.rs index ac56324798..2067523404 100644 --- a/rye/src/pyproject.rs +++ b/rye/src/pyproject.rs @@ -603,13 +603,6 @@ fn implicit() -> Item { Item::Table(table) } -/// Returns an implicit table. -fn implicit() -> Item { - let mut table = Table::new(); - table.set_implicit(true); - Item::Table(table) -} - impl PyProject { /// Load a pyproject toml if explicitly given, else discover from current directory /// diff --git a/rye/src/uv.rs b/rye/src/uv.rs index 15d5eb225d..6cd5fa3291 100644 --- a/rye/src/uv.rs +++ b/rye/src/uv.rs @@ -484,6 +484,7 @@ impl UvWithVenv { } /// Install the bootstrap requirements in the venv. + #[allow(dead_code)] pub fn bootstrap(&self) -> Result<(), Error> { self.update(LATEST_PIP, SELF_REQUIREMENTS)?; Ok(()) diff --git a/rye/tests/test_add.rs b/rye/tests/test_add.rs index d0466ab669..d9fc8a3de3 100644 --- a/rye/tests/test_add.rs +++ b/rye/tests/test_add.rs @@ -511,4 +511,4 @@ fn test_add_dev_w_venv() { ] "### ); -} \ No newline at end of file +}