Skip to content
Myr

edit some cli messages

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

dev server message doesn't show one of the lines in grey app.run message uses click.secho instead of warning

authored by David Lord · committed by David Lord · parent 97298e0 · Browse files · 3 files+17 added−29 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+17 added−29 removed

  • other:+17 added−29 removed

3 files+17 added−29 removed

modified:src/flask/app.py+12 added-4 removed
8 unmodified lines
9from itertools import chain10from threading import Lock11from types import TracebackType1213import click14from werkzeug.datastructures import Headers15from werkzeug.datastructures import ImmutableDict16from werkzeug.exceptions import Aborter17from werkzeug.exceptions import BadRequest
5 unmodified lines
23from werkzeug.routing import MapAdapter24from werkzeug.routing import RequestRedirect25from werkzeug.routing import RoutingException26from werkzeug.routing import Rule27from werkzeug.serving import is_running_from_reloader28from werkzeug.urls import url_quote29from werkzeug.utils import redirect as _wz_redirect30from werkzeug.wrappers import Response as BaseResponse31
877 unmodified lines
909 .. versionchanged:: 0.10910 The default port is now picked from the ``SERVER_NAME``911 variable.912 """911 # Change this into a no-op if the server is invoked from the912 # command line. Have a look at cli.py for more information.913 # Ignore this call so that it doesn't start another server if914 # the 'flask run' command is used.915 if os.environ.get("FLASK_RUN_FROM_CLI") == "true":914 from .debughelpers import explain_ignored_app_run916 if not is_running_from_reloader():917 click.secho(918 " * Ignoring a call to 'app.run()', the server is"919 " already being run with the 'flask run' command.\n"920 " Only call 'app.run()' in an 'if __name__ =="921 ' "__main__"\' guard.',922 fg="red",923 )924916 explain_ignored_app_run()925 return926927 if get_load_dotenv(load_dotenv):928 cli.load_dotenv()
1374 unmodified lines
modified:src/flask/cli.py+5 added-10 removed
9 unmodified lines
10from threading import Lock11from threading import Thread1213import click14from werkzeug.serving import is_running_from_reloader15from werkzeug.utils import import_string1617from .globals import current_app18from .helpers import get_debug_flag
254 unmodified lines
273 self._lock = Lock()274 self._bg_loading_exc = None275276 if use_eager_loading is None:276 use_eager_loading = os.environ.get("WERKZEUG_RUN_MAIN") != "true"277 use_eager_loading = not is_running_from_reloader()278279 if use_eager_loading:280 self._load_unlocked()281 else:
264 unmodified lines
546547 return sorted(rv)548549 def main(self, *args, **kwargs):549 # Set a global flag that indicates that we were invoked from the550 # command line interface. This is detected by Flask.run to make the551 # call into a no-op. This is necessary to avoid ugly errors when the552 # script that is loaded here also attempts to start a server.553 os.environ["FLASK_RUN_FROM_CLI"] = "true"554550 if get_load_dotenv(self.load_dotenv):551 load_dotenv()552553 obj = kwargs.get("obj")
77 unmodified lines
631def show_server_banner(env, debug, app_import_path, eager_loading):632 """Show extra startup messages the first time the server is run,633 ignoring the reloader.634 """640 if os.environ.get("WERKZEUG_RUN_MAIN") == "true":635 if is_running_from_reloader():636 return637638 if app_import_path is not None:639 message = f" * Serving Flask app {app_import_path!r}"
7 unmodified lines
647648 if env == "production":649 click.secho(650 " WARNING: This is a development server. Do not use it in"656 " a production deployment.",651 " a production deployment.\n Use a production WSGI server"652 " instead.",653 fg="red",654 )659 click.secho(" Use a production WSGI server instead.", dim=True)655656 if debug is not None:657 click.echo(f" * Debug mode: {'on' if debug else 'off'}")658
327 unmodified lines
modified:src/flask/debughelpers.py-15 removed
1import os1import typing as t3from warnings import warn23from .app import Flask4from .blueprints import Blueprint5from .globals import _request_ctx_stack
150 unmodified lines
156 info.append(" Maybe you did not place a template in the right folder?")157 info.append(" See https://flask.palletsprojects.com/blueprints/#templates")158159 app.logger.info("\n".join(info))162163164def explain_ignored_app_run() -> None:165 if os.environ.get("WERKZEUG_RUN_MAIN") != "true":166 warn(167 Warning(168 "Silently ignoring app.run() because the application is"169 " run from the flask command line executable. Consider"170 ' putting app.run() behind an if __name__ == "__main__"'171 " guard to silence this warning."172 ),173 stacklevel=3,174 )