(self, spy=False, spy_delimiter=('-' * 30), output_fn=None, locals=None, filename="<stdin>", allow_incomplete=True)
| 218 | __module__ = 'hy' |
| 219 | |
| 220 | def __init__(self, spy=False, spy_delimiter=('-' * 30), output_fn=None, locals=None, filename="<stdin>", allow_incomplete=True): |
| 221 | |
| 222 | # Create a proper module for this REPL so that we can obtain it easily |
| 223 | # (e.g. using `importlib.import_module`). |
| 224 | # We let `InteractiveConsole` initialize `self.locals` when it's |
| 225 | # `None`. |
| 226 | super().__init__(locals=locals, filename=filename) |
| 227 | |
| 228 | module_name = self.locals.get("__name__", "__console__") |
| 229 | # Make sure our newly created module is properly introduced to |
| 230 | # `sys.modules`, and consistently use its namespace as `self.locals` |
| 231 | # from here on. |
| 232 | self.module = sys.modules.setdefault(module_name, types.ModuleType(module_name)) |
| 233 | self.module.__dict__.update(self.locals) |
| 234 | self.locals = self.module.__dict__ |
| 235 | |
| 236 | self.ps1 = "=> " |
| 237 | self.ps2 = "... " |
| 238 | |
| 239 | if os.environ.get("HYSTARTUP"): |
| 240 | try: |
| 241 | loader = HyLoader("__hystartup__", os.environ.get("HYSTARTUP")) |
| 242 | spec = importlib.util.spec_from_loader(loader.name, loader) |
| 243 | mod = importlib.util.module_from_spec(spec) |
| 244 | sys.modules.setdefault(mod.__name__, mod) |
| 245 | loader.exec_module(mod) |
| 246 | imports = mod.__dict__.get( |
| 247 | "__all__", |
| 248 | [name for name in mod.__dict__ if not name.startswith("_")], |
| 249 | ) |
| 250 | imports = {name: mod.__dict__[name] for name in imports} |
| 251 | spy = spy or imports.get("repl_spy") |
| 252 | output_fn = output_fn or imports.get("repl_output_fn") |
| 253 | self.ps1 = imports.get("repl_ps1", self.ps1) |
| 254 | self.ps2 = imports.get("repl_ps2", self.ps2) |
| 255 | |
| 256 | # Load imports and defs |
| 257 | self.locals.update(imports) |
| 258 | |
| 259 | # load module macros |
| 260 | require(mod, self.module, assignments="ALL") |
| 261 | require_reader(mod, self.module, assignments="ALL") |
| 262 | except Exception as e: |
| 263 | print(e) |
| 264 | |
| 265 | self.hy_compiler = HyASTCompiler(self.module, module_name) |
| 266 | |
| 267 | self.cmdline_cache = {} |
| 268 | self.compile = HyCommandCompiler( |
| 269 | self.module, |
| 270 | self.locals, |
| 271 | ast_callback=self.ast_callback, |
| 272 | hy_compiler=self.hy_compiler, |
| 273 | cmdline_cache=self.cmdline_cache, |
| 274 | allow_incomplete=allow_incomplete, |
| 275 | ) |
| 276 | |
| 277 | self.spy = spy |
no test coverage detected