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
Provenance
- Commit
4f03a76- Tree
b022042- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
97298e0
3 files changed+17 added−29 removed
modified:src/flask/app.py+12 added-4 removed
8 unmodified lines9 from itertools import chain10 from threading import Lock11 from types import TracebackType12 13+import click14 from werkzeug.datastructures import Headers15 from werkzeug.datastructures import ImmutableDict16 from werkzeug.exceptions import Aborter17 from werkzeug.exceptions import BadRequest5 unmodified lines23 from werkzeug.routing import MapAdapter24 from werkzeug.routing import RequestRedirect25 from werkzeug.routing import RoutingException26 from werkzeug.routing import Rule27+from werkzeug.serving import is_running_from_reloader28 from werkzeug.urls import url_quote29 from werkzeug.utils import redirect as _wz_redirect30 from werkzeug.wrappers import Response as BaseResponse31 877 unmodified lines909 .. 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+ )924 916- explain_ignored_app_run()925 return926 927 if get_load_dotenv(load_dotenv):928 cli.load_dotenv()1374 unmodified linesmodified:src/flask/cli.py+5 added-10 removed
9 unmodified lines10 from threading import Lock11 from threading import Thread12 13 import click14+from werkzeug.serving import is_running_from_reloader15 from werkzeug.utils import import_string16 17 from .globals import current_app18 from .helpers import get_debug_flag254 unmodified lines273 self._lock = Lock()274 self._bg_loading_exc = None275 276 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()278 279 if use_eager_loading:280 self._load_unlocked()281 else:264 unmodified lines546 547 return sorted(rv)548 549 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"554-550 if get_load_dotenv(self.load_dotenv):551 load_dotenv()552 553 obj = kwargs.get("obj")77 unmodified lines631 def 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 return637 638 if app_import_path is not None:639 message = f" * Serving Flask app {app_import_path!r}"7 unmodified lines647 648 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)655 656 if debug is not None:657 click.echo(f" * Debug mode: {'on' if debug else 'off'}")658 327 unmodified linesmodified:src/flask/debughelpers.py-15 removed
1-import os1 import typing as t3-from warnings import warn2 3 from .app import Flask4 from .blueprints import Blueprint5 from .globals import _request_ctx_stack150 unmodified lines156 info.append(" Maybe you did not place a template in the right folder?")157 info.append(" See https://flask.palletsprojects.com/blueprints/#templates")158 159 app.logger.info("\n".join(info))162-163-164-def 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- )