Browse Source

shorten cli factory name

[ci skip]
pull/2319/head
David Lord 8 years ago
parent
commit
38df3df735
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
  1. 24
      flask/cli.py

24
flask/cli.py

@ -61,8 +61,7 @@ def find_best_app(script_info, module):
if callable(app_factory): if callable(app_factory):
try: try:
app = check_factory_for_script_info_and_call(app_factory, app = call_factory(app_factory, script_info)
script_info)
if isinstance(app, Flask): if isinstance(app, Flask):
return app return app
except TypeError: except TypeError:
@ -80,19 +79,18 @@ def find_best_app(script_info, module):
) )
def check_factory_for_script_info_and_call(func, script_info): def call_factory(func, script_info):
"""Given a function this checks if the function has an argument named """Checks if the given app factory function has an argument named
script_info or just a single argument and calls the function with ``script_info`` or just a single argument and calls the function passing
script_info if so. Otherwise calls the function without any arguments and ``script_info`` if so. Otherwise, calls the function without any arguments
returns the result.""" and returns the result.
"""
arguments = getargspec(func).args arguments = getargspec(func).args
if 'script_info' in arguments: if 'script_info' in arguments:
result = func(script_info=script_info) return func(script_info=script_info)
elif len(arguments) == 1: elif len(arguments) == 1:
result = func(script_info) return func(script_info)
else: return func()
result = func()
return result
def prepare_exec_for_file(filename): def prepare_exec_for_file(filename):
@ -275,7 +273,7 @@ class ScriptInfo(object):
if self._loaded_app is not None: if self._loaded_app is not None:
return self._loaded_app return self._loaded_app
if self.create_app is not None: if self.create_app is not None:
rv = check_factory_for_script_info_and_call(self.create_app, self) rv = call_factory(self.create_app, self)
else: else:
if not self.app_import_path: if not self.app_import_path:
raise NoAppException( raise NoAppException(

Loading…
Cancel
Save