Skip to content

Commit

Permalink
fix: use default .venv path for virtual environment
Browse files Browse the repository at this point in the history
  • Loading branch information
jpopesculian committed Mar 22, 2024
1 parent 2f072d2 commit 74d8653
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -43,7 +42,7 @@ pub fn project_config_dir(project_dir: impl AsRef<Path>) -> PathBuf {
}

pub fn project_venv_dir(project_dir: impl AsRef<Path>) -> 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<Path>) -> PathBuf {
Expand Down Expand Up @@ -90,34 +89,6 @@ pub async fn read_pyproject(project_dir: impl AsRef<Path>) -> Result<PyProject>
})
}

#[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<Path>) -> Result<(), SymlinkError> {
let symlink_dir = project_dir.as_ref().join(".venv");
let venv_dir = [AQORA_DIRNAME, VENV_DIRNAME].iter().collect::<PathBuf>();

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<impl AsRef<Path>>, pb: &ProgressBar) -> Result<PathBuf> {
if let Some(uv_path) = uv_path
.map(|p| PathBuf::from(p.as_ref()))
Expand Down Expand Up @@ -185,8 +156,5 @@ pub async fn init_venv(
),
)
})?;
if let Err(err) = create_venv_symlink(&project_dir) {
eprintln!("WARN: {err}");
}
Ok(env)
}

0 comments on commit 74d8653

Please sign in to comment.