Skip to content
Myr

style cleanup

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

[ci skip]

authored by David Lord · committed by David Lord · parent 0b80acb · Browse files · 3 files+35 added−21 removed
This commit

State

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

Diff stats

3 files+35 added−21 removed

  • tests:+10 added−8 removed
  • other:+25 added−13 removed

3 files+35 added−21 removed

modified:docs/cli.rst+4 added-4 removed
23 unmodified lines
24your Flask application's :attr:`Flask.cli` instance as well as some25built-in commands that are always there. Flask extensions can also26register more commands there if they desire so.2728For the :command:`flask` script to work, an application needs to be29discovered. Flask looks for a module named wsgi.py or app.py by default, and30if it finds one it assumes the application is defined in it.28For the :command:`flask` script to work, an application needs to be discovered.29Flask looks for a module named :file:`wsgi.py` or :file:`app.py` by default,30and if it finds one it assumes the application is defined in it.3132You can instruct Flask to look for the application in a different module by33exporting the ``FLASK_APP`` environment variable. It can be either set to an33exporting the ``FLASK_APP`` environment variable. It can be either set to an34import path or to a filename of a Python module that contains a Flask35application.3637In that imported file the name of the app needs to be called ``app`` or
270 unmodified lines
modified:flask/cli.py+21 added-9 removed
172 unmodified lines
173 break174175 if sys.path[0] != dirpath:176 sys.path.insert(0, dirpath)177178 return '.'.join(module[::-1])179180181def locate_app(script_info, app_id, raise_if_not_found=True):182 """Attempts to locate the application."""183 __traceback_hide__ = True184185 if ':' in app_id:186 module, app_obj = app_id.split(':', 1)187 else:188 module = app_id
5 unmodified lines
194 # Reraise the ImportError if it occurred within the imported module.195 # Determine this by checking whether the trace has a depth > 1.196 if sys.exc_info()[-1].tb_next:197 stack_trace = traceback.format_exc()196 raise NoAppException('There was an error trying to import'197 ' the app (%s):\n%s' % (module, stack_trace))198 raise NoAppException(199 'There was an error trying to import the app ({module}):\n'200 '{stack_trace}'.format(201 module=module, stack_trace=stack_trace202 )203 )204 elif raise_if_not_found:199 raise NoAppException('The file/path provided (%s) does not appear'200 ' to exist. Please verify the path is '201 'correct. If app is not on PYTHONPATH, '202 'ensure the extension is .py' % module)205 raise NoAppException(206 'The file/path provided (%s) does not appear to exist. Please'207 ' verify the path is correct. If app is not on PYTHONPATH,'208 ' ensure the extension is .py.'.format(module=module)209 )210 else:211 return212213 mod = sys.modules[module]214215 if app_obj is None:216 return find_best_app(script_info, mod)217 else:218 return find_app_by_string(app_obj, script_info, mod)
122 unmodified lines
341 rv = locate_app(self, self.app_import_path)342 else:343 for module in ['wsgi.py', 'app.py']:344 import_path = prepare_exec_for_file(module)337 rv = locate_app(self, import_path,338 raise_if_not_found=False)345 rv = locate_app(346 self, import_path, raise_if_not_found=False347 )348349 if rv:350 break351352 if not rv:353 raise NoAppException(354 'Could not locate Flask application. You did not provide '355 'the FLASK_APP environment variable, and a wsgi.py or '356 'app.py module was not found in the current directory.\n\n'357 'For more information see '347 'http://flask.pocoo.org/docs/latest/quickstart/')358 'http://flask.pocoo.org/docs/latest/quickstart/'359 )360361 debug = get_debug_flag()362363 if debug is not None:
336 unmodified lines
modified:tests/test_cli.py+10 added-8 removed
179 unmodified lines
180 NoAppException, locate_app,181 script_info, "cliapp.factory:create_app ()")182 pytest.raises(183 NoAppException, locate_app, script_info, "cliapp.importerrorapp")184 assert locate_app(script_info, "notanpp.py",185 raise_if_not_found=False) is None184 assert locate_app(185 script_info, "notanpp.py", raise_if_not_found=False186 ) is None187188189def test_find_default_import_path(test_apps, monkeypatch, tmpdir):190 """Test of find_default_import_path."""
40 unmodified lines
231 assert app.name == "createapp"232 assert obj.load_app() == app233234 obj = ScriptInfo()234 pytest.raises(235 NoAppException, obj.load_app)235 pytest.raises(NoAppException, obj.load_app)236237 # import app from wsgi.py in current directory238 monkeypatch.chdir(os.path.abspath(239 os.path.join(os.path.dirname(__file__), 'test_apps', 'helloworld')))238 monkeypatch.chdir(os.path.abspath(os.path.join(239 os.path.dirname(__file__), 'test_apps', 'helloworld'240 )))241 obj = ScriptInfo()242 app = obj.load_app()243 assert app.name == 'hello'244245 # import app from app.py in current directory245 monkeypatch.chdir(os.path.abspath(246 os.path.join(os.path.dirname(__file__), 'test_apps', 'cliapp')))246 monkeypatch.chdir(os.path.abspath(os.path.join(247 os.path.dirname(__file__), 'test_apps', 'cliapp'248 )))249 obj = ScriptInfo()250 app = obj.load_app()251 assert app.name == 'testapp'252
138 unmodified lines