Skip to content
Myr

Merge pull request #2591 from pallets/run-behavior

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

match run command behavior in app.run

authored by David Lord · committed by GitHub · parents 2433522, 3738f7f · Browse files · 2 files+58 added−39 removed
This commit

State

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

Diff stats

2 files+58 added−39 removed

  • other:+58 added−39 removed

2 files+58 added−39 removed

modified:flask/app.py+22 added-5 removed
862 unmodified lines
863 .. versionchanged:: 1.0864 If installed, python-dotenv will be used to load environment865 variables from :file:`.env` and :file:`.flaskenv` files.866867 .. versionchanged:: 0.10868 The default port is now picked from the ``SERVER_NAME`` variable.867 If set, the :envvar:`FLASK_ENV` and :envvar:`FLASK_DEBUG`868 environment variables will override :attr:`env` and869 :attr:`debug`.870871 Threaded mode is enabled by default.872873 .. versionchanged:: 0.10874 The default port is now picked from the ``SERVER_NAME``875 variable.876 """877 # Change this into a no-op if the server is invoked from the872 # command line. Have a look at cli.py for more information.878 # command line. Have a look at cli.py for more information.879 if os.environ.get('FLASK_RUN_FROM_CLI') == 'true':880 from .debughelpers import explain_ignored_app_run881 explain_ignored_app_run()882 return883884 if load_dotenv:879 from flask.cli import load_dotenv880 load_dotenv()885 cli.load_dotenv()886887 # if set, let env vars override previous values888 if 'FLASK_ENV' in os.environ:889 self.env = get_env()890 self.debug = get_debug_flag()891 elif 'FLASK_DEBUG' in os.environ:892 self.debug = get_debug_flag()893894 # debug passed to method overrides all other sources895 if debug is not None:896 self.debug = bool(debug)897898 _host = '127.0.0.1'
5 unmodified lines
904 sn_host, _, sn_port = server_name.partition(':')905906 host = host or sn_host or _host907 port = int(port or sn_port or _port)908909 options.setdefault('use_reloader', self.debug)910 options.setdefault('use_debugger', self.debug)911 options.setdefault('threaded', True)912913 cli.show_server_banner(self.env, self.debug, self.name)914915 from werkzeug.serving import run_simple916917 try:918 run_simple(host, port, self, **options)
1291 unmodified lines
modified:flask/cli.py+36 added-34 removed
575 unmodified lines
576577 return new_dir is not None # at least one file was located and loaded578579580def show_server_banner(env, debug, app_import_path):581 """Show extra startup messages the first time the server is run,582 ignoring the reloader.583 """584 if os.environ.get('WERKZEUG_RUN_MAIN') == 'true':585 return586587 if app_import_path is not None:588 print(' * Serving Flask app "{0}"'.format(app_import_path))589590 print(' * Environment: {0}'.format(env))591592 if env == 'production':593 click.secho(594 ' WARNING: Do not use the development server in a production'595 ' environment.', fg='red')596 click.secho(' Use a production WSGI server instead.', dim=True)597598 if debug is not None:599 print(' * Debug mode: {0}'.format('on' if debug else 'off'))600601602@click.command('run', short_help='Runs a development server.')603@click.option('--host', '-h', default='127.0.0.1',604 help='The interface to bind to.')605@click.option('--port', '-p', default=5000,
11 unmodified lines
617 help='Enable or disable multithreading.')618@pass_script_info619def run_command(info, host, port, reload, debugger, eager_loading,620 with_threads):599 """Runs a local development server for the Flask application.621 """Run a local development server.622601 This local server is recommended for development purposes only but it602 can also be used for simple intranet deployments. By default it will603 not support any sort of concurrency at all to simplify debugging. This604 can be changed with the --with-threads option which will enable basic605 multithreading.623 This server is for development purposes only. It does not provide624 the stability, security, or performance of production WSGI servers.625607 The reloader and debugger are by default enabled if the debug flag of608 Flask is enabled and disabled otherwise.626 The reloader and debugger are enabled by default if627 FLASK_ENV=development or FLASK_DEBUG=1.628 """610 from werkzeug.serving import run_simple611612 if get_env() == 'production':613 click.secho('Warning: Detected a production environment. Do not '614 'use `flask run` for production use.',615 fg='red')616 click.secho('Use a production ready WSGI server instead',617 dim=True)618629 debug = get_debug_flag()630631 if reload is None:621 reload = bool(debug)632 reload = debug633634 if debugger is None:623 debugger = bool(debug)635 debugger = debug636637 if eager_loading is None:638 eager_loading = not reload639640 show_server_banner(get_env(), debug, info.app_import_path)641 app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)642629 # Extra startup messages. This depends a bit on Werkzeug internals to630 # not double execute when the reloader kicks in.631 if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':632 # If we have an import path we can print it out now which can help633 # people understand what's being served. If we do not have an634 # import path because the app was loaded through a callback then635 # we won't print anything.636 if info.app_import_path is not None:637 print(' * Serving Flask app "%s"' % info.app_import_path)638 print(' * Env %s' % get_env())639 if debug is not None:640 print(' * Forcing debug mode %s' % (debug and 'on' or 'off'))643 from werkzeug.serving import run_simple644 run_simple(host, port, app, use_reloader=reload, use_debugger=debugger,645 threaded=with_threads)646642 run_simple(host, port, app, use_reloader=reload,643 use_debugger=debugger, threaded=with_threads)647645648@click.command('shell', short_help='Runs a shell in the app context.')649@with_appcontext650def shell_command():651 """Runs an interactive Python shell in the context of a given
117 unmodified lines