Skip to content

[Python] Venv tweaks based on testing in Sandboxes #2264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/pip.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.0.2",
"description": "This plugin adds a script for automatically creating a virtual environment using `venv` for python3 projects, so you can install packages with pip as normal.\nTo activate the environment, run `. $VENV_DIR/bin/activate` or add it to the init_hook of your devbox.json\nTo change where your virtual environment is created, modify the $VENV_DIR environment variable in your init_hook",
"env": {
"VENV_DIR": "{{ .Virtenv }}/.venv"
"VENV_DIR": "{{ .Virtenv }}/.venv",
"UV_PYTHON": "{{ .DevboxProjectRoot }}/.devbox/nix/profile/default/bin/python"
},
"create_files": {
"{{ .Virtenv }}/bin/venvShellHook.sh": "pip/venvShellHook.sh"
Expand Down
11 changes: 5 additions & 6 deletions plugins/pip/venvShellHook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ create_venv() {
echo "*\n.*" >> "$VENV_DIR/.gitignore"
}

# Check if we've already run this script
if [ -f "$STATE_FILE" ]; then
# "We've already run this script. Exiting..."
exit 0
fi

# Check that Python version supports venv
if ! python -c 'import venv' 1> /dev/null 2> /dev/null; then
echo "\033[1;33mWARNING: Python version must be > 3.3 to create a virtual environment.\033[0m"
Expand All @@ -31,6 +25,11 @@ fi
# Check if the directory exists
if [ -d "$VENV_DIR" ]; then
if is_valid_venv "$VENV_DIR"; then
# Check if we've already run this script
if [ -f "$STATE_FILE" ]; then
# "We've already run this script. Exiting..."
exit 0
fi
if ! is_devbox_venv "$VENV_DIR"; then
echo "\033[1;33mWARNING: Virtual environment at $VENV_DIR doesn't use Devbox Python.\033[0m"
read -p "Do you want to overwrite it? (y/n) " -n 1 -r
Expand Down
Loading