|
|
@ -41,32 +41,42 @@ def find_best_app(module): |
|
|
|
return app |
|
|
|
return app |
|
|
|
|
|
|
|
|
|
|
|
# Otherwise find the only object that is a Flask instance. |
|
|
|
# Otherwise find the only object that is a Flask instance. |
|
|
|
matches = [v for k, v in iteritems(module.__dict__) |
|
|
|
matches = [ |
|
|
|
if isinstance(v, Flask)] |
|
|
|
v for k, v in iteritems(module.__dict__) if isinstance(v, Flask) |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
if len(matches) == 1: |
|
|
|
if len(matches) == 1: |
|
|
|
return matches[0] |
|
|
|
return matches[0] |
|
|
|
|
|
|
|
elif len(matches) > 1: |
|
|
|
|
|
|
|
raise NoAppException( |
|
|
|
|
|
|
|
'Auto-detected multiple Flask applications in module "{module}".' |
|
|
|
|
|
|
|
' Use "FLASK_APP={module}:name" to specify the correct' |
|
|
|
|
|
|
|
' one.'.format(module=module.__name__) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
# Search for app factory callables. |
|
|
|
# Search for app factory callables. |
|
|
|
for attr_name in 'create_app', 'make_app': |
|
|
|
for attr_name in 'create_app', 'make_app': |
|
|
|
app_factory = getattr(module, attr_name, None) |
|
|
|
app_factory = getattr(module, attr_name, None) |
|
|
|
|
|
|
|
|
|
|
|
if callable(app_factory): |
|
|
|
if callable(app_factory): |
|
|
|
try: |
|
|
|
try: |
|
|
|
app = app_factory() |
|
|
|
app = app_factory() |
|
|
|
|
|
|
|
|
|
|
|
if isinstance(app, Flask): |
|
|
|
if isinstance(app, Flask): |
|
|
|
return app |
|
|
|
return app |
|
|
|
except TypeError: |
|
|
|
except TypeError: |
|
|
|
raise NoAppException( |
|
|
|
raise NoAppException( |
|
|
|
'Auto-detected "{callable}()" in module "{module}", but ' |
|
|
|
'Auto-detected "{callable}()" in module "{module}", but ' |
|
|
|
'could not call it without specifying arguments.' |
|
|
|
'could not call it without specifying arguments.'.format( |
|
|
|
.format(callable=attr_name, |
|
|
|
callable=attr_name, module=module.__name__ |
|
|
|
module=module.__name__)) |
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
raise NoAppException( |
|
|
|
raise NoAppException( |
|
|
|
'Failed to find application in module "{module}". Are you sure ' |
|
|
|
'Failed to find application in module "{module}". Are you sure ' |
|
|
|
'it contains a Flask application? Maybe you wrapped it in a WSGI ' |
|
|
|
'it contains a Flask application? Maybe you wrapped it in a WSGI ' |
|
|
|
'middleware or you are using a factory function.' |
|
|
|
'middleware.'.format(module=module.__name__) |
|
|
|
.format(module=module.__name__)) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prepare_exec_for_file(filename): |
|
|
|
def prepare_exec_for_file(filename): |
|
|
|