Run the module after setting up the environment. First check the syntax. Next get customization. If OK, make sure the shell is active and then transfer the arguments, set the run environment's working directory to the directory of the module being executed and also
(self, event, *, customize=False)
| 110 | return self.run_module_event(event, customize=True) |
| 111 | |
| 112 | def run_module_event(self, event, *, customize=False): |
| 113 | """Run the module after setting up the environment. |
| 114 | |
| 115 | First check the syntax. Next get customization. If OK, make |
| 116 | sure the shell is active and then transfer the arguments, set |
| 117 | the run environment's working directory to the directory of the |
| 118 | module being executed and also add that directory to its |
| 119 | sys.path if not already included. |
| 120 | """ |
| 121 | if macosx.isCocoaTk() and (time.perf_counter() - self.perf < .05): |
| 122 | return 'break' |
| 123 | if isinstance(self.editwin, outwin.OutputWindow): |
| 124 | self.editwin.text.bell() |
| 125 | return 'break' |
| 126 | filename = self.getfilename() |
| 127 | if not filename: |
| 128 | return 'break' |
| 129 | code = self.checksyntax(filename) |
| 130 | if not code: |
| 131 | return 'break' |
| 132 | if not self.tabnanny(filename): |
| 133 | return 'break' |
| 134 | if customize: |
| 135 | title = f"Customize {self.editwin.short_title()} Run" |
| 136 | run_args = CustomRun(self.shell.text, title, |
| 137 | cli_args=self.cli_args).result |
| 138 | if not run_args: # User cancelled. |
| 139 | return 'break' |
| 140 | self.cli_args, restart = run_args if customize else ([], True) |
| 141 | interp = self.shell.interp |
| 142 | if pyshell.use_subprocess and restart: |
| 143 | interp.restart_subprocess( |
| 144 | with_cwd=False, filename=filename) |
| 145 | dirname = os.path.dirname(filename) |
| 146 | argv = [filename] |
| 147 | if self.cli_args: |
| 148 | argv += self.cli_args |
| 149 | interp.runcommand(f"""if 1: |
| 150 | __file__ = {filename!r} |
| 151 | import sys as _sys |
| 152 | from os.path import basename as _basename |
| 153 | argv = {argv!r} |
| 154 | if (not _sys.argv or |
| 155 | _basename(_sys.argv[0]) != _basename(__file__) or |
| 156 | len(argv) > 1): |
| 157 | _sys.argv = argv |
| 158 | import os as _os |
| 159 | _os.chdir({dirname!r}) |
| 160 | del _sys, argv, _basename, _os |
| 161 | \n""") |
| 162 | interp.prepend_syspath(filename) |
| 163 | # XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still |
| 164 | # go to __stderr__. With subprocess, they go to the shell. |
| 165 | # Need to change streams in pyshell.ModifiedInterpreter. |
| 166 | interp.runcode(code) |
| 167 | return 'break' |
| 168 | |
| 169 | def getfilename(self): |
no test coverage detected