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

Class IPythonDirective

IPython/sphinxext/ipython_directive.py:881–1043  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

879
880
881class IPythonDirective(Directive):
882
883 has_content = True
884 required_arguments = 0
885 optional_arguments = 4 # python, suppress, verbatim, doctest
886 final_argumuent_whitespace = True
887 option_spec = { 'python': directives.unchanged,
888 'suppress' : directives.flag,
889 'verbatim' : directives.flag,
890 'doctest' : directives.flag,
891 'okexcept': directives.flag,
892 'okwarning': directives.flag
893 }
894
895 shell = None
896
897 seen_docs = set()
898
899 def get_config_options(self):
900 # contains sphinx configuration variables
901 config = self.state.document.settings.env.config
902
903 # get config variables to set figure output directory
904 savefig_dir = config.ipython_savefig_dir
905 source_dir = self.state.document.settings.env.srcdir
906 savefig_dir = os.path.join(source_dir, savefig_dir)
907
908 # get regex and prompt stuff
909 rgxin = config.ipython_rgxin
910 rgxout = config.ipython_rgxout
911 warning_is_error= config.ipython_warning_is_error
912 promptin = config.ipython_promptin
913 promptout = config.ipython_promptout
914 mplbackend = config.ipython_mplbackend
915 exec_lines = config.ipython_execlines
916 hold_count = config.ipython_holdcount
917
918 return (savefig_dir, source_dir, rgxin, rgxout,
919 promptin, promptout, mplbackend, exec_lines, hold_count, warning_is_error)
920
921 def setup(self):
922 # Get configuration values.
923 (savefig_dir, source_dir, rgxin, rgxout, promptin, promptout,
924 mplbackend, exec_lines, hold_count, warning_is_error) = self.get_config_options()
925
926 try:
927 os.makedirs(savefig_dir)
928 except OSError as e:
929 if e.errno != errno.EEXIST:
930 raise
931
932 if self.shell is None:
933 # We will be here many times. However, when the
934 # EmbeddedSphinxShell is created, its interactive shell member
935 # is the same for each instance.
936
937 if mplbackend and 'matplotlib.backends' not in sys.modules and use_matplotlib:
938 import matplotlib

Callers 1

testFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected