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
Provenance
- Commit
448368e- Tree
2c5f983- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
0b80acb
3 files changed+35 added−21 removed
modified:docs/cli.rst+4 added-4 removed
23 unmodified lines24 your Flask application's :attr:`Flask.cli` instance as well as some25 built-in commands that are always there. Flask extensions can also26 register more commands there if they desire so.27 28-For the :command:`flask` script to work, an application needs to be29-discovered. Flask looks for a module named wsgi.py or app.py by default, and30-if it finds one it assumes the application is defined in it.28+For the :command:`flask` script to work, an application needs to be discovered.29+Flask looks for a module named :file:`wsgi.py` or :file:`app.py` by default,30+and if it finds one it assumes the application is defined in it.31 32 You can instruct Flask to look for the application in a different module by33-exporting the ``FLASK_APP`` environment variable. It can be either set to an33+exporting the ``FLASK_APP`` environment variable. It can be either set to an34 import path or to a filename of a Python module that contains a Flask35 application.36 37 In that imported file the name of the app needs to be called ``app`` or270 unmodified linesmodified:flask/cli.py+21 added-9 removed
172 unmodified lines173 break174 175 if sys.path[0] != dirpath:176 sys.path.insert(0, dirpath)177+178 return '.'.join(module[::-1])179 180 181 def locate_app(script_info, app_id, raise_if_not_found=True):182 """Attempts to locate the application."""183 __traceback_hide__ = True184+185 if ':' in app_id:186 module, app_obj = app_id.split(':', 1)187 else:188 module = app_id5 unmodified lines194 # 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 return212 213 mod = sys.modules[module]214+215 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 lines341 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+ )348+349 if rv:350 break351+352 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+ )360 361 debug = get_debug_flag()362 363 if debug is not None:336 unmodified linesmodified:tests/test_cli.py+10 added-8 removed
179 unmodified lines180 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 None187 188 189 def test_find_default_import_path(test_apps, monkeypatch, tmpdir):190 """Test of find_default_import_path."""40 unmodified lines231 assert app.name == "createapp"232 assert obj.load_app() == app233 234 obj = ScriptInfo()234- pytest.raises(235- NoAppException, obj.load_app)235+ pytest.raises(NoAppException, obj.load_app)236 237 # 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'244 245 # 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