From 74d86530a0355ccee35ab75153a5458703933327 Mon Sep 17 00:00:00 2001 From: Julian Popescu Date: Fri, 22 Mar 2024 16:45:15 +0100 Subject: [PATCH] fix: use default .venv path for virtual environment --- src/dirs.rs | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/dirs.rs b/src/dirs.rs index 491795f..d6a57c2 100644 --- a/src/dirs.rs +++ b/src/dirs.rs @@ -8,11 +8,10 @@ use aqora_runner::python::PyEnv; use clap::ColorChoice; use indicatif::ProgressBar; use std::path::{Path, PathBuf}; -use thiserror::Error; const AQORA_DIRNAME: &str = ".aqora"; const DATA_DIRNAME: &str = "data"; -const VENV_DIRNAME: &str = "venv"; +const VENV_DIRNAME: &str = ".venv"; const LAST_RUN_DIRNAME: &str = "last_run"; const PYPROJECT_FILENAME: &str = "pyproject.toml"; const USE_CASE_FILENAME: &str = "use_case.toml"; @@ -43,7 +42,7 @@ pub fn project_config_dir(project_dir: impl AsRef) -> PathBuf { } pub fn project_venv_dir(project_dir: impl AsRef) -> PathBuf { - project_config_dir(project_dir).join(VENV_DIRNAME) + project_dir.as_ref().join(VENV_DIRNAME) } pub fn project_last_run_dir(project_dir: impl AsRef) -> PathBuf { @@ -90,34 +89,6 @@ pub async fn read_pyproject(project_dir: impl AsRef) -> Result }) } -#[derive(Debug, Error)] -enum SymlinkError { - #[error("Failed to create symlink from {0} to {1}: {2}")] - CreateSymlink(PathBuf, PathBuf, std::io::Error), - #[error("{0} directory already exists. Symlink to {1} could not be created.")] - VenvDirExists(PathBuf, PathBuf), -} - -fn create_venv_symlink(project_dir: impl AsRef) -> Result<(), SymlinkError> { - let symlink_dir = project_dir.as_ref().join(".venv"); - let venv_dir = [AQORA_DIRNAME, VENV_DIRNAME].iter().collect::(); - - if symlink_dir.exists() { - if symlink_dir.read_link().ok().as_ref() != Some(&venv_dir) { - return Err(SymlinkError::VenvDirExists(symlink_dir, venv_dir)); - } - return Ok(()); - } - - #[cfg(unix)] - use std::os::unix::fs::symlink; - #[cfg(windows)] - use std::os::windows::fs::symlink_dir as symlink; - - symlink(&venv_dir, &symlink_dir) - .map_err(|err| SymlinkError::CreateSymlink(symlink_dir, venv_dir, err)) -} - async fn ensure_uv(uv_path: Option>, pb: &ProgressBar) -> Result { if let Some(uv_path) = uv_path .map(|p| PathBuf::from(p.as_ref())) @@ -185,8 +156,5 @@ pub async fn init_venv( ), ) })?; - if let Err(err) = create_venv_symlink(&project_dir) { - eprintln!("WARN: {err}"); - } Ok(env) }