Fix direnv configuration to use root-level venv

Simplified .envrc to use the existing root venv (bin/ directory) instead of creating nested .venv
Updated .tinyrc to point to root directory
Ensures direnv properly activates the virtual environment with all installed packages
This commit is contained in:
Vijay Janapa Reddi
2025-11-05 09:15:40 -05:00
parent ca12b70ef3
commit 6140cadad4
2 changed files with 13 additions and 18 deletions

29
.envrc
View File

@@ -1,28 +1,23 @@
# Python Virtual Environment Auto-Activation Template
# Copy this file as .envrc to any Python project directory
# Default usage:
# Then run: direnv allow
VENV_PATH=$(python -c "import json; print(json.load(open('.tinyrc')).get('venv_path', '.venv'))")
echo "Using virtual env in ${VENV_PATH}"
export VENV_PATH
# TinyTorch Virtual Environment Auto-Activation
# This uses the root-level venv (bin/ directory)
# Check if .venv exists, create if it doesn't
if [[ ! -d "$VENV_PATH" ]]; then
echo "🔧 Creating Python virtual environment..."
python3 -m venv "$VENV_PATH"
echo "📦 Installing basic dependencies..."
source "$VENV_PATH/bin/activate"
pip install --upgrade pip
# Uncomment the next line if you have a requirements.txt
# pip install -r requirements.txt
# The virtual environment is at the project root
VENV_PATH="${PWD}"
# Check if bin/activate exists
if [[ ! -f "${VENV_PATH}/bin/activate" ]]; then
echo "❌ Virtual environment not found at ${VENV_PATH}"
echo "Run: python3 -m venv ${VENV_PATH}"
exit 1
fi
# Activate the virtual environment
source "$VENV_PATH/bin/activate"
source "${VENV_PATH}/bin/activate"
# Set common Python environment variables
export PYTHONPATH="${PWD}:${PYTHONPATH}"
export PROJECT_ROOT="${PWD}"
export VENV_PATH
# Prevent Python from writing pyc files
export PYTHONDONTWRITEBYTECODE=1

View File

@@ -1,3 +1,3 @@
{
"venv_path": ".venv"
"venv_path": "."
}