Show More
@@ -20,7 +20,6 b' import sys' | |||||
20 | # Our own packages |
|
20 | # Our own packages | |
21 | import IPython.utils.io |
|
21 | import IPython.utils.io | |
22 |
|
22 | |||
23 | from IPython.core import ipapi |
|
|||
24 | from IPython.core.inputlist import InputList |
|
23 | from IPython.core.inputlist import InputList | |
25 | from IPython.utils.pickleshare import PickleShareDB |
|
24 | from IPython.utils.pickleshare import PickleShareDB | |
26 | from IPython.utils.io import ask_yes_no |
|
25 | from IPython.utils.io import ask_yes_no | |
@@ -118,7 +117,7 b' class HistoryManager(object):' | |||||
118 | print(r"only has ASCII characters, e.g. c:\home") |
|
117 | print(r"only has ASCII characters, e.g. c:\home") | |
119 | print("Now it is", self.ipython_dir) |
|
118 | print("Now it is", self.ipython_dir) | |
120 | sys.exit() |
|
119 | sys.exit() | |
121 | self.shadow_hist = ShadowHist(self.shadow_db) |
|
120 | self.shadow_hist = ShadowHist(self.shadow_db, self.shell) | |
122 |
|
121 | |||
123 | def save_hist(self): |
|
122 | def save_hist(self): | |
124 | """Save input history to a file (via readline library).""" |
|
123 | """Save input history to a file (via readline library).""" | |
@@ -456,11 +455,12 b' def rep_f(self, arg):' | |||||
456 | _sentinel = object() |
|
455 | _sentinel = object() | |
457 |
|
456 | |||
458 | class ShadowHist(object): |
|
457 | class ShadowHist(object): | |
459 | def __init__(self, db): |
|
458 | def __init__(self, db, shell): | |
460 | # cmd => idx mapping |
|
459 | # cmd => idx mapping | |
461 | self.curidx = 0 |
|
460 | self.curidx = 0 | |
462 | self.db = db |
|
461 | self.db = db | |
463 | self.disabled = False |
|
462 | self.disabled = False | |
|
463 | self.shell = shell | |||
464 |
|
464 | |||
465 | def inc_idx(self): |
|
465 | def inc_idx(self): | |
466 | idx = self.db.get('shadowhist_idx', 1) |
|
466 | idx = self.db.get('shadowhist_idx', 1) | |
@@ -478,7 +478,7 b' class ShadowHist(object):' | |||||
478 | #print("new", newidx) # dbg |
|
478 | #print("new", newidx) # dbg | |
479 | self.db.hset('shadowhist',ent, newidx) |
|
479 | self.db.hset('shadowhist',ent, newidx) | |
480 | except: |
|
480 | except: | |
481 |
|
|
481 | self.shell.showtraceback() | |
482 | print("WARNING: disabling shadow history") |
|
482 | print("WARNING: disabling shadow history") | |
483 | self.disabled = True |
|
483 | self.disabled = True | |
484 |
|
484 |
@@ -154,6 +154,8 b' class InteractiveShell(Configurable, Magic):' | |||||
154 | deep_reload = CBool(False, config=True) |
|
154 | deep_reload = CBool(False, config=True) | |
155 | displayhook_class = Type(DisplayHook) |
|
155 | displayhook_class = Type(DisplayHook) | |
156 | exit_now = CBool(False) |
|
156 | exit_now = CBool(False) | |
|
157 | # Monotonically increasing execution counter | |||
|
158 | execution_count = Int(1) | |||
157 | filename = Str("<ipython console>") |
|
159 | filename = Str("<ipython console>") | |
158 | ipython_dir= Unicode('', config=True) # Set to get_ipython_dir() in __init__ |
|
160 | ipython_dir= Unicode('', config=True) # Set to get_ipython_dir() in __init__ | |
159 |
|
161 | |||
@@ -370,6 +372,10 b' class InteractiveShell(Configurable, Magic):' | |||||
370 | self.compile = codeop.CommandCompiler() |
|
372 | self.compile = codeop.CommandCompiler() | |
371 |
|
373 | |||
372 | # User input buffers |
|
374 | # User input buffers | |
|
375 | # NOTE: these variables are slated for full removal, once we are 100% | |||
|
376 | # sure that the new execution logic is solid. We will delte runlines, | |||
|
377 | # push_line and these buffers, as all input will be managed by the | |||
|
378 | # frontends via an inputsplitter instance. | |||
373 | self.buffer = [] |
|
379 | self.buffer = [] | |
374 | self.buffer_raw = [] |
|
380 | self.buffer_raw = [] | |
375 |
|
381 | |||
@@ -399,9 +405,6 b' class InteractiveShell(Configurable, Magic):' | |||||
399 | # Indentation management |
|
405 | # Indentation management | |
400 | self.indent_current_nsp = 0 |
|
406 | self.indent_current_nsp = 0 | |
401 |
|
407 | |||
402 | # Increasing execution counter |
|
|||
403 | self.execution_count = 1 |
|
|||
404 |
|
||||
405 | def init_environment(self): |
|
408 | def init_environment(self): | |
406 | """Any changes we need to make to the user's environment.""" |
|
409 | """Any changes we need to make to the user's environment.""" | |
407 | pass |
|
410 | pass | |
@@ -2066,27 +2069,6 b' class InteractiveShell(Configurable, Magic):' | |||||
2066 | cell : str |
|
2069 | cell : str | |
2067 | A single or multiline string. |
|
2070 | A single or multiline string. | |
2068 | """ |
|
2071 | """ | |
2069 | ################################################################# |
|
|||
2070 | # FIXME |
|
|||
2071 | # ===== |
|
|||
2072 | # This execution logic should stop calling runlines altogether, and |
|
|||
2073 | # instead we should do what runlines does, in a controlled manner, here |
|
|||
2074 | # (runlines mutates lots of state as it goes calling sub-methods that |
|
|||
2075 | # also mutate state). Basically we should: |
|
|||
2076 | # - apply dynamic transforms for single-line input (the ones that |
|
|||
2077 | # split_blocks won't apply since they need context). |
|
|||
2078 | # - increment the global execution counter (we need to pull that out |
|
|||
2079 | # from outputcache's control; outputcache should instead read it from |
|
|||
2080 | # the main object). |
|
|||
2081 | # - do any logging of input |
|
|||
2082 | # - update histories (raw/translated) |
|
|||
2083 | # - then, call plain run_source (for single blocks, so displayhook is |
|
|||
2084 | # triggered) or run_code (for multiline blocks in exec mode). |
|
|||
2085 | # |
|
|||
2086 | # Once this is done, we'll be able to stop using runlines and we'll |
|
|||
2087 | # also have a much cleaner separation of logging, input history and |
|
|||
2088 | # output cache management. |
|
|||
2089 | ################################################################# |
|
|||
2090 |
|
2072 | |||
2091 | # We need to break up the input into executable blocks that can be run |
|
2073 | # We need to break up the input into executable blocks that can be run | |
2092 | # in 'single' mode, to provide comfortable user behavior. |
|
2074 | # in 'single' mode, to provide comfortable user behavior. |
@@ -161,7 +161,7 b' def test_shist():' | |||||
161 | tfile = tempfile.mktemp('','tmp-ipython-') |
|
161 | tfile = tempfile.mktemp('','tmp-ipython-') | |
162 |
|
162 | |||
163 | db = pickleshare.PickleShareDB(tfile) |
|
163 | db = pickleshare.PickleShareDB(tfile) | |
164 | s = ShadowHist(db) |
|
164 | s = ShadowHist(db, get_ipython()) | |
165 | s.add('hello') |
|
165 | s.add('hello') | |
166 | s.add('world') |
|
166 | s.add('world') | |
167 | s.add('hello') |
|
167 | s.add('hello') |
General Comments 0
You need to be logged in to leave comments.
Login now