6b54302b90720437300967b3506bffe00a3e243c

Author
Petr Bělohlávek <petrbel@users.noreply.github.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

python: add alias to run the proper IPython based on virtualenv

Current state: a user invokes `ipython` and is provided with the IPython
instance regarding the `$PATH`.

Proposed state: a user invokes `ipython` (which is a new alias in the
*python plugin*) and is provided with the proper IPython instance regarding
the currently activated virtualenv.

Example: the user's default Python is 2.7 with installed IPython 2.7. User
activates Python 3.5 virtualenv where he installs IPython 3.5. After
activating the environment, one expects `ipython` to run the version 3.5,
which does not happen by default. Instead, IPython 2.7 is used, which in
counter-intuitive and often causes problem.

Closes #5797

Diff

 1diff --git a/plugins/python/README.md b/plugins/python/README.md
 2index 2d955c5cbb49eadf356c3928d7831fd42e7507a2..e391bcfd4436ffca2f18c51226d83dd22b0d78b9 100644
 3--- a/plugins/python/README.md
 4+++ b/plugins/python/README.md
 5@@ -14,3 +14,4 @@ plugins=(... python)
 6 | `pyfind`         | Finds .py files recursively in the current directory                            |
 7 | `pyclean [dirs]` | Deletes byte-code and cache files from a list of directories or the current one |
 8 | `pygrep <text>`  | Looks for `text` in .py files                                                   |
 9+| `ipython`        | Runs the appropriate `ipython` version according to the activated virtualenv    |
10diff --git a/plugins/python/python.plugin.zsh b/plugins/python/python.plugin.zsh
11index f39cd80b7a86e5e257821582b4289e456682d7bc..62855fca219db2982a69ec5df488671c53b51954 100644
12--- a/plugins/python/python.plugin.zsh
13+++ b/plugins/python/python.plugin.zsh
14@@ -14,3 +14,5 @@ function pyclean() {
15 # Grep among .py files
16 alias pygrep='grep -r --include="*.py"'
17 
18+# Run proper IPython regarding current virtualenv (if any)
19+alias ipython="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"