| 1322 | return user_module, user_ns |
| 1323 | |
| 1324 | def init_sys_modules(self): |
| 1325 | # We need to insert into sys.modules something that looks like a |
| 1326 | # module but which accesses the IPython namespace, for shelve and |
| 1327 | # pickle to work interactively. Normally they rely on getting |
| 1328 | # everything out of __main__, but for embedding purposes each IPython |
| 1329 | # instance has its own private namespace, so we can't go shoving |
| 1330 | # everything into __main__. |
| 1331 | |
| 1332 | # note, however, that we should only do this for non-embedded |
| 1333 | # ipythons, which really mimic the __main__.__dict__ with their own |
| 1334 | # namespace. Embedded instances, on the other hand, should not do |
| 1335 | # this because they need to manage the user local/global namespaces |
| 1336 | # only, but they live within a 'normal' __main__ (meaning, they |
| 1337 | # shouldn't overtake the execution environment of the script they're |
| 1338 | # embedded in). |
| 1339 | |
| 1340 | # This is overridden in the InteractiveShellEmbed subclass to a no-op. |
| 1341 | main_name = self.user_module.__name__ |
| 1342 | sys.modules[main_name] = self.user_module |
| 1343 | |
| 1344 | def init_user_ns(self): |
| 1345 | """Initialize all user-visible namespaces to their minimum defaults. |