Commit e0fd2b3c authored by Robert Bradshaw's avatar Robert Bradshaw

Rename module to __main__ in embed mode.

This is more consistent with the execution of "python foo.py" and
also allows for compilation of files that don't obey the module
naming rules.
parent 5f7de216
......@@ -111,7 +111,7 @@ class Context(object):
return Errors.report_error(exc)
def find_module(self, module_name, relative_to=None, pos=None, need_pxd=1,
check_module_name=True, absolute_fallback=True):
absolute_fallback=True):
# Finds and returns the module scope corresponding to
# the given relative or absolute module name. If this
# is the first time the module has been requested, finds
......@@ -138,7 +138,7 @@ class Context(object):
else:
qualified_name = module_name
if check_module_name and not module_name_pattern.match(qualified_name):
if not module_name_pattern.match(qualified_name):
raise CompileError(pos or (module_name, 0, 0),
"'%s' is not a valid module name" % module_name)
......
......@@ -27,11 +27,13 @@ def abort_on_errors(node):
def parse_stage_factory(context):
def parse(compsrc):
source_desc = compsrc.source_desc
full_module_name = compsrc.full_module_name
if Options.embed:
full_module_name = "__main__"
else:
full_module_name = compsrc.full_module_name
initial_pos = (source_desc, 1, 0)
saved_cimport_from_pyx, Options.cimport_from_pyx = Options.cimport_from_pyx, False
scope = context.find_module(full_module_name, pos = initial_pos, need_pxd = 0,
check_module_name = not Options.embed)
scope = context.find_module(full_module_name, pos = initial_pos, need_pxd = 0)
Options.cimport_from_pyx = saved_cimport_from_pyx
tree = context.parse(source_desc, scope, pxd = 0, full_module_name = full_module_name)
tree.compilation_source = compsrc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment