From f7e3c82ef0bb70df23f0f088f6465bdebb46249a Mon Sep 17 00:00:00 2001 From: Sean Monahan <1907654+seancmonahan@users.noreply.github.com> Date: Wed, 19 Jan 2022 20:44:23 -0500 Subject: [PATCH 1/5] Use AUTOSWITCH_HIDE_MKVENV_SUGGESTION to prevent this plugin from saying it detected an uninitialized virtual environment project --- autoswitch_virtualenv.plugin.zsh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh index bbd2308..7bdb858 100644 --- a/autoswitch_virtualenv.plugin.zsh +++ b/autoswitch_virtualenv.plugin.zsh @@ -1,3 +1,5 @@ +# TODO: document AUTOSWITCH_HIDE_MKVENV_SUGGESTION variable + export AUTOSWITCH_VERSION="3.4.0" export AUTOSWITCH_FILE=".venv" @@ -31,6 +33,10 @@ function _virtual_env_dir() { function _python_version() { local PYTHON_BIN="$1" + + # TODO: is the lack of a semicolon after the ]] OK style-wise? + # I know it's valid in ZSH because the [[ ]] is grammar, but it's not + # portable. E.g. it breaks bash it seems. if [[ -f "$PYTHON_BIN" ]] then # For some reason python --version writes to stderr printf "%s" "$($PYTHON_BIN --version 2>&1)" @@ -209,8 +215,10 @@ function check_venv() # If we still haven't got anywhere, fallback to defaults if [[ "$venv_type" != "unknown" ]]; then - printf "Python ${PURPLE}$venv_type${NORMAL} project detected. " - printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n" + if (( !AUTOSWITCH_HIDE_MKVENV_SUGGESTION )); then + printf "Python ${PURPLE}$venv_type${NORMAL} project detected. " + printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n" + fi fi _default_venv } From 8a775ae0baff3dd23dac7a4431958947fdfb5c64 Mon Sep 17 00:00:00 2001 From: Sean Monahan <1907654+seancmonahan@users.noreply.github.com> Date: Wed, 19 Jan 2022 21:05:47 -0500 Subject: [PATCH 2/5] Documentation for AUTOSWITCH_HIDE_MKVENV_SUGGESTION --- README.rst | 16 ++++++++++++++++ autoswitch_virtualenv.plugin.zsh | 5 ----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 3182727..dfe1fc5 100644 --- a/README.rst +++ b/README.rst @@ -315,6 +315,22 @@ By default `mkvenv` will install setup.py via pip in editable (i.e. development) and `here `__ for further information. To change this set ``AUTOSWITCH_PIPINSTALL`` to ``FULL``. +**Disabling the suggestion to run mkvenv** + +By default, this plugin prints a suggestion to run `mkvenv` when it detects a +supported project without an initialized virtual environment: + +:: + + Python virtualenv project detected. Run mkvenv to setup autoswitching + +This can be silenced by setting the environment variable +``AUTOSWITCH_HIDE_MKVENV_SUGGESTION``: + +:: + + export AUTOSWITCH_HIDE_MKVENV_SUGGESTION=1 + Security Warnings ----------------- diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh index 7bdb858..6233df1 100644 --- a/autoswitch_virtualenv.plugin.zsh +++ b/autoswitch_virtualenv.plugin.zsh @@ -1,5 +1,3 @@ -# TODO: document AUTOSWITCH_HIDE_MKVENV_SUGGESTION variable - export AUTOSWITCH_VERSION="3.4.0" export AUTOSWITCH_FILE=".venv" @@ -34,9 +32,6 @@ function _virtual_env_dir() { function _python_version() { local PYTHON_BIN="$1" - # TODO: is the lack of a semicolon after the ]] OK style-wise? - # I know it's valid in ZSH because the [[ ]] is grammar, but it's not - # portable. E.g. it breaks bash it seems. if [[ -f "$PYTHON_BIN" ]] then # For some reason python --version writes to stderr printf "%s" "$($PYTHON_BIN --version 2>&1)" From 340e070b0eca1ba961a2a994d65b707c7ece2155 Mon Sep 17 00:00:00 2001 From: Sean Monahan <1907654+seancmonahan@users.noreply.github.com> Date: Wed, 19 Jan 2022 21:19:51 -0500 Subject: [PATCH 3/5] virtualenv -> $venv_type --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index dfe1fc5..c01cb9e 100644 --- a/README.rst +++ b/README.rst @@ -322,7 +322,7 @@ supported project without an initialized virtual environment: :: - Python virtualenv project detected. Run mkvenv to setup autoswitching + Python $venv_type project detected. Run mkvenv to setup autoswitching This can be silenced by setting the environment variable ``AUTOSWITCH_HIDE_MKVENV_SUGGESTION``: From 081f9ce2c62c76482dd88b4c909129ceedd7c28e Mon Sep 17 00:00:00 2001 From: Sean Monahan <1907654+seancmonahan@users.noreply.github.com> Date: Wed, 19 Jan 2022 21:22:59 -0500 Subject: [PATCH 4/5] added `;` between `]]` and `then` to be consistent with rest of file --- autoswitch_virtualenv.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh index 6233df1..5c00e99 100644 --- a/autoswitch_virtualenv.plugin.zsh +++ b/autoswitch_virtualenv.plugin.zsh @@ -32,7 +32,7 @@ function _virtual_env_dir() { function _python_version() { local PYTHON_BIN="$1" - if [[ -f "$PYTHON_BIN" ]] then + if [[ -f "$PYTHON_BIN" ]]; then # For some reason python --version writes to stderr printf "%s" "$($PYTHON_BIN --version 2>&1)" else From 752b91f9ef0e3a10c316dc3e6acacc3c83a64396 Mon Sep 17 00:00:00 2001 From: Sean Monahan <1907654+seancmonahan@users.noreply.github.com> Date: Wed, 19 Jan 2022 21:31:44 -0500 Subject: [PATCH 5/5] removed blank line added inadvertently --- autoswitch_virtualenv.plugin.zsh | 1 - 1 file changed, 1 deletion(-) diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh index 5c00e99..f9a4d5e 100644 --- a/autoswitch_virtualenv.plugin.zsh +++ b/autoswitch_virtualenv.plugin.zsh @@ -31,7 +31,6 @@ function _virtual_env_dir() { function _python_version() { local PYTHON_BIN="$1" - if [[ -f "$PYTHON_BIN" ]]; then # For some reason python --version writes to stderr printf "%s" "$($PYTHON_BIN --version 2>&1)"