Prepare the module and namespace in which user code will be run. When IPython is started normally, both parameters are None: a new module is created automatically, and its __dict__ used as the namespace. If only user_module is provided, its __dict__ is used as the namespace
(self, user_module=None, user_ns=None)
| 1324 | return self.user_module.__dict__ |
| 1325 | |
| 1326 | def prepare_user_module(self, user_module=None, user_ns=None): |
| 1327 | """Prepare the module and namespace in which user code will be run. |
| 1328 | |
| 1329 | When IPython is started normally, both parameters are None: a new module |
| 1330 | is created automatically, and its __dict__ used as the namespace. |
| 1331 | |
| 1332 | If only user_module is provided, its __dict__ is used as the namespace. |
| 1333 | If only user_ns is provided, a dummy module is created, and user_ns |
| 1334 | becomes the global namespace. If both are provided (as they may be |
| 1335 | when embedding), user_ns is the local namespace, and user_module |
| 1336 | provides the global namespace. |
| 1337 | |
| 1338 | Parameters |
| 1339 | ---------- |
| 1340 | user_module : module, optional |
| 1341 | The current user module in which IPython is being run. If None, |
| 1342 | a clean module will be created. |
| 1343 | user_ns : dict, optional |
| 1344 | A namespace in which to run interactive commands. |
| 1345 | |
| 1346 | Returns |
| 1347 | ------- |
| 1348 | A tuple of user_module and user_ns, each properly initialised. |
| 1349 | """ |
| 1350 | if user_module is None and user_ns is not None: |
| 1351 | user_ns.setdefault("__name__", "__main__") |
| 1352 | user_module = make_main_module_type(user_ns)() |
| 1353 | |
| 1354 | if user_module is None: |
| 1355 | user_module = types.ModuleType("__main__", |
| 1356 | doc="Automatically created module for IPython interactive environment") |
| 1357 | |
| 1358 | # We must ensure that __builtin__ (without the final 's') is always |
| 1359 | # available and pointing to the __builtin__ *module*. For more details: |
| 1360 | # http://mail.python.org/pipermail/python-dev/2001-April/014068.html |
| 1361 | user_module.__dict__.setdefault('__builtin__', builtin_mod) |
| 1362 | user_module.__dict__.setdefault('__builtins__', builtin_mod) |
| 1363 | |
| 1364 | if user_ns is None: |
| 1365 | user_ns = user_module.__dict__ |
| 1366 | return user_module, user_ns |
| 1367 | |
| 1368 | def init_sys_modules(self): |
| 1369 | # We need to insert into sys.modules something that looks like a |
no test coverage detected