From 4df3a570421f3ba1d8bddde433f903760eccba9f Mon Sep 17 00:00:00 2001 From: Semyon Maryasin Date: Mon, 7 Aug 2017 04:25:26 +0300 Subject: [PATCH 1/5] Use pyvenv for py3 --- scripts/envie | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/envie b/scripts/envie index 8ee08aa..67c41cf 100755 --- a/scripts/envie +++ b/scripts/envie @@ -371,16 +371,23 @@ function mkenv() { pip_valid_reqs+=("${pip_auto_reqs[@]}") fi - local output virtualenv_opts=(--no-site-packages -p "$pypath") + local output virtualenv_cmd=(virtualenv) virtualenv_opts=(--no-site-packages -p "$pypath") (( quietness > 0 )) && virtualenv_opts+=(-q) (( verbosity > 1 )) && virtualenv_opts+=(-v) + if [[ "$pyver" == "Python 3"* ]]; then + # use py3's built-in venv which is faster than virtualenv + virtualenv_cmd=("${pypath}" -m venv) + # and it doesn't support (or need) our regular opts, so clear them + virtualenv_opts=() + fi + ( if (( verbosity > 0 )); then - virtualenv "${virtualenv_opts[@]}" "$@" "$envpath" + "${virtualenv_cmd[@]}" "${virtualenv_opts[@]}" "$@" "$envpath" else - output=$(virtualenv "${virtualenv_opts[@]}" "$@" "$envpath" 2>&1) + output=$("${virtualenv_cmd[@]}" "${virtualenv_opts[@]}" "$@" "$envpath" 2>&1) if (( $? )); then (( quietness < 2 )) && _errmsg "$output" exit 1 From 7bf1829b25693aa7025762660e09f316a1235a71 Mon Sep 17 00:00:00 2001 From: Semyon Maryasin Date: Mon, 7 Aug 2017 04:29:28 +0300 Subject: [PATCH 2/5] Control pyvenv usage with config variable --- scripts/envie | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/envie b/scripts/envie index 67c41cf..a515dee 100755 --- a/scripts/envie +++ b/scripts/envie @@ -22,11 +22,12 @@ _ENVIE_USE_DB="0" _ENVIE_DB_PATH="$_ENVIE_CONFIG_DIR/locate.db" _ENVIE_CACHE_PATH="$_ENVIE_CONFIG_DIR/virtualenvs.list" _ENVIE_INDEX_ROOT="$HOME" -_ENVIE_CRON_INDEX="0" # having periodical updatedb? -_ENVIE_CRON_PERIOD_MIN="15" # update period in minutes -_ENVIE_LS_INDEX="0" # updatedb on each lsenv? -_ENVIE_FIND_LIMIT_SEC="0.4" # abort find search if takes longer this (in seconds) -_ENVIE_LOCATE_LIMIT_SEC="4" # warn if index older than this (in seconds) +_ENVIE_CRON_INDEX="0" # having periodical updatedb? +_ENVIE_CRON_PERIOD_MIN="15" # update period in minutes +_ENVIE_LS_INDEX="0" # updatedb on each lsenv? +_ENVIE_FIND_LIMIT_SEC="0.4" # abort find search if takes longer this (in seconds) +_ENVIE_LOCATE_LIMIT_SEC="4" # warn if index older than this (in seconds) +_ENVIE_USE_PYVENV_FOR_PY3="0" # for py3, use pyvenv rather than slower virtualenv _ENVIE_UUID="28d0b2c7bc5245d5b1278015abc3f0cd" _ENVIE_VERSION="0.4.36-dev" @@ -43,6 +44,7 @@ function _envie_dump_config() { _ENVIE_LS_INDEX="$_ENVIE_LS_INDEX" _ENVIE_FIND_LIMIT_SEC="$_ENVIE_FIND_LIMIT_SEC" _ENVIE_LOCATE_LIMIT_SEC="$_ENVIE_LOCATE_LIMIT_SEC" + _ENVIE_USE_PYVENV_FOR_PY3="$_ENVIE_USE_PYVENV_FOR_PY3" _ENVIE_UUID="$_ENVIE_UUID" END } @@ -376,7 +378,7 @@ function mkenv() { (( quietness > 0 )) && virtualenv_opts+=(-q) (( verbosity > 1 )) && virtualenv_opts+=(-v) - if [[ "$pyver" == "Python 3"* ]]; then + if (( _ENVIE_USE_PYVENV_FOR_PY3 )) && [[ "$pyver" == "Python 3"* ]]; then # use py3's built-in venv which is faster than virtualenv virtualenv_cmd=("${pypath}" -m venv) # and it doesn't support (or need) our regular opts, so clear them From 83d2e4d1ae86454181d54cef2166c96babfa0507 Mon Sep 17 00:00:00 2001 From: Semyon Maryasin Date: Mon, 7 Aug 2017 04:31:30 +0300 Subject: [PATCH 3/5] Do propmpt for pyvenv option on config --- scripts/envie | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/envie b/scripts/envie index a515dee..7597129 100755 --- a/scripts/envie +++ b/scripts/envie @@ -1045,6 +1045,12 @@ function __envie_config() { _ENVIE_LS_INDEX=0 fi + read -p "Use pyvenv rather than virtualenv for python3 (faster) [y/N]? " ans + case "$ans" in + Y|y) _ENVIE_USE_PYVENV_FOR_PY3=1;; + *) _ENVIE_USE_PYVENV_FOR_PY3=0;; + esac + # add/remove source statement to/from .bashrc (( add_to_bashrc )) && __envie_register || __envie_unregister From a2215ea60b0e086c50a6c40c2290b0debf31d0ac Mon Sep 17 00:00:00 2001 From: Semyon Maryasin Date: Mon, 7 Aug 2017 04:39:38 +0300 Subject: [PATCH 4/5] Use just python as virtualenv_cmd, and pass -m venv as options --- scripts/envie | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/envie b/scripts/envie index 7597129..b9a1dcd 100755 --- a/scripts/envie +++ b/scripts/envie @@ -373,23 +373,23 @@ function mkenv() { pip_valid_reqs+=("${pip_auto_reqs[@]}") fi - local output virtualenv_cmd=(virtualenv) virtualenv_opts=(--no-site-packages -p "$pypath") + local output virtualenv_cmd=virtualenv virtualenv_opts=(--no-site-packages -p "$pypath") (( quietness > 0 )) && virtualenv_opts+=(-q) (( verbosity > 1 )) && virtualenv_opts+=(-v) if (( _ENVIE_USE_PYVENV_FOR_PY3 )) && [[ "$pyver" == "Python 3"* ]]; then # use py3's built-in venv which is faster than virtualenv - virtualenv_cmd=("${pypath}" -m venv) - # and it doesn't support (or need) our regular opts, so clear them - virtualenv_opts=() + virtualenv_cmd="${pypath}" + # and it doesn't support (or need) our regular opts, so clear them. + virtualenv_opts=(-m venv) fi ( if (( verbosity > 0 )); then - "${virtualenv_cmd[@]}" "${virtualenv_opts[@]}" "$@" "$envpath" + "$virtualenv_cmd" "${virtualenv_opts[@]}" "$@" "$envpath" else - output=$("${virtualenv_cmd[@]}" "${virtualenv_opts[@]}" "$@" "$envpath" 2>&1) + output=$("$virtualenv_cmd" "${virtualenv_opts[@]}" "$@" "$envpath" 2>&1) if (( $? )); then (( quietness < 2 )) && _errmsg "$output" exit 1 From feb04790a8ffd6d540dc7e8b32223bea775bb174 Mon Sep 17 00:00:00 2001 From: Semyon Maryasin Date: Mon, 7 Aug 2017 04:39:57 +0300 Subject: [PATCH 5/5] couple comments --- scripts/envie | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/envie b/scripts/envie index b9a1dcd..efb6b51 100755 --- a/scripts/envie +++ b/scripts/envie @@ -382,6 +382,8 @@ function mkenv() { # use py3's built-in venv which is faster than virtualenv virtualenv_cmd="${pypath}" # and it doesn't support (or need) our regular opts, so clear them. + # no need to specify python because the one we launch will be used + # also it does not produce much output and hence doesn't support or need -q/-v opts. virtualenv_opts=(-m venv) fi