From 22072cded51c50548aa955366c67edc44a46fcce Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 15 Feb 2017 05:08:03 -0500 Subject: [PATCH] ipython: fix up to work w/ipython-5 and py3 --- .gitignore | 1 + .ipython/profile_default/ipython_config.py | 12 +++++++ .ipython/profile_default/startup/50-dump.py | 37 ++++++++++++--------- .profile.d/aliases.sh | 30 ++++++++++++++++- 4 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 .ipython/profile_default/ipython_config.py diff --git a/.gitignore b/.gitignore index 2ed139b..e4635e4 100644 --- a/.gitignore +++ b/.gitignore @@ -334,6 +334,7 @@ lock /.gnupg/random_seed /.ipython/README +/.ipython/profile_default/db/ /.ipython/profile_default/history.sqlite /.ipython/profile_default/startup/README /.ipython/profile_default/static/ diff --git a/.ipython/profile_default/ipython_config.py b/.ipython/profile_default/ipython_config.py new file mode 100644 index 0000000..0a96067 --- /dev/null +++ b/.ipython/profile_default/ipython_config.py @@ -0,0 +1,12 @@ +from IPython.terminal.prompts import Prompts, Token + + +class MyPrompt(Prompts): + def in_prompt_tokens(self, cli=None): + return [(Token.Prompt, '>>> ')] + + def out_prompt_tokens(self, cli=None): + return [] + + +c.InteractiveShell.prompts_class = MyPrompt diff --git a/.ipython/profile_default/startup/50-dump.py b/.ipython/profile_default/startup/50-dump.py index e1910ea..11195a7 100644 --- a/.ipython/profile_default/startup/50-dump.py +++ b/.ipython/profile_default/startup/50-dump.py @@ -25,8 +25,8 @@ class Dump(object): # Objects that hold multiple objects (can be looped over). TYPES_ITERABLES = ( types.GeneratorType, - types.ListType, - types.TupleType, + list, + tuple, ) # Objects that we shouldn't really probe. @@ -37,23 +37,21 @@ class Dump(object): # Simple objects we don't decode further. TYPES_SCALAR = ( - types.BooleanType, - types.ComplexType, - types.FloatType, - types.IntType, - types.LongType, - types.NoneType, - types.StringType, - types.UnicodeType, - - types.ClassType, - types.TypeType, + bool, + complex, + float, + int, + #types.LongType, + type(None), + bytes, + str, + + type, ) # Objects that are dictionary based. TYPES_DICT = ( - types.DictType, - types.DictionaryType, + dict, ) # Standard python objects we don't normally expand. @@ -110,7 +108,13 @@ class Dump(object): return s def dump(self, obj, depth=0, name=None): - """Dump |obj| with |name|""" + """Dump |obj| with |name|. + + Args: + obj: The object to dump. + depth: How deep to recursively dive. + name: The name? + """ indent = ' ' * depth def w(msg, indent=indent, color=None): for line in msg.splitlines(): @@ -202,3 +206,4 @@ class Dump(object): def dump(*args, **kwargs): d = Dump(*args, **kwargs) del d +dump.__doc__ = Dump.dump.__doc__ diff --git a/.profile.d/aliases.sh b/.profile.d/aliases.sh index 3ee83b7..103b795 100644 --- a/.profile.d/aliases.sh +++ b/.profile.d/aliases.sh @@ -11,7 +11,6 @@ alias gdb='gdb --quiet' alias gdbtui='gdbtui --quiet' alias nohist='export HISTFILE=/dev/null' alias kpdf='okular' -alias ipython='ipython --no-banner --no-confirm-exit --pdb --nosep --PromptManager.in_template=">>> " --PromptManager.out_template="" --PromptManager.justify=False' if command -v elinks >/dev/null ; then alias links='elinks -default-mime-type text/html' alias lynx=links @@ -36,6 +35,35 @@ alias xine='xine -l' alias wol-vapier='wakeonlan -i 192.168.1.255 00:25:22:64:19:79; wakeonlan -i 192.168.0.255 00:25:22:64:19:79' +_ipython() { + # These guys keep changing their CLI because they hate their users. + local cmd=$1; shift + local args=( + --no-banner + --no-confirm-exit + --pdb + --nosep + --term-title + --pprint + ) + + case $(command ${cmd} --version) in + 0*) ;; + [123]*) + args+=( + --PromptManager.in_template='>>> ' + --PromptManager.out_template='' + --PromptManager.justify=False + ) + ;; + esac + + command ${cmd} "${args[@]}" "$@" +} +ipython() { _ipython ${FUNCNAME}; } +ipython2() { _ipython ${FUNCNAME}; } +ipython3() { _ipython ${FUNCNAME}; } + adk_path() { local adk=/usr/local/src/android/adk/current/sdk PATH+=":${adk}/tools:${adk}/platform-tools" -- 2.39.5