From 760774afde2bdf7209a37044936c8ffd9862b6e2 Mon Sep 17 00:00:00 2001 From: John Jacobsen Date: Wed, 24 Apr 2013 09:21:16 -0400 Subject: [PATCH] Implement import_buffer_to_module --- hy/importer.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hy/importer.py b/hy/importer.py index 548eb1f..1287d8b 100644 --- a/hy/importer.py +++ b/hy/importer.py @@ -78,6 +78,13 @@ def import_file_to_module(module_name, fpath): return mod +def import_buffer_to_module(module_name, buf): + _ast = import_buffer_to_ast(buf) + mod = imp.new_module(module_name) + eval(ast_compile(_ast, "", "exec"), mod.__dict__) + return mod + + def hy_eval(hytree, namespace): foo = HyObject() foo.start_line = 0