Skip to content

Commit 8a83775

Browse files
author
Yamashita Yuu
committed
activate: invoke pyenv shell only if the arguments passed
1 parent ea120da commit 8a83775

File tree

5 files changed

+11
-26
lines changed

5 files changed

+11
-26
lines changed

README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,7 @@ version.
8686
Some external tools (e.g. [jedi](https://github.com/davidhalter/jedi)) might require you to `activate` the virtualenv.
8787
`pyenv activate` lets you to activate the virtualenv into your shell.
8888

89-
$ pyenv activate venv27
90-
91-
`pyenv activate` acts almost like following commands.
92-
The activate'd virtualenv will be persisted as _shell_ version.
93-
94-
$ pyenv shell venv27
95-
$ source "$(pyenv prefix venv27)/bin/activate"
89+
$ pyenv activate
9690

9791
### Deactivate virtualenv
9892

@@ -105,13 +99,6 @@ This is prepared for similality between other `pyenv` commands like `shell` and
10599

106100
$ pyenv activate --unset
107101

108-
`pyenv deactivate` acts almost like following commands.
109-
You can also use virtualenv's `deactivate` in place of `pyenv deactivate`,
110-
but be careful with the _shell_ version because it will be persisted even if `deactivate` has invoked.
111-
112-
$ deactivate
113-
$ pyenv shell --unset
114-
115102
### Special environment variables
116103

117104
You can set certain environment variables to control the pyenv-virtualenv.

bin/pyenv-sh-activate

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ if [ "$1" = "--unset" ]; then
2626
fi
2727

2828
versions=("$@")
29-
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
30-
3129
if [ -z "$versions" ]; then
30+
no_shell=1
3231
OLDIFS="$IFS"
3332
IFS=: versions=($(pyenv-version-name))
3433
IFS="$OLDIFS"
@@ -41,7 +40,11 @@ fi
4140

4241
pyenv-virtualenv-prefix "${versions}" 1>/dev/null
4342

44-
echo "pyenv shell \"${versions}\";"
43+
if [ -z "$no_shell" ]; then
44+
echo "pyenv shell \"${versions}\";"
45+
fi
46+
47+
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
4548
case "$shell" in
4649
fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;;
4750
* ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;;

bin/pyenv-sh-deactivate

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ set -e
1111

1212
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
1313
case "$shell" in
14-
fish ) echo "functions -q deactivate; and deactivate;";;
15-
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate;";;
14+
fish ) echo "functions -q deactivate; and deactivate";;
15+
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate";;
1616
esac
17-
echo "pyenv shell --unset"

test/activate.bats

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ setup() {
1919

2020
assert_success
2121
assert_output <<EOS
22-
pyenv shell "venv";
2322
source "${PYENV_ROOT}/versions/venv/bin/activate"
2423
EOS
2524
}
@@ -37,7 +36,6 @@ EOS
3736

3837
assert_success
3938
assert_output <<EOS
40-
pyenv shell "venv";
4139
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
4240
EOS
4341
}

test/deactivate.bats

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ setup() {
1111

1212
assert_success
1313
assert_output <<EOS
14-
declare -f deactivate 1>/dev/null 2>&1 && deactivate;
15-
pyenv shell --unset
14+
declare -f deactivate 1>/dev/null 2>&1 && deactivate
1615
EOS
1716
}
1817

@@ -21,8 +20,7 @@ EOS
2120

2221
assert_success
2322
assert_output <<EOS
24-
functions -q deactivate; and deactivate;
25-
pyenv shell --unset
23+
functions -q deactivate; and deactivate
2624
EOS
2725
}
2826

0 commit comments

Comments
 (0)