mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2025-12-05 19:17:52 -06:00
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:
29
.envrc
29
.envrc
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user