Skip to content

Commit

Permalink
stdlib: use venv module for python if available
Browse files Browse the repository at this point in the history
This removes the dependency on virtualenv, because venv is included
in stdlib since python3.3.
  • Loading branch information
Mic92 authored and eddies committed Jul 23, 2019
1 parent 0bc462c commit 46ced97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,10 @@ const STDLIB = "#!/usr/bin/env bash\n" +
"\n" +
"# Usage: layout python <python_exe>\n" +
"#\n" +
"# Creates and loads a virtualenv environment under\n" +
"# Creates and loads a virtual environment under\n" +
"# \"$direnv_layout_dir/python-$python_version\".\n" +
"# This forces the installation of any egg into the project's sub-folder.\n" +
"# For python older then 3.3 this requires virtualenv to be installed.\n" +
"#\n" +
"# It's possible to specify the python executable if you want to use different\n" +
"# versions of python.\n" +
Expand All @@ -451,7 +452,11 @@ const STDLIB = "#!/usr/bin/env bash\n" +
" VIRTUAL_ENV=$(direnv_layout_dir)/python-$python_version\n" +
" export VIRTUAL_ENV\n" +
" if [[ ! -d $VIRTUAL_ENV ]]; then\n" +
" virtualenv \"--python=$python\" \"$@\" \"$VIRTUAL_ENV\"\n" +
" if $python -c \"import venv\"; then\n" +
" $python -m venv \"$@\" \"$VIRTUAL_ENV\"\n" +
" else\n" +
" virtualenv \"--python=$python\" \"$@\" \"$VIRTUAL_ENV\"\n" +
" fi\n" +
" fi\n" +
" fi\n" +
" PATH_add \"$VIRTUAL_ENV/bin\"\n" +
Expand Down
9 changes: 7 additions & 2 deletions stdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,10 @@ layout_php() {

# Usage: layout python <python_exe>
#
# Creates and loads a virtualenv environment under
# Creates and loads a virtual environment under
# "$direnv_layout_dir/python-$python_version".
# This forces the installation of any egg into the project's sub-folder.
# For python older then 3.3 this requires virtualenv to be installed.
#
# It's possible to specify the python executable if you want to use different
# versions of python.
Expand All @@ -449,7 +450,11 @@ layout_python() {
VIRTUAL_ENV=$(direnv_layout_dir)/python-$python_version
export VIRTUAL_ENV
if [[ ! -d $VIRTUAL_ENV ]]; then
virtualenv "--python=$python" "$@" "$VIRTUAL_ENV"
if $python -c "import venv"; then
$python -m venv "$@" "$VIRTUAL_ENV"
else
virtualenv "--python=$python" "$@" "$VIRTUAL_ENV"
fi
fi
fi
PATH_add "$VIRTUAL_ENV/bin"
Expand Down

0 comments on commit 46ced97

Please sign in to comment.