]> git.wh0rd.org Git - home.git/commitdiff
ipython: fix up to work w/ipython-5 and py3
authorMike Frysinger <vapier@gentoo.org>
Wed, 15 Feb 2017 10:08:03 +0000 (05:08 -0500)
committerMike Frysinger <vapier@gentoo.org>
Wed, 15 Feb 2017 10:08:03 +0000 (05:08 -0500)
.gitignore
.ipython/profile_default/ipython_config.py [new file with mode: 0644]
.ipython/profile_default/startup/50-dump.py
.profile.d/aliases.sh

index 2ed139be471e4aec80dc8cc38bffca9cd77ea13e..e4635e4d37dd9dcfe039c1fdec33671519c7e0e7 100644 (file)
@@ -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 (file)
index 0000000..0a96067
--- /dev/null
@@ -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
index e1910eae62059286bf136ff198338a8db967d73f..11195a7763c5599de20f792b30f136edeb7de7a5 100644 (file)
@@ -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__
index 3ee83b7f206b561e5c1e5e1922b97fca2e6e8d3a..103b795174f19fd1d4c7020d0a45ad50779d221b 100644 (file)
@@ -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"