MCPcopy
hub / github.com/hylang/hy / __init__

Method __init__

hy/repl.py:220–305  ·  view source on GitHub ↗
(self, spy=False, spy_delimiter=('-' * 30), output_fn=None, locals=None, filename="<stdin>", allow_incomplete=True)

Source from the content-addressed store, hash-verified

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

Callers 1

__init__Method · 0.45

Calls 9

ast_callbackMethod · 0.95
HyLoaderClass · 0.90
requireFunction · 0.90
require_readerFunction · 0.90
HyASTCompilerClass · 0.90
mangleFunction · 0.90
hy_compileFunction · 0.90
read_manyFunction · 0.90
HyCommandCompilerClass · 0.85

Tested by

no test coverage detected