i2y/mochi

examples/flask_restful.mochi has wrong __main__

pya opened this issue · 1 comments

pya commented

The example flask_restful.mochi does not run:

mochi flask_restful.mochi 
Traceback (most recent call last):
  File "/Users/mike/anaconda/envs/py34/bin/mochi", line 9, in <module>
    load_entry_point('mochi==0.2.1', 'console_scripts', 'mochi')()
  File "/Users/mike/anaconda/envs/py34/lib/python3.4/site-packages/mochi/core/main.py", line 174, in main
    load_file(args.file, global_env)
  File "/Users/mike/anaconda/envs/py34/lib/python3.4/site-packages/mochi/core/main.py", line 50, in load_file
    return exec(compile_file(path), env)
  File "flask_restful.mochi", line 8, in <module>
    app = Flask(__name__)
  File "/Users/mike/anaconda/envs/py34/lib/python3.4/site-packages/flask/app.py", line 331, in __init__
    instance_path = self.auto_find_instance_path()
  File "/Users/mike/anaconda/envs/py34/lib/python3.4/site-packages/flask/app.py", line 622, in auto_find_instance_path
    prefix, package_path = find_package(self.import_name)
  File "/Users/mike/anaconda/envs/py34/lib/python3.4/site-packages/flask/helpers.py", line 661, in find_package
    loader = pkgutil.get_loader(root_mod_name)
  File "/Users/mike/anaconda/envs/py34/lib/python3.4/pkgutil.py", line 471, in get_loader
    return find_loader(fullname)
  File "/Users/mike/anaconda/envs/py34/lib/python3.4/pkgutil.py", line 481, in find_loader
    if fullname.startswith('.'):
  File "/Users/mike/anaconda/envs/py34/lib/python3.4/site-packages/mochi/core/global_env.py", line 21, in __getattr__
    return self[attr]
KeyError: 'startswith'

This can be resolved by placing this in the file flask_restful.mochi:

import sys

sys.modules.pop(__name__)

The module __main__ is replaced by an instance of core.global_env.AttrDict. Deleting it fixes the problem.

pya commented

Duplicate of #23.