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
(self, user_module=None, user_ns=None)
| 1278 | return self.user_module.__dict__ |
| 1279 | |
| 1280 | def prepare_user_module(self, user_module=None, user_ns=None): |
| 1281 | """Prepare the module and namespace in which user code will be run. |
| 1282 | |
| 1283 | When IPython is started normally, both parameters are None: a new module |
| 1284 | is created automatically, and its __dict__ used as the namespace. |
| 1285 | |
| 1286 | If only user_module is provided, its __dict__ is used as the namespace. |
| 1287 | If only user_ns is provided, a dummy module is created, and user_ns |
| 1288 | becomes the global namespace. If both are provided (as they may be |
| 1289 | when embedding), user_ns is the local namespace, and user_module |
| 1290 | provides the global namespace. |
| 1291 | |
| 1292 | Parameters |
| 1293 | ---------- |
| 1294 | user_module : module, optional |
| 1295 | The current user module in which IPython is being run. If None, |
| 1296 | a clean module will be created. |
| 1297 | user_ns : dict, optional |
| 1298 | A namespace in which to run interactive commands. |
| 1299 | |
| 1300 | Returns |
| 1301 | ------- |
| 1302 | A tuple of user_module and user_ns, each properly initialised. |
| 1303 | """ |
| 1304 | if user_module is None and user_ns is not None: |
| 1305 | user_ns.setdefault("__name__", "__main__") |
| 1306 | user_module = DummyMod() |
| 1307 | user_module.__dict__ = user_ns |
| 1308 | |
| 1309 | if user_module is None: |
| 1310 | user_module = types.ModuleType("__main__", |
| 1311 | doc="Automatically created module for IPython interactive environment") |
| 1312 | |
| 1313 | # We must ensure that __builtin__ (without the final 's') is always |
| 1314 | # available and pointing to the __builtin__ *module*. For more details: |
| 1315 | # http://mail.python.org/pipermail/python-dev/2001-April/014068.html |
| 1316 | user_module.__dict__.setdefault('__builtin__', builtin_mod) |
| 1317 | user_module.__dict__.setdefault('__builtins__', builtin_mod) |
| 1318 | |
| 1319 | if user_ns is None: |
| 1320 | user_ns = user_module.__dict__ |
| 1321 | |
| 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 |
no test coverage detected