Skip to content
Myr

Merge remote-tracking branch 'pallets/master' into 2313-refactor-gevent-tests-into-class

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Rene A. Zelaya · committed by Rene A. Zelaya · parents 2eb2816, 39f7aaa · Browse files · 7 files+84 added−32 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+84 added−32 removed

  • tests:+41 added−21 removed
  • other:+43 added−11 removed

7 files+84 added−32 removed

modified:docs/quickstart.rst+8 added-1 removed
48 unmodified lines
49 $ export FLASK_APP=hello.py50 $ flask run51 * Running on http://127.0.0.1:5000/5253If you are on Windows you need to use ``set`` instead of ``export``.53If you are on Windows, the environment variable syntax depends on command line54interpreter. On Command Prompt::5556 C:\path\to\app>set FLASK_APP=hello.py5758And on PowerShell::5960 PS C:\path\to\app> $env:FLASK_APP = "hello.py"6162Alternatively you can use :command:`python -m flask`::6364 $ export FLASK_APP=hello.py65 $ python -m flask run
784 unmodified lines
modified:flask/_compat.py+2 added
23 unmodified lines
24 iterkeys = lambda d: iter(d.keys())25 itervalues = lambda d: iter(d.values())26 iteritems = lambda d: iter(d.items())2728 from inspect import getfullargspec as getargspec29 from io import StringIO3031 def reraise(tp, value, tb=None):32 if value.__traceback__ is not tb:
10 unmodified lines
43 iterkeys = lambda d: d.iterkeys()44 itervalues = lambda d: d.itervalues()45 iteritems = lambda d: d.iteritems()4647 from inspect import getargspec48 from cStringIO import StringIO4950 exec('def reraise(tp, value, tb=None):\n raise tp, value, tb')51
47 unmodified lines
modified:flask/cli.py+21 added-7 removed
20 unmodified lines
21from . import __version__22from ._compat import iteritems, reraise23from .globals import current_app24from .helpers import get_debug_flag25from ._compat import getargspec262728class NoAppException(click.UsageError):29 """Raised if an application cannot be found or loaded."""303131def find_best_app(module):32def find_best_app(script_info, module):33 """Given a module instance this tries to find the best possible34 application in the module or raises an exception.35 """36 from . import Flask
23 unmodified lines
60 app_factory = getattr(module, attr_name, None)6162 if callable(app_factory):63 try:63 app = app_factory()6464 app = call_factory(app_factory, script_info)65 if isinstance(app, Flask):66 return app67 except TypeError:68 raise NoAppException(
9 unmodified lines
78 'middleware.'.format(module=module.__name__)79 )808182def call_factory(func, script_info):83 """Checks if the given app factory function has an argument named 84 ``script_info`` or just a single argument and calls the function passing 85 ``script_info`` if so. Otherwise, calls the function without any arguments86 and returns the result.87 """88 arguments = getargspec(func).args89 if 'script_info' in arguments:90 return func(script_info=script_info)91 elif len(arguments) == 1:92 return func(script_info)93 return func()949596def prepare_exec_for_file(filename):97 """Given a filename this will try to calculate the python path, add it98 to the search path and return the actual module name that is expected.99 """
21 unmodified lines
121 sys.path.insert(0, dirpath)122 return '.'.join(module[::-1])123124111def locate_app(app_id):125def locate_app(script_info, app_id):126 """Attempts to locate the application."""127 __traceback_hide__ = True128 if ':' in app_id:129 module, app_obj = app_id.split(':', 1)
17 unmodified lines
147 'ensure the extension is .py' % module)148149 mod = sys.modules[module]150 if app_obj is None:137 app = find_best_app(mod)151 app = find_best_app(script_info, mod)152 else:153 app = getattr(mod, app_obj, None)154 if app is None:155 raise RuntimeError('Failed to find application in module "%s"'
116 unmodified lines
272 __traceback_hide__ = True273 if self._loaded_app is not None:274 return self._loaded_app275 if self.create_app is not None:262 rv = self.create_app(self)276 rv = call_factory(self.create_app, self)277 else:278 if not self.app_import_path:279 raise NoAppException(280 'Could not locate Flask application. You did not provide '281 'the FLASK_APP environment variable.\n\nFor more '282 'information see '283 'http://flask.pocoo.org/docs/latest/quickstart/')270 rv = locate_app(self.app_import_path)284 rv = locate_app(self, self.app_import_path)285 debug = get_debug_flag()286 if debug is not None:287 rv.debug = debug288 self._loaded_app = rv
333 unmodified lines
modified:tests/test_cli.py+41 added-21 removed
37 unmodified lines
383940def test_find_best_app(test_apps):41 """Test if `find_best_app` behaves as expected with different combinations of input."""42 script_info = ScriptInfo()43 class Module:44 app = Flask('appname')44 assert find_best_app(Module) == Module.app45 assert find_best_app(script_info, Module) == Module.app4647 class Module:48 application = Flask('appname')48 assert find_best_app(Module) == Module.application49 assert find_best_app(script_info, Module) == Module.application5051 class Module:52 myapp = Flask('appname')52 assert find_best_app(Module) == Module.myapp53 assert find_best_app(script_info, Module) == Module.myapp5455 class Module:56 @staticmethod57 def create_app():58 return Flask('appname')58 assert isinstance(find_best_app(Module), Flask)59 assert find_best_app(Module).name == 'appname'59 assert isinstance(find_best_app(script_info, Module), Flask)60 assert find_best_app(script_info, Module).name == 'appname'6162 class Module:63 @staticmethod64 def create_app(foo):65 return Flask('appname')66 assert isinstance(find_best_app(script_info, Module), Flask)67 assert find_best_app(script_info, Module).name == 'appname'6869 class Module:70 @staticmethod71 def create_app(foo=None, script_info=None):72 return Flask('appname')73 assert isinstance(find_best_app(script_info, Module), Flask)74 assert find_best_app(script_info, Module).name == 'appname'7576 class Module:77 @staticmethod78 def make_app():79 return Flask('appname')65 assert isinstance(find_best_app(Module), Flask)66 assert find_best_app(Module).name == 'appname'80 assert isinstance(find_best_app(script_info, Module), Flask)81 assert find_best_app(script_info, Module).name == 'appname'8283 class Module:84 myapp = Flask('appname1')85 @staticmethod86 def create_app():87 return Flask('appname2')73 assert find_best_app(Module) == Module.myapp88 assert find_best_app(script_info, Module) == Module.myapp8990 class Module:91 myapp = Flask('appname1')92 @staticmethod78 def create_app(foo):93 def create_app():94 return Flask('appname2')80 assert find_best_app(Module) == Module.myapp95 assert find_best_app(script_info, Module) == Module.myapp9697 class Module:98 pass84 pytest.raises(NoAppException, find_best_app, Module)99 pytest.raises(NoAppException, find_best_app, script_info, Module)100101 class Module:102 myapp1 = Flask('appname1')103 myapp2 = Flask('appname2')89 pytest.raises(NoAppException, find_best_app, Module)104 pytest.raises(NoAppException, find_best_app, script_info, Module)105106 class Module:107 @staticmethod93 def create_app(foo):108 def create_app(foo, bar):109 return Flask('appname2')95 pytest.raises(NoAppException, find_best_app, Module)110 pytest.raises(NoAppException, find_best_app, script_info, Module)111112113def test_prepare_exec_for_file(test_apps):114 """Expect the correct path to be set and the correct module name to be returned.
16 unmodified lines
131132133def test_locate_app(test_apps):134 """Test of locate_app."""120 assert locate_app("cliapp.app").name == "testapp"121 assert locate_app("cliapp.app:testapp").name == "testapp"122 assert locate_app("cliapp.multiapp:app1").name == "app1"123 pytest.raises(NoAppException, locate_app, "notanpp.py")124 pytest.raises(NoAppException, locate_app, "cliapp/app")125 pytest.raises(RuntimeError, locate_app, "cliapp.app:notanapp")126 pytest.raises(NoAppException, locate_app, "cliapp.importerrorapp")135 script_info = ScriptInfo()136 assert locate_app(script_info, "cliapp.app").name == "testapp"137 assert locate_app(script_info, "cliapp.app:testapp").name == "testapp"138 assert locate_app(script_info, "cliapp.multiapp:app1").name == "app1"139 pytest.raises(NoAppException, locate_app,140 script_info, "notanpp.py")141 pytest.raises(NoAppException, locate_app,142 script_info, "cliapp/app")143 pytest.raises(RuntimeError, locate_app,144 script_info, "cliapp.app:notanapp")145 pytest.raises(NoAppException, locate_app,146 script_info, "cliapp.importerrorapp")147148149def test_find_default_import_path(test_apps, monkeypatch, tmpdir):150 """Test of find_default_import_path."""
174 unmodified lines
modified:CHANGES+5 added
40 unmodified lines
41- ``SESSION_COOKIE_DOMAIN`` is set if it is detected through ``SERVER_NAME``.42 (`#2282`_)43- Auto-detect zero-argument app factory called ``create_app`` or ``make_app``44 from ``FLASK_APP``. (`#2297`_)45- Factory functions are not required to take a ``script_info`` parameter to46 work with the ``flask`` command. If they take a single parameter or a47 parameter named ``script_info``, the ``ScriptInfo`` object will be passed.48 (`#2319`_)4950.. _#1489: https://github.com/pallets/flask/pull/148951.. _#1898: https://github.com/pallets/flask/pull/189852.. _#1936: https://github.com/pallets/flask/pull/1936
3 unmodified lines
56.. _#2256: https://github.com/pallets/flask/pull/225657.. _#2259: https://github.com/pallets/flask/pull/225958.. _#2282: https://github.com/pallets/flask/pull/228259.. _#2297: https://github.com/pallets/flask/pull/229760.. _#2319: https://github.com/pallets/flask/pull/23196162Version 0.12.263--------------64
615 unmodified lines
modified:setup.py+1 added-1 removed
72 unmodified lines
73 install_requires=[74 'Werkzeug>=0.7',75 'Jinja2>=2.4',76 'itsdangerous>=0.21',77 'click>=2.0',77 'click>=4.0',78 ],79 classifiers=[80 'Development Status :: 4 - Beta',81 'Environment :: Web Environment',
19 unmodified lines
modified:tox.ini+6 added-2 removed
1[tox]2envlist = {py26,py27,pypy}-{lowest,release,devel}{,-simplejson}, {py33,py34,py35,py36}-{release,devel}{,-simplejson}3454[testenv]5passenv = LANG6usedevelop=true7commands =
9 unmodified lines
1718 lowest: Werkzeug==0.719 lowest: Jinja2==2.420 lowest: itsdangerous==0.2121 lowest: Click==4.022 lowest: blinker==1.02324 release: blinker2526 devel: git+https://github.com/pallets/werkzeug.git27 devel: git+https://github.com/pallets/markupsafe.git28 devel: git+https://github.com/pallets/jinja.git29 devel: git+https://github.com/pallets/itsdangerous.git30 devel: git+https://github.com/pallets/click.git31 devel: git+https://github.com/jek/blinker.git3233 simplejson: simplejson3435[testenv:docs]36deps = sphinx
1 unmodified line