##// END OF EJS Templates
Merge branch 'master' of https://github.com/abakan/ipython
Ahmet Bakan -
r10598:235caf66 merge
parent child Browse files
Show More
@@ -0,0 +1,157 b''
1 /*
2
3 Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
4 Adapted from GitHub theme
5
6 */
7
8 pre code {
9 display: block;
10 padding: 0.5em;
11 }
12
13 .highlight-base,
14 pre code,
15 pre .subst,
16 pre .tag .title,
17 pre .lisp .title,
18 pre .clojure .built_in,
19 pre .nginx .title {
20 color: black;
21 }
22
23 .highlight-string,
24 pre .string,
25 pre .constant,
26 pre .parent,
27 pre .tag .value,
28 pre .rules .value,
29 pre .rules .value .number,
30 pre .preprocessor,
31 pre .ruby .symbol,
32 pre .ruby .symbol .string,
33 pre .aggregate,
34 pre .template_tag,
35 pre .django .variable,
36 pre .smalltalk .class,
37 pre .addition,
38 pre .flow,
39 pre .stream,
40 pre .bash .variable,
41 pre .apache .tag,
42 pre .apache .cbracket,
43 pre .tex .command,
44 pre .tex .special,
45 pre .erlang_repl .function_or_atom,
46 pre .markdown .header {
47 color: #BA2121;
48 }
49
50 .highlight-comment,
51 pre .comment,
52 pre .annotation,
53 pre .template_comment,
54 pre .diff .header,
55 pre .chunk,
56 pre .markdown .blockquote {
57 color: #408080;
58 font-style: italic;
59 }
60
61 .highlight-number,
62 pre .number,
63 pre .date,
64 pre .regexp,
65 pre .literal,
66 pre .smalltalk .symbol,
67 pre .smalltalk .char,
68 pre .go .constant,
69 pre .change,
70 pre .markdown .bullet,
71 pre .markdown .link_url {
72 color: #080;
73 }
74
75 pre .label,
76 pre .javadoc,
77 pre .ruby .string,
78 pre .decorator,
79 pre .filter .argument,
80 pre .localvars,
81 pre .array,
82 pre .attr_selector,
83 pre .important,
84 pre .pseudo,
85 pre .pi,
86 pre .doctype,
87 pre .deletion,
88 pre .envvar,
89 pre .shebang,
90 pre .apache .sqbracket,
91 pre .nginx .built_in,
92 pre .tex .formula,
93 pre .erlang_repl .reserved,
94 pre .prompt,
95 pre .markdown .link_label,
96 pre .vhdl .attribute,
97 pre .clojure .attribute,
98 pre .coffeescript .property {
99 color: #88F
100 }
101
102 .highlight-keyword,
103 pre .keyword,
104 pre .id,
105 pre .phpdoc,
106 pre .aggregate,
107 pre .css .tag,
108 pre .javadoctag,
109 pre .phpdoc,
110 pre .yardoctag,
111 pre .smalltalk .class,
112 pre .winutils,
113 pre .bash .variable,
114 pre .apache .tag,
115 pre .go .typename,
116 pre .tex .command,
117 pre .markdown .strong,
118 pre .request,
119 pre .status {
120 color: #008000;
121 font-weight: bold;
122 }
123
124 .highlight-builtin,
125 pre .built_in {
126 color: #008000;
127 }
128
129 pre .markdown .emphasis {
130 font-style: italic;
131 }
132
133 pre .nginx .built_in {
134 font-weight: normal;
135 }
136
137 pre .coffeescript .javascript,
138 pre .javascript .xml,
139 pre .tex .formula,
140 pre .xml .javascript,
141 pre .xml .vbscript,
142 pre .xml .css,
143 pre .xml .cdata {
144 opacity: 0.5;
145 }
146
147 /* apply the same style to codemirror */
148
149 .cm-s-ipython span.cm-variable { .highlight-base()}
150 .cm-s-ipython span.cm-keyword { .highlight-keyword() }
151 .cm-s-ipython span.cm-number { .highlight-number() }
152 .cm-s-ipython span.cm-comment { .highlight-comment() }
153 .cm-s-ipython span.cm-string { .highlight-string()}
154 .cm-s-ipython span.cm-builtin { .highlight-builtin() }
155 .cm-s-ipython span.cm-error { color: #f00; }
156 .cm-s-ipython span.cm-operator {color: #AA22FF; font-weight: bold;}
157 .cm-s-ipython span.cm-meta {color: #AA22FF;}
@@ -1,3 +1,3 b''
1 1 [submodule "components"]
2 2 path = IPython/frontend/html/notebook/static/components
3 url = git://github.com/ipython/ipython-components.git
3 url = https://github.com/ipython/ipython-components.git
@@ -144,8 +144,17 b' class BaseIPythonApplication(Application):'
144 144 # The class to use as the crash handler.
145 145 crash_handler_class = Type(crashhandler.CrashHandler)
146 146
147 @catch_config_error
147 148 def __init__(self, **kwargs):
148 149 super(BaseIPythonApplication, self).__init__(**kwargs)
150 # ensure current working directory exists
151 try:
152 directory = os.getcwdu()
153 except:
154 # raise exception
155 self.log.error("Current working directory doesn't exist.")
156 raise
157
149 158 # ensure even default IPYTHONDIR exists
150 159 if not os.path.exists(self.ipython_dir):
151 160 self._ipython_dir_changed('ipython_dir', self.ipython_dir, self.ipython_dir)
@@ -77,8 +77,7 b' python-profiler package from non-free.""")'
77 77
78 78 @skip_doctest
79 79 @line_cell_magic
80 def prun(self, parameter_s='', cell=None, user_mode=True,
81 opts=None,arg_lst=None,prog_ns=None):
80 def prun(self, parameter_s='', cell=None):
82 81
83 82 """Run a statement through the python code profiler.
84 83
@@ -178,38 +177,33 b' python-profiler package from non-free.""")'
178 177
179 178 In [1]: import profile; profile.help()
180 179 """
181
182 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
183
184 if user_mode: # regular user call
185 180 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:q',
186 181 list_all=True, posix=False)
187 namespace = self.shell.user_ns
188 182 if cell is not None:
189 183 arg_str += '\n' + cell
190 else: # called to run a program by %run -p
191 try:
192 filename = get_py_filename(arg_lst[0])
193 except IOError as e:
194 try:
195 msg = str(e)
196 except UnicodeError:
197 msg = e.message
198 error(msg)
199 return
184 return self._run_with_profiler(arg_str, opts, self.shell.user_ns)
200 185
201 arg_str = 'execfile(filename,prog_ns)'
202 namespace = {
203 'execfile': self.shell.safe_execfile,
204 'prog_ns': prog_ns,
205 'filename': filename
206 }
186 def _run_with_profiler(self, code, opts, namespace):
187 """
188 Run `code` with profiler. Used by ``%prun`` and ``%run -p``.
189
190 Parameters
191 ----------
192 code : str
193 Code to be executed.
194 opts : Struct
195 Options parsed by `self.parse_options`.
196 namespace : dict
197 A dictionary for Python namespace (e.g., `self.shell.user_ns`).
207 198
208 opts.merge(opts_def)
199 """
200
201 # Fill default values for unspecified options:
202 opts.merge(Struct(D=[''], l=[], s=['time'], T=['']))
209 203
210 204 prof = profile.Profile()
211 205 try:
212 prof = prof.runctx(arg_str,namespace,namespace)
206 prof = prof.runctx(code, namespace, namespace)
213 207 sys_exit = ''
214 208 except SystemExit:
215 209 sys_exit = """*** SystemExit exception caught in code being profiled."""
@@ -327,8 +321,10 b' python-profiler package from non-free.""")'
327 321 file_finder=get_py_filename):
328 322 """Run the named file inside IPython as a program.
329 323
330 Usage:\\
331 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options] -G] file [args]
324 Usage:
325 %run [-n -i -e -G]
326 [( -t [-N<N>] | -d [-b<N>] | -p [profile options] )]
327 ( -m mod | file ) [args]
332 328
333 329 Parameters after the filename are passed as command-line arguments to
334 330 the program (put in sys.argv). Then, control returns to IPython's
@@ -541,13 +537,123 b' python-profiler package from non-free.""")'
541 537 # every single object ever created.
542 538 sys.modules[main_mod_name] = main_mod
543 539
540 if 'p' in opts or 'd' in opts:
541 if 'm' in opts:
542 code = 'run_module(modulename, prog_ns)'
543 code_ns = {
544 'run_module': self.shell.safe_run_module,
545 'prog_ns': prog_ns,
546 'modulename': modulename,
547 }
548 else:
549 code = 'execfile(filename, prog_ns)'
550 code_ns = {
551 'execfile': self.shell.safe_execfile,
552 'prog_ns': prog_ns,
553 'filename': get_py_filename(filename),
554 }
555
544 556 try:
545 557 stats = None
546 558 with self.shell.readline_no_record:
547 559 if 'p' in opts:
548 stats = self.prun('', None, False, opts, arg_lst, prog_ns)
560 stats = self._run_with_profiler(code, opts, code_ns)
549 561 else:
550 562 if 'd' in opts:
563 self._run_with_debugger(
564 code, code_ns, opts.get('b', ['1'])[0], filename)
565 else:
566 if 'm' in opts:
567 def run():
568 self.shell.safe_run_module(modulename, prog_ns)
569 else:
570 if runner is None:
571 runner = self.default_runner
572 if runner is None:
573 runner = self.shell.safe_execfile
574
575 def run():
576 runner(filename, prog_ns, prog_ns,
577 exit_ignore=exit_ignore)
578
579 if 't' in opts:
580 # timed execution
581 try:
582 nruns = int(opts['N'][0])
583 if nruns < 1:
584 error('Number of runs must be >=1')
585 return
586 except (KeyError):
587 nruns = 1
588 self._run_with_timing(run, nruns)
589 else:
590 # regular execution
591 run()
592
593 if 'i' in opts:
594 self.shell.user_ns['__name__'] = __name__save
595 else:
596 # The shell MUST hold a reference to prog_ns so after %run
597 # exits, the python deletion mechanism doesn't zero it out
598 # (leaving dangling references).
599 self.shell.cache_main_mod(prog_ns, filename)
600 # update IPython interactive namespace
601
602 # Some forms of read errors on the file may mean the
603 # __name__ key was never set; using pop we don't have to
604 # worry about a possible KeyError.
605 prog_ns.pop('__name__', None)
606
607 with preserve_keys(self.shell.user_ns, '__file__'):
608 self.shell.user_ns.update(prog_ns)
609 finally:
610 # It's a bit of a mystery why, but __builtins__ can change from
611 # being a module to becoming a dict missing some key data after
612 # %run. As best I can see, this is NOT something IPython is doing
613 # at all, and similar problems have been reported before:
614 # http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-10/0188.html
615 # Since this seems to be done by the interpreter itself, the best
616 # we can do is to at least restore __builtins__ for the user on
617 # exit.
618 self.shell.user_ns['__builtins__'] = builtin_mod
619
620 # Ensure key global structures are restored
621 sys.argv = save_argv
622 if restore_main:
623 sys.modules['__main__'] = restore_main
624 else:
625 # Remove from sys.modules the reference to main_mod we'd
626 # added. Otherwise it will trap references to objects
627 # contained therein.
628 del sys.modules[main_mod_name]
629
630 return stats
631
632 def _run_with_debugger(self, code, code_ns, break_point, filename):
633 """
634 Run `code` in debugger with a break point.
635
636 Parameters
637 ----------
638 code : str
639 Code to execute.
640 code_ns : dict
641 A namespace in which `code` is executed.
642 break_point : str
643 Line number in the file specified by `filename` argument
644 or a string in the format ``file:line``. In the latter
645 case, `filename` is ignored.
646 See also :func:`.parse_breakpoint`.
647 filename : str
648 Path to the file in which break point is specified.
649
650 Raises
651 ------
652 UsageError
653 If no meaningful break point is given by `break_point` and
654 `filename`.
655
656 """
551 657 deb = debugger.Pdb(self.shell.colors)
552 658 # reset Breakpoint state, which is moronically kept
553 659 # in a class
@@ -556,7 +662,7 b' python-profiler package from non-free.""")'
556 662 bdb.Breakpoint.bpbynumber = [None]
557 663 # Set an initial breakpoint to stop execution
558 664 maxtries = 10
559 bp_file, bp_line = parse_breakpoint(opts.get('b', ['1'])[0], filename)
665 bp_file, bp_line = parse_breakpoint(break_point, filename)
560 666 checkline = deb.checkline(bp_file, bp_line)
561 667 if not checkline:
562 668 for bp in range(bp_line + 1, bp_line + maxtries + 1):
@@ -568,8 +674,7 b' python-profiler package from non-free.""")'
568 674 "after trying up to line: %s.\n"
569 675 "Please set a valid breakpoint manually "
570 676 "with the -b option." % bp)
571 error(msg)
572 return
677 raise UsageError(msg)
573 678 # if we find a good linenumber, set the breakpoint
574 679 deb.do_break('%s:%s' % (bp_file, bp_line))
575 680
@@ -580,11 +685,10 b' python-profiler package from non-free.""")'
580 685 # Start file run
581 686 print "NOTE: Enter 'c' at the",
582 687 print "%s prompt to start your script." % deb.prompt
583 ns = {'execfile': py3compat.execfile, 'prog_ns': prog_ns}
584 688 try:
585 689 #save filename so it can be used by methods on the deb object
586 690 deb._exec_filename = filename
587 deb.run('execfile("%s", prog_ns)' % filename, ns)
691 deb.run(code, code_ns)
588 692
589 693 except:
590 694 etype, value, tb = sys.exc_info()
@@ -592,25 +696,24 b' python-profiler package from non-free.""")'
592 696 # one inside bdb.py, and the command-line typed by the
593 697 # user (run by exec in pdb itself).
594 698 self.shell.InteractiveTB(etype, value, tb, tb_offset=3)
595 else:
596 if runner is None:
597 runner = self.default_runner
598 if runner is None:
599 runner = self.shell.safe_execfile
600 if 't' in opts:
601 # timed execution
602 try:
603 nruns = int(opts['N'][0])
604 if nruns < 1:
605 error('Number of runs must be >=1')
606 return
607 except (KeyError):
608 nruns = 1
699
700 @staticmethod
701 def _run_with_timing(run, nruns):
702 """
703 Run function `run` and print timing information.
704
705 Parameters
706 ----------
707 run : callable
708 Any callable object which takes no argument.
709 nruns : int
710 Number of times to execute `run`.
711
712 """
609 713 twall0 = time.time()
610 714 if nruns == 1:
611 715 t0 = clock2()
612 runner(filename, prog_ns, prog_ns,
613 exit_ignore=exit_ignore)
716 run()
614 717 t1 = clock2()
615 718 t_usr = t1[0] - t0[0]
616 719 t_sys = t1[1] - t0[1]
@@ -621,8 +724,7 b' python-profiler package from non-free.""")'
621 724 runs = range(nruns)
622 725 t0 = clock2()
623 726 for nr in runs:
624 runner(filename, prog_ns, prog_ns,
625 exit_ignore=exit_ignore)
727 run()
626 728 t1 = clock2()
627 729 t_usr = t1[0] - t0[0]
628 730 t_sys = t1[1] - t0[1]
@@ -634,49 +736,6 b' python-profiler package from non-free.""")'
634 736 twall1 = time.time()
635 737 print "Wall time: %10.2f s." % (twall1 - twall0)
636 738
637 else:
638 # regular execution
639 runner(filename, prog_ns, prog_ns, exit_ignore=exit_ignore)
640
641 if 'i' in opts:
642 self.shell.user_ns['__name__'] = __name__save
643 else:
644 # The shell MUST hold a reference to prog_ns so after %run
645 # exits, the python deletion mechanism doesn't zero it out
646 # (leaving dangling references).
647 self.shell.cache_main_mod(prog_ns, filename)
648 # update IPython interactive namespace
649
650 # Some forms of read errors on the file may mean the
651 # __name__ key was never set; using pop we don't have to
652 # worry about a possible KeyError.
653 prog_ns.pop('__name__', None)
654
655 with preserve_keys(self.shell.user_ns, '__file__'):
656 self.shell.user_ns.update(prog_ns)
657 finally:
658 # It's a bit of a mystery why, but __builtins__ can change from
659 # being a module to becoming a dict missing some key data after
660 # %run. As best I can see, this is NOT something IPython is doing
661 # at all, and similar problems have been reported before:
662 # http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-10/0188.html
663 # Since this seems to be done by the interpreter itself, the best
664 # we can do is to at least restore __builtins__ for the user on
665 # exit.
666 self.shell.user_ns['__builtins__'] = builtin_mod
667
668 # Ensure key global structures are restored
669 sys.argv = save_argv
670 if restore_main:
671 sys.modules['__main__'] = restore_main
672 else:
673 # Remove from sys.modules the reference to main_mod we'd
674 # added. Otherwise it will trap references to objects
675 # contained therein.
676 del sys.modules[main_mod_name]
677
678 return stats
679
680 739 @skip_doctest
681 740 @line_cell_magic
682 741 def timeit(self, line='', cell=None):
@@ -13,9 +13,13 b' from __future__ import absolute_import'
13 13 # Imports
14 14 #-----------------------------------------------------------------------------
15 15
16 import functools
16 17 import os
18 import random
17 19 import sys
18 20 import tempfile
21 import textwrap
22 import unittest
19 23
20 24 import nose.tools as nt
21 25 from nose import SkipTest
@@ -23,6 +27,8 b' from nose import SkipTest'
23 27 from IPython.testing import decorators as dec
24 28 from IPython.testing import tools as tt
25 29 from IPython.utils import py3compat
30 from IPython.utils.tempdir import TemporaryDirectory
31 from IPython.core import debugger
26 32
27 33 #-----------------------------------------------------------------------------
28 34 # Test functions begin
@@ -337,3 +343,74 b' tclass.py: deleting object: C-third'
337 343 self.mktmp(src)
338 344 _ip.magic('run -t -N 1 %s' % self.fname)
339 345 _ip.magic('run -t -N 10 %s' % self.fname)
346
347
348 class TestMagicRunWithPackage(unittest.TestCase):
349
350 def writefile(self, name, content):
351 path = os.path.join(self.tempdir.name, name)
352 d = os.path.dirname(path)
353 if not os.path.isdir(d):
354 os.makedirs(d)
355 with open(path, 'w') as f:
356 f.write(textwrap.dedent(content))
357
358 def setUp(self):
359 self.package = package = 'tmp{0}'.format(repr(random.random())[2:])
360 """Temporary valid python package name."""
361
362 self.value = int(random.random() * 10000)
363
364 self.tempdir = TemporaryDirectory()
365 self.__orig_cwd = os.getcwdu()
366 sys.path.insert(0, self.tempdir.name)
367
368 self.writefile(os.path.join(package, '__init__.py'), '')
369 self.writefile(os.path.join(package, 'sub.py'), """
370 x = {0!r}
371 """.format(self.value))
372 self.writefile(os.path.join(package, 'relative.py'), """
373 from .sub import x
374 """)
375 self.writefile(os.path.join(package, 'absolute.py'), """
376 from {0}.sub import x
377 """.format(package))
378
379 def tearDown(self):
380 os.chdir(self.__orig_cwd)
381 sys.path[:] = [p for p in sys.path if p != self.tempdir.name]
382 self.tempdir.cleanup()
383
384 def check_run_submodule(self, submodule, opts=''):
385 _ip.magic('run {2} -m {0}.{1}'.format(self.package, submodule, opts))
386 self.assertEqual(_ip.user_ns['x'], self.value,
387 'Variable `x` is not loaded from module `{0}`.'
388 .format(submodule))
389
390 def test_run_submodule_with_absolute_import(self):
391 self.check_run_submodule('absolute')
392
393 def test_run_submodule_with_relative_import(self):
394 """Run submodule that has a relative import statement (#2727)."""
395 self.check_run_submodule('relative')
396
397 def test_prun_submodule_with_absolute_import(self):
398 self.check_run_submodule('absolute', '-p')
399
400 def test_prun_submodule_with_relative_import(self):
401 self.check_run_submodule('relative', '-p')
402
403 def with_fake_debugger(func):
404 @functools.wraps(func)
405 def wrapper(*args, **kwds):
406 with tt.monkeypatch(debugger.Pdb, 'run', staticmethod(eval)):
407 return func(*args, **kwds)
408 return wrapper
409
410 @with_fake_debugger
411 def test_debug_run_submodule_with_absolute_import(self):
412 self.check_run_submodule('absolute', '-d')
413
414 @with_fake_debugger
415 def test_debug_run_submodule_with_relative_import(self):
416 self.check_run_submodule('relative', '-d')
@@ -1,1 +1,1 b''
1 Subproject commit f7467391a9f9d4868f0bbf0d088fd572625862a4
1 Subproject commit 945dfca396a1a7ca66d36ee758c7d8dca2b11287
@@ -866,6 +866,26 b' a.label:hover,a.label:focus,a.badge:hover,a.badge:focus{color:#ffffff;text-decor'
866 866 .end{-webkit-box-pack:end;-moz-box-pack:end;box-pack:end;}
867 867 .center{-webkit-box-pack:center;-moz-box-pack:center;box-pack:center;}
868 868 .corner-all{border-radius:4px;}
869 pre code{display:block;padding:0.5em;}
870 .highlight-base,pre code,pre .subst,pre .tag .title,pre .lisp .title,pre .clojure .built_in,pre .nginx .title{color:black;}
871 .highlight-string,pre .string,pre .constant,pre .parent,pre .tag .value,pre .rules .value,pre .rules .value .number,pre .preprocessor,pre .ruby .symbol,pre .ruby .symbol .string,pre .aggregate,pre .template_tag,pre .django .variable,pre .smalltalk .class,pre .addition,pre .flow,pre .stream,pre .bash .variable,pre .apache .tag,pre .apache .cbracket,pre .tex .command,pre .tex .special,pre .erlang_repl .function_or_atom,pre .markdown .header{color:#BA2121;}
872 .highlight-comment,pre .comment,pre .annotation,pre .template_comment,pre .diff .header,pre .chunk,pre .markdown .blockquote{color:#408080;font-style:italic;}
873 .highlight-number,pre .number,pre .date,pre .regexp,pre .literal,pre .smalltalk .symbol,pre .smalltalk .char,pre .go .constant,pre .change,pre .markdown .bullet,pre .markdown .link_url{color:#080;}
874 pre .label,pre .javadoc,pre .ruby .string,pre .decorator,pre .filter .argument,pre .localvars,pre .array,pre .attr_selector,pre .important,pre .pseudo,pre .pi,pre .doctype,pre .deletion,pre .envvar,pre .shebang,pre .apache .sqbracket,pre .nginx .built_in,pre .tex .formula,pre .erlang_repl .reserved,pre .prompt,pre .markdown .link_label,pre .vhdl .attribute,pre .clojure .attribute,pre .coffeescript .property{color:#8888ff;}
875 .highlight-keyword,pre .keyword,pre .id,pre .phpdoc,pre .aggregate,pre .css .tag,pre .javadoctag,pre .phpdoc,pre .yardoctag,pre .smalltalk .class,pre .winutils,pre .bash .variable,pre .apache .tag,pre .go .typename,pre .tex .command,pre .markdown .strong,pre .request,pre .status{color:#008000;font-weight:bold;}
876 .highlight-builtin,pre .built_in{color:#008000;}
877 pre .markdown .emphasis{font-style:italic;}
878 pre .nginx .built_in{font-weight:normal;}
879 pre .coffeescript .javascript,pre .javascript .xml,pre .tex .formula,pre .xml .javascript,pre .xml .vbscript,pre .xml .css,pre .xml .cdata{opacity:0.5;}
880 .cm-s-ipython span.cm-variable{color:black;}
881 .cm-s-ipython span.cm-keyword{color:#008000;font-weight:bold;}
882 .cm-s-ipython span.cm-number{color:#080;}
883 .cm-s-ipython span.cm-comment{color:#408080;font-style:italic;}
884 .cm-s-ipython span.cm-string{color:#BA2121;}
885 .cm-s-ipython span.cm-builtin{color:#008000;}
886 .cm-s-ipython span.cm-error{color:#f00;}
887 .cm-s-ipython span.cm-operator{color:#AA22FF;font-weight:bold;}
888 .cm-s-ipython span.cm-meta{color:#AA22FF;}
869 889 body{background-color:#ffffff;}
870 890 body.notebook_app{overflow:hidden;}
871 891 blockquote{border-left:4px solid #DDD;padding:0 15px;color:#777;}
@@ -42,7 +42,6 b' $(document).ready(function () {'
42 42 var baseProjectUrl = $('body').data('baseProjectUrl')
43 43
44 44 IPython.page = new IPython.Page();
45 IPython.markdown_converter = new Markdown.Converter();
46 45 IPython.layout_manager = new IPython.LayoutManager();
47 46 IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
48 47 IPython.quick_help = new IPython.QuickHelp('span#quick_help_area');
@@ -95,5 +94,22 b' $(document).ready(function () {'
95 94 $([IPython.events]).on('notebook_loaded.Notebook', first_load);
96 95 IPython.notebook.load_notebook($('body').data('notebookId'));
97 96
97 if (marked) {
98 marked.setOptions({
99 gfm : true,
100 tables: true,
101 langPrefix: "language-",
102 highlight: function(code, lang) {
103 var highlighted;
104 try {
105 highlighted = hljs.highlight(lang, code, false);
106 } catch(err) {
107 highlighted = hljs.highlightAuto(code);
108 }
109 return highlighted.value;
110 }
111 })
112 }
113
98 114 });
99 115
@@ -140,6 +140,7 b' var IPython = (function (IPython) {'
140 140 SaveWidget.prototype.set_last_checkpoint = function (checkpoint) {
141 141 if (!checkpoint) {
142 142 this.set_checkpoint_status("");
143 return;
143 144 }
144 145 var d = new Date(checkpoint.last_modified);
145 146 this.set_checkpoint_status(
@@ -298,7 +298,7 b' var IPython = (function (IPython) {'
298 298
299 299 MarkdownCell.options_default = {
300 300 cm_config: {
301 mode: 'markdown'
301 mode: 'gfm'
302 302 },
303 303 placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$"
304 304 }
@@ -315,9 +315,9 b' var IPython = (function (IPython) {'
315 315 if (this.rendered === false) {
316 316 var text = this.get_text();
317 317 if (text === "") { text = this.placeholder; }
318 text = IPython.mathjaxutils.remove_math(text)
319 var html = IPython.markdown_converter.makeHtml(text);
320 html = IPython.mathjaxutils.replace_math(html)
318 text = IPython.mathjaxutils.remove_math(text);
319 var html = marked.parser(marked.lexer(text));
320 html = IPython.mathjaxutils.replace_math(html);
321 321 try {
322 322 this.set_rendered(html);
323 323 } catch (e) {
@@ -329,18 +329,6 b' var IPython = (function (IPython) {'
329 329 }
330 330 this.element.find('div.text_cell_input').hide();
331 331 this.element.find("div.text_cell_render").show();
332 var code_snippets = this.element.find("pre > code");
333 code_snippets.replaceWith(function () {
334 var code = $(this).html();
335 /* Substitute br for newlines and &nbsp; for spaces
336 before highlighting, since prettify doesn't
337 preserve those on all browsers */
338 code = code.replace(/(\r\n|\n|\r)/gm, "<br/>");
339 code = code.replace(/ /gm, '&nbsp;');
340 code = prettyPrintOne(code);
341
342 return '<code class="prettyprint">' + code + '</code>';
343 });
344 332 this.typeset()
345 333 this.rendered = true;
346 334 }
@@ -5,7 +5,7 b''
5 5 */
6 6
7 7 @import "variables.less";
8
8 @import "highlight.less";
9 9
10 10 body {
11 11 background-color:@notebook_background;
@@ -12,9 +12,6 b' window.mathjax_url = "{{mathjax_url}}";'
12 12 </script>
13 13
14 14 <link rel="stylesheet" href="{{ static_url("components/codemirror/lib/codemirror.css") }}">
15 <link rel="stylesheet" href="{{ static_url("css/codemirror-ipython.css") }}">
16
17 <link rel="stylesheet" href="{{ static_url("prettify/prettify.css") }}"/>
18 15
19 16 <link rel="stylesheet" href="{{ static_url("css/celltoolbar.css") }}" type="text/css" />
20 17
@@ -198,6 +195,7 b' class="notebook_app"'
198 195 <script src="{{ static_url("components/codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
199 196 <script src="{{ static_url("components/codemirror/addon/mode/loadmode.js") }}" charset="utf-8"></script>
200 197 <script src="{{ static_url("components/codemirror/addon/mode/multiplex.js") }}" charset="utf-8"></script>
198 <script src="{{ static_url("components/codemirror/addon/mode/overlay.js") }}" charset="utf-8"></script>
201 199 <script src="{{ static_url("js/codemirror-ipython.js") }}" charset="utf-8"></script>
202 200 <script src="{{ static_url("components/codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script>
203 201 <script src="{{ static_url("components/codemirror/mode/xml/xml.js") }}" charset="utf-8"></script>
@@ -205,10 +203,11 b' class="notebook_app"'
205 203 <script src="{{ static_url("components/codemirror/mode/css/css.js") }}" charset="utf-8"></script>
206 204 <script src="{{ static_url("components/codemirror/mode/rst/rst.js") }}" charset="utf-8"></script>
207 205 <script src="{{ static_url("components/codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script>
206 <script src="{{ static_url("components/codemirror/mode/gfm/gfm.js") }}" charset="utf-8"></script>
208 207
209 <script src="{{ static_url("pagedown/Markdown.Converter.js") }}" charset="utf-8"></script>
208 <script src="{{ static_url("components/marked/lib/marked.js") }}" charset="utf-8"></script>
209 <script src="{{ static_url("components/highlight.js/build/highlight.pack.js") }}" charset="utf-8"></script>
210 210
211 <script src="{{ static_url("prettify/prettify.js") }}" charset="utf-8"></script>
212 211 <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script>
213 212
214 213 <script src="{{ static_url("js/events.js") }}" type="text/javascript" charset="utf-8"></script>
@@ -24,7 +24,7 b' from zmq.eventloop import ioloop, zmqstream'
24 24
25 25 from IPython.config.configurable import LoggingConfigurable
26 26 from IPython.utils.py3compat import str_to_bytes
27 from IPython.utils.traitlets import Set, Instance, CFloat, Integer
27 from IPython.utils.traitlets import Set, Instance, CFloat, Integer, Dict
28 28
29 29 from IPython.parallel.util import log_errors
30 30
@@ -74,6 +74,9 b' class HeartMonitor(LoggingConfigurable):'
74 74 help='The frequency at which the Hub pings the engines for heartbeats '
75 75 '(in ms)',
76 76 )
77 max_heartmonitor_misses = Integer(10, config=True,
78 help='Allowed consecutive missed pings from controller Hub to engine before unregistering.',
79 )
77 80
78 81 pingstream=Instance('zmq.eventloop.zmqstream.ZMQStream')
79 82 pongstream=Instance('zmq.eventloop.zmqstream.ZMQStream')
@@ -84,7 +87,7 b' class HeartMonitor(LoggingConfigurable):'
84 87 # not settable:
85 88 hearts=Set()
86 89 responses=Set()
87 on_probation=Set()
90 on_probation=Dict()
88 91 last_ping=CFloat(0)
89 92 _new_handlers = Set()
90 93 _failure_handlers = Set()
@@ -121,11 +124,12 b' class HeartMonitor(LoggingConfigurable):'
121 124 self.log.debug("heartbeat::sending %s", self.lifetime)
122 125 goodhearts = self.hearts.intersection(self.responses)
123 126 missed_beats = self.hearts.difference(goodhearts)
124 heartfailures = self.on_probation.intersection(missed_beats)
125 127 newhearts = self.responses.difference(goodhearts)
126 128 map(self.handle_new_heart, newhearts)
129 heartfailures, on_probation = self._check_missed(missed_beats, self.on_probation,
130 self.hearts)
127 131 map(self.handle_heart_failure, heartfailures)
128 self.on_probation = missed_beats.intersection(self.hearts)
132 self.on_probation = on_probation
129 133 self.responses = set()
130 134 #print self.on_probation, self.hearts
131 135 # self.log.debug("heartbeat::beat %.3f, %i beating hearts", self.lifetime, len(self.hearts))
@@ -133,6 +137,20 b' class HeartMonitor(LoggingConfigurable):'
133 137 # flush stream to force immediate socket send
134 138 self.pingstream.flush()
135 139
140 def _check_missed(self, missed_beats, on_probation, hearts):
141 """Update heartbeats on probation, identifying any that have too many misses.
142 """
143 failures = []
144 new_probation = {}
145 for cur_heart in (b for b in missed_beats if b in hearts):
146 miss_count = on_probation.get(cur_heart, 0) + 1
147 self.log.info("heartbeat::missed %s : %s" % (cur_heart, miss_count))
148 if miss_count > self.max_heartmonitor_misses:
149 failures.append(cur_heart)
150 else:
151 new_probation[cur_heart] = miss_count
152 return failures, new_probation
153
136 154 def handle_new_heart(self, heart):
137 155 if self._new_handlers:
138 156 for handler in self._new_handlers:
@@ -11,8 +11,6 b''
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14
15
16 14 from IPython.parallel.apps.ipclusterapp import launch_new_instance
17 15
18 16 launch_new_instance()
@@ -11,8 +11,6 b''
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14
15
16 14 from IPython.parallel.apps.ipcontrollerapp import launch_new_instance
17 15
18 16 launch_new_instance()
@@ -11,10 +11,6 b''
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14
15
16 14 from IPython.parallel.apps.ipengineapp import launch_new_instance
17 15
18 16 launch_new_instance()
19
20
@@ -11,10 +11,6 b''
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14
15
16 14 from IPython.parallel.apps.iploggerapp import launch_new_instance
17 15
18 16 launch_new_instance()
19
20
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1319 lines changed) Show them Hide them
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now