MCPcopy Create free account
hub / github.com/ipython/ipython / run

Method run

IPython/sphinxext/ipython_directive.py:979–1043  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

977 self.shell.clear_cout()
978
979 def run(self):
980 debug = False
981
982 #TODO, any reason block_parser can't be a method of embeddable shell
983 # then we wouldn't have to carry these around
984 rgxin, rgxout, promptin, promptout = self.setup()
985
986 options = self.options
987 self.shell.is_suppress = 'suppress' in options
988 self.shell.is_doctest = 'doctest' in options
989 self.shell.is_verbatim = 'verbatim' in options
990 self.shell.is_okexcept = 'okexcept' in options
991 self.shell.is_okwarning = 'okwarning' in options
992
993 # handle pure python code
994 if 'python' in self.arguments:
995 content = self.content
996 self.content = self.shell.process_pure_python(content)
997
998 # parts consists of all text within the ipython-block.
999 # Each part is an input/output block.
1000 parts = '\n'.join(self.content).split('\n\n')
1001
1002 lines = ['.. code-block:: ipython', '']
1003 figures = []
1004
1005 for part in parts:
1006 block = block_parser(part, rgxin, rgxout, promptin, promptout)
1007 if len(block):
1008 rows, figure = self.shell.process_block(block)
1009 for row in rows:
1010 lines.extend([' {0}'.format(line)
1011 for line in row.split('\n')])
1012
1013 if figure is not None:
1014 figures.append(figure)
1015 else:
1016 message = 'Code input with no code at {}, line {}'\
1017 .format(
1018 self.state.document.current_source,
1019 self.state.document.current_line)
1020 if self.shell.warning_is_error:
1021 raise RuntimeError(message)
1022 else:
1023 warnings.warn(message)
1024
1025 for figure in figures:
1026 lines.append('')
1027 lines.extend(figure.split('\n'))
1028 lines.append('')
1029
1030 if len(lines) > 2:
1031 if debug:
1032 print('\n'.join(lines))
1033 else:
1034 # This has to do with input, not output. But if we comment
1035 # these lines out, then no IPython code will appear in the
1036 # final output.

Callers

nothing calls this directly

Calls 7

setupMethod · 0.95
teardownMethod · 0.95
block_parserFunction · 0.85
process_pure_pythonMethod · 0.80
process_blockMethod · 0.80
warnMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected