From 21239c934207207a7405b1d09ab555e13ba66865 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Sat, 18 Jul 2015 20:39:56 +0900 Subject: [PATCH] If the current virtualenv is created with `--system-site-packages` and an executable is not found in it, automatically look up the executable for source Python version. (fixes #62) --- etc/pyenv.d/which/system-site-packages.bash | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 etc/pyenv.d/which/system-site-packages.bash diff --git a/etc/pyenv.d/which/system-site-packages.bash b/etc/pyenv.d/which/system-site-packages.bash new file mode 100644 index 0000000..956de12 --- /dev/null +++ b/etc/pyenv.d/which/system-site-packages.bash @@ -0,0 +1,20 @@ +# if virtualenv is created with `--system-site-packages`, +# looks up executables for source version as well if none is +# installed in the virtualenv. +# https://github.com/yyuu/pyenv-virtualenv/issues/62 + +if [ ! -x "${PYENV_COMMAND_PATH}" ]; then + virtualenv_prefix="$(pyenv-virtualenv-prefix 2>/dev/null || true)" + if [ -d "${virtualenv_prefix}" ]; then + shopt -s nullglob + no_global_site_packages="$(echo "$(pyenv-prefix)/lib/"*"/no-global-site-packages.txt")" + shopt -u nullglob + if [ ! -f "${no_global_site_packages}" ]; then + # virtualenv is created with `--system-site-packages` + virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}" + if [ -x "${virtualenv_command_path}" ]; then + PYENV_COMMAND_PATH="${virtualenv_command_path}" + fi + fi + fi +fi