chiark / gitweb /
dot/ipython-config.py: Hedge against the necessary modules not being there.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 9 Mar 2018 00:15:41 +0000 (00:15 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 9 Mar 2018 00:16:54 +0000 (00:16 +0000)
dot/ipython-config.py

index 9db7f6bd22d74a0b15090e9e73f55713569abdd6..ac08c66eac99b9a9316c3168bd245bd929d9fa82 100644 (file)
@@ -1,7 +1,9 @@
 ### -*-python -*-
 
-import pygments as PYG
-import prompt_toolkit as PTK
+try: import pygments as PYG
+except: PYG = None
+try: import prompt_toolkit as PTK
+except: PTK = None
 
 c = get_config()
 
@@ -18,34 +20,40 @@ c.TerminalInteractiveShell.confirm_exit = False
 c.TerminalInteractiveShell.display_completions = 'readlinelike'
 
 ## Syntax colouring.
-T = PYG.token
-c.TerminalInteractiveShell.highlighting_style = 'emacs'
-c.TerminalInteractiveShell.highlighting_style_overrides = {
-  T.Keyword: 'bold #fff',
-  T.Comment: 'italic #54ff9f',
-  T.Literal.Number: '#ffff00',
-  T.Literal.String: '#87ceff',
-  T.Literal.String.Escape: '#87ceff',
-  T.Literal.String.Interpol: '#87ceff',
-  T.Name: '#fff',
-  T.Name.Builtin: '#fff',
-  T.Name.Class: '#fff',
-  T.Name.Constant: 'italic #fff',
-  T.Name.Decorator: '#fff',
-  T.Name.Exception: '#fff',
-  T.Name.Function: '#fff',
-  T.Name.Function.Magic: '#fff',
-  T.Name.Label: '#fff',
-  T.Name.Namespace: '#fff',
-  T.Name.Variable: '#fff',
-  T.Name.Variable.Class: '#fff',
-  T.Name.Variable.Global: '#fff',
-  T.Name.Variable.Instance: '#fff',
-  T.Name.Variable.Magic: '#fff',
-  T.Operator: '#eec591',
-  T.Operator.Word: 'bold #fff',
-  T.Punctuation: '#eec591',
-  PTK.token.Token.MatchingBracket: '',
-  PTK.token.Token.MatchingBracket.Cursor: '',
-  PTK.token.Token.MatchingBracket.Other: 'bg:#006400'
-}
+if PYG and getattr(PYG, 'token', None):
+  T = PYG.token
+  c.TerminalInteractiveShell.highlighting_style = 'emacs'
+  c.TerminalInteractiveShell.highlighting_style_overrides = {
+    T.Keyword: 'bold #fff',
+    T.Comment: 'italic #54ff9f',
+    T.Literal.Number: '#ffff00',
+    T.Literal.String: '#87ceff',
+    T.Literal.String.Escape: '#87ceff',
+    T.Literal.String.Interpol: '#87ceff',
+    T.Name: '#fff',
+    T.Name.Builtin: '#fff',
+    T.Name.Class: '#fff',
+    T.Name.Constant: 'italic #fff',
+    T.Name.Decorator: '#fff',
+    T.Name.Exception: '#fff',
+    T.Name.Function: '#fff',
+    T.Name.Function.Magic: '#fff',
+    T.Name.Label: '#fff',
+    T.Name.Namespace: '#fff',
+    T.Name.Variable: '#fff',
+    T.Name.Variable.Class: '#fff',
+    T.Name.Variable.Global: '#fff',
+    T.Name.Variable.Instance: '#fff',
+    T.Name.Variable.Magic: '#fff',
+    T.Operator: '#eec591',
+    T.Operator.Word: 'bold #fff',
+    T.Punctuation: '#eec591',
+  }
+
+if PYG and PTK:
+  d = {
+    PTK.token.Token.MatchingBracket: '',
+    PTK.token.Token.MatchingBracket.Cursor: '',
+    PTK.token.Token.MatchingBracket.Other: 'bg:#006400'
+  }
+  c.TerminalInteractiveShell.highlighting_style_overrides.update(d)