|
|
@ -172,11 +172,12 @@ def prepare_exec_for_file(filename): |
|
|
|
if not os.path.isfile(os.path.join(dirpath, '__init__.py')): |
|
|
|
if not os.path.isfile(os.path.join(dirpath, '__init__.py')): |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if sys.path[0] != dirpath: |
|
|
|
sys.path.insert(0, dirpath) |
|
|
|
sys.path.insert(0, dirpath) |
|
|
|
return '.'.join(module[::-1]) |
|
|
|
return '.'.join(module[::-1]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def locate_app(script_info, app_id): |
|
|
|
def locate_app(script_info, app_id, raise_if_not_found=True): |
|
|
|
"""Attempts to locate the application.""" |
|
|
|
"""Attempts to locate the application.""" |
|
|
|
__traceback_hide__ = True |
|
|
|
__traceback_hide__ = True |
|
|
|
if ':' in app_id: |
|
|
|
if ':' in app_id: |
|
|
@ -194,11 +195,13 @@ def locate_app(script_info, app_id): |
|
|
|
stack_trace = traceback.format_exc() |
|
|
|
stack_trace = traceback.format_exc() |
|
|
|
raise NoAppException('There was an error trying to import' |
|
|
|
raise NoAppException('There was an error trying to import' |
|
|
|
' the app (%s):\n%s' % (module, stack_trace)) |
|
|
|
' the app (%s):\n%s' % (module, stack_trace)) |
|
|
|
else: |
|
|
|
elif raise_if_not_found: |
|
|
|
raise NoAppException('The file/path provided (%s) does not appear' |
|
|
|
raise NoAppException('The file/path provided (%s) does not appear' |
|
|
|
' to exist. Please verify the path is ' |
|
|
|
' to exist. Please verify the path is ' |
|
|
|
'correct. If app is not on PYTHONPATH, ' |
|
|
|
'correct. If app is not on PYTHONPATH, ' |
|
|
|
'ensure the extension is .py' % module) |
|
|
|
'ensure the extension is .py' % module) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
mod = sys.modules[module] |
|
|
|
mod = sys.modules[module] |
|
|
|
if app_obj is None: |
|
|
|
if app_obj is None: |
|
|
@ -326,15 +329,23 @@ class ScriptInfo(object): |
|
|
|
if self.create_app is not None: |
|
|
|
if self.create_app is not None: |
|
|
|
rv = call_factory(self.create_app, self) |
|
|
|
rv = call_factory(self.create_app, self) |
|
|
|
else: |
|
|
|
else: |
|
|
|
if not self.app_import_path: |
|
|
|
if self.app_import_path: |
|
|
|
|
|
|
|
rv = locate_app(self, self.app_import_path) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
for module in ['wsgi.py', 'app.py']: |
|
|
|
|
|
|
|
import_path = prepare_exec_for_file(module) |
|
|
|
|
|
|
|
rv = locate_app(self, import_path, |
|
|
|
|
|
|
|
raise_if_not_found=False) |
|
|
|
|
|
|
|
if rv: |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
if not rv: |
|
|
|
raise NoAppException( |
|
|
|
raise NoAppException( |
|
|
|
'Could not locate Flask application. You did not provide ' |
|
|
|
'Could not locate Flask application. You did not provide ' |
|
|
|
'the FLASK_APP environment variable.\n\nFor more ' |
|
|
|
'the FLASK_APP environment variable, and a wsgi.py or ' |
|
|
|
'information see ' |
|
|
|
'app.py module was not found in the current directory.\n\n' |
|
|
|
|
|
|
|
'For more information see ' |
|
|
|
'http://flask.pocoo.org/docs/latest/quickstart/') |
|
|
|
'http://flask.pocoo.org/docs/latest/quickstart/') |
|
|
|
|
|
|
|
|
|
|
|
rv = locate_app(self, self.app_import_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug = get_debug_flag() |
|
|
|
debug = get_debug_flag() |
|
|
|
|
|
|
|
|
|
|
|
if debug is not None: |
|
|
|
if debug is not None: |
|
|
|