(self)
| 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 |
| 939 | matplotlib.use(mplbackend) |
| 940 | |
| 941 | # Must be called after (potentially) importing matplotlib and |
| 942 | # setting its backend since exec_lines might import pylab. |
| 943 | self.shell = EmbeddedSphinxShell(exec_lines) |
| 944 | |
| 945 | # Store IPython directive to enable better error messages |
| 946 | self.shell.directive = self |
| 947 | |
| 948 | # reset the execution count if we haven't processed this doc |
| 949 | #NOTE: this may be borked if there are multiple seen_doc tmp files |
| 950 | #check time stamp? |
| 951 | if not self.state.document.current_source in self.seen_docs: |
| 952 | self.shell.IP.history_manager.reset() |
| 953 | self.shell.IP.execution_count = 1 |
| 954 | self.seen_docs.add(self.state.document.current_source) |
| 955 | |
| 956 | # and attach to shell so we don't have to pass them around |
| 957 | self.shell.rgxin = rgxin |
| 958 | self.shell.rgxout = rgxout |
| 959 | self.shell.promptin = promptin |
| 960 | self.shell.promptout = promptout |
| 961 | self.shell.savefig_dir = savefig_dir |
| 962 | self.shell.source_dir = source_dir |
| 963 | self.shell.hold_count = hold_count |
| 964 | self.shell.warning_is_error = warning_is_error |
| 965 | |
| 966 | # setup bookmark for saving figures directory |
| 967 | self.shell.process_input_line('bookmark ipy_savedir %s'%savefig_dir, |
| 968 | store_history=False) |
| 969 | self.shell.clear_cout() |
| 970 | |
| 971 | return rgxin, rgxout, promptin, promptout |
| 972 | |
| 973 | def teardown(self): |
| 974 | # delete last bookmark |
no test coverage detected