From 396e19c2fdc3e36d62caefc5a91b8d58d4d1454d Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Sat, 10 Aug 2013 00:42:00 -0600 Subject: [PATCH 1/8] Don't format the code to go in .pythonrc.py in a doctest This is way too confusing. You don't put doctests in files, you put code in files. --- jedi/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jedi/utils.py b/jedi/utils.py index 1736dfff..8ab4c2f0 100644 --- a/jedi/utils.py +++ b/jedi/utils.py @@ -14,13 +14,13 @@ def setup_readline(): This function setups :mod:`readline` to use Jedi in Python interactive shell. If you want to use a custom ``PYTHONSTARTUP`` file (typically - ``$HOME/.pythonrc.py``), you can add this piece of code: + ``$HOME/.pythonrc.py``), you can add this piece of code:: - >>> try: - ... from jedi.utils import setup_readline - ... setup_readline() - ... except ImportError: - ... print('Install Jedi with pip! No autocompletion otherwise.') + try: + from jedi.utils import setup_readline + setup_readline() + except ImportError: + print('Install Jedi with pip! No autocompletion otherwise.') """ try: From c60fd21805290c57cbc902fc3fa7e25103cb47e9 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Sat, 10 Aug 2013 00:42:34 -0600 Subject: [PATCH 2/8] Don't make it sound like Jedi has to be installed with pip --- jedi/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jedi/utils.py b/jedi/utils.py index 8ab4c2f0..77b193cc 100644 --- a/jedi/utils.py +++ b/jedi/utils.py @@ -20,7 +20,7 @@ def setup_readline(): from jedi.utils import setup_readline setup_readline() except ImportError: - print('Install Jedi with pip! No autocompletion otherwise.') + print('Install Jedi! No autocompletion otherwise.') """ try: From 6f9da26593f440152a877b36f3db6cba3e92d599 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Sat, 10 Aug 2013 00:43:37 -0600 Subject: [PATCH 3/8] Show how to fallback to regular readline completion --- jedi/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jedi/utils.py b/jedi/utils.py index 77b193cc..780e756a 100644 --- a/jedi/utils.py +++ b/jedi/utils.py @@ -22,6 +22,16 @@ def setup_readline(): except ImportError: print('Install Jedi! No autocompletion otherwise.') + Alternately, you can fall back to regular readline completion with + something like:: + + try: + from jedi.utils import setup_readline + setup_readline() + except ImportError: + import readline, rlcompleter + readline.parse_and_bind("tab: complete") + """ try: import readline From 7c53988baefb268dcf4a18fda17c54394028ae14 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Sat, 10 Aug 2013 00:44:30 -0600 Subject: [PATCH 4/8] Note that you have to add PYTHONSTARTUP to your profile --- jedi/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jedi/utils.py b/jedi/utils.py index 780e756a..0e0a9d26 100644 --- a/jedi/utils.py +++ b/jedi/utils.py @@ -32,6 +32,9 @@ def setup_readline(): import readline, rlcompleter readline.parse_and_bind("tab: complete") + You'll also need to add ``export PYTHONSTARTUP=$HOME/.pythonrc.py`` to + your bash profile (usually ``.bash_profile`` or ``.profile``). + """ try: import readline From 8b3a62a76f4609b47caff4e2b09b7cb7e11b5f23 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Sat, 10 Aug 2013 00:50:26 -0600 Subject: [PATCH 5/8] Indent code blocks in the docstring --- jedi/utils.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/jedi/utils.py b/jedi/utils.py index 0e0a9d26..cc5d2a41 100644 --- a/jedi/utils.py +++ b/jedi/utils.py @@ -16,21 +16,21 @@ def setup_readline(): shell. If you want to use a custom ``PYTHONSTARTUP`` file (typically ``$HOME/.pythonrc.py``), you can add this piece of code:: - try: - from jedi.utils import setup_readline - setup_readline() - except ImportError: - print('Install Jedi! No autocompletion otherwise.') + try: + from jedi.utils import setup_readline + setup_readline() + except ImportError: + print('Install Jedi! No autocompletion otherwise.') Alternately, you can fall back to regular readline completion with something like:: - try: - from jedi.utils import setup_readline - setup_readline() - except ImportError: - import readline, rlcompleter - readline.parse_and_bind("tab: complete") + try: + from jedi.utils import setup_readline + setup_readline() + except ImportError: + import readline, rlcompleter + readline.parse_and_bind("tab: complete") You'll also need to add ``export PYTHONSTARTUP=$HOME/.pythonrc.py`` to your bash profile (usually ``.bash_profile`` or ``.profile``). From 1ac6d779a1d1ecbe643b99b801e94436489e4cfd Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Sat, 10 Aug 2013 10:28:09 -0600 Subject: [PATCH 6/8] Cleanup to the Jedi .pythonrc.py example --- jedi/utils.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/jedi/utils.py b/jedi/utils.py index cc5d2a41..492e2c90 100644 --- a/jedi/utils.py +++ b/jedi/utils.py @@ -20,20 +20,32 @@ def setup_readline(): from jedi.utils import setup_readline setup_readline() except ImportError: - print('Install Jedi! No autocompletion otherwise.') + # Fallback to the stdlib readline completer if it is installed. + # Taken from http://docs.python.org/2/library/rlcompleter.html + try: + import readline + import rlcompleter + readline.parse_and_bind("tab: complete") + except ImportError: + pass - Alternately, you can fall back to regular readline completion with - something like:: + This will fallback to the readline completer if Jedi is not installed. + The readline completer will only complete names in the global namespace, + so for example, - try: - from jedi.utils import setup_readline - setup_readline() - except ImportError: - import readline, rlcompleter - readline.parse_and_bind("tab: complete") + >>> ran + + will complete to ``range`` + + with both Jedi and readline, but + + >>> range(10).cou + + will show complete to ``range(10).count`` only with Jedi. You'll also need to add ``export PYTHONSTARTUP=$HOME/.pythonrc.py`` to - your bash profile (usually ``.bash_profile`` or ``.profile``). + your shell profile (usually ``.bash_profile`` or ``.profile`` if you use + bash). """ try: From 754835bec5b84673e0c286e3e3617c7264286991 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Sat, 10 Aug 2013 10:34:30 -0600 Subject: [PATCH 7/8] Add some print statements to the .pythonrc.py example --- jedi/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jedi/utils.py b/jedi/utils.py index 492e2c90..704ab8ed 100644 --- a/jedi/utils.py +++ b/jedi/utils.py @@ -22,12 +22,13 @@ def setup_readline(): except ImportError: # Fallback to the stdlib readline completer if it is installed. # Taken from http://docs.python.org/2/library/rlcompleter.html + print("Jedi is not installed, falling back to readline") try: import readline import rlcompleter readline.parse_and_bind("tab: complete") except ImportError: - pass + print("Readline is not installed either. No tab completion is enabled.") This will fallback to the readline completer if Jedi is not installed. The readline completer will only complete names in the global namespace, From 5e81fc22e1b4eb76fa1b4ea22847d010c04cc025 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Sat, 10 Aug 2013 11:20:31 -0600 Subject: [PATCH 8/8] Skip doctests that are just completion examples --- jedi/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jedi/utils.py b/jedi/utils.py index 704ab8ed..cd8b0c48 100644 --- a/jedi/utils.py +++ b/jedi/utils.py @@ -34,13 +34,13 @@ def setup_readline(): The readline completer will only complete names in the global namespace, so for example, - >>> ran + >>> ran # doctest: +SKIP will complete to ``range`` with both Jedi and readline, but - >>> range(10).cou + >>> range(10).cou # doctest: +SKIP will show complete to ``range(10).count`` only with Jedi.