Skip to content
Myr

reconfigure the app from run command and method

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

extract templates_auto_reload to property continues #1910 closes #1907

authored by David Lord · committed by David Lord · parent 9e39c50 · Browse files · 3 files+60 added−10 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+60 added−10 removed

  • other:+60 added−10 removed

3 files+60 added−10 removed

modified:flask/app.py+50 added-9 removed
701 unmodified lines
702 :param mode: resource file opening mode, default is 'rb'.703 """704 return open(os.path.join(self.instance_path, resource), mode)705706 def _get_templates_auto_reload(self):707 """Reload templates when they are changed. Used by708 :meth:`create_jinja_environment`.709710 This attribute can be configured with :data:`TEMPLATES_AUTO_RELOAD`. If711 not set, it will be enabled in debug mode.712713 .. versionadded:: 1.0714 This property was added but the underlying config and behavior715 already existed.716 """717 rv = self.config['TEMPLATES_AUTO_RELOAD']718 return rv if rv is not None else self.debug719720 def _set_templates_auto_reload(self, value):721 self.config['TEMPLATES_AUTO_RELOAD'] = value722723 templates_auto_reload = property(724 _get_templates_auto_reload, _set_templates_auto_reload725 )726 del _get_templates_auto_reload, _set_templates_auto_reload727728 def create_jinja_environment(self):729 """Creates the Jinja2 environment based on :attr:`jinja_options`730 and :meth:`select_jinja_autoescape`. Since 0.7 this also adds731 the Jinja2 globals and filters after initialization. Override
4 unmodified lines
736 ``Environment.auto_reload`` set in accordance with737 ``TEMPLATES_AUTO_RELOAD`` configuration option.738 """739 options = dict(self.jinja_options)740741 if 'autoescape' not in options:742 options['autoescape'] = self.select_jinja_autoescape743744 if 'auto_reload' not in options:721 if self.config['TEMPLATES_AUTO_RELOAD'] is not None:722 options['auto_reload'] = self.config['TEMPLATES_AUTO_RELOAD']723 else:724 options['auto_reload'] = self.debug745 options['auto_reload'] = self.templates_auto_reload746747 rv = self.jinja_environment(self, **options)748 rv.globals.update(749 url_for=url_for,750 get_flashed_messages=get_flashed_messages,
76 unmodified lines
827 for processor in self.shell_context_processors:828 rv.update(processor())829 return rv830831 def _reconfigure_for_run_debug(self, debug):832 """The ``run`` commands will set the application's debug flag. Some833 application configuration may already be calculated based on the834 previous debug value. This method will recalculate affected values.835836 Called by the :func:`flask.cli.run` command or :meth:`Flask.run`837 method if the debug flag is set explicitly in the call.838839 :param debug: the new value of the debug flag840841 .. versionadded:: 1.0842 Reconfigures ``app.jinja_env.auto_reload``.843 """844 self.debug = debug845 self.jinja_env.auto_reload = self.templates_auto_reload846847 def run(self, host=None, port=None, debug=None, **options):848 """Runs the application on a local development server.849850 Do not use ``run()`` in a production setting. It is not intended to
45 unmodified lines
896 from .debughelpers import explain_ignored_app_run897 explain_ignored_app_run()898 return899862 from werkzeug.serving import run_simple900 if debug is not None:901 self._reconfigure_for_run_debug(bool(debug))902903 _host = '127.0.0.1'904 _port = 5000905 server_name = self.config.get("SERVER_NAME")906 sn_host, sn_port = None, None907908 if server_name:909 sn_host, _, sn_port = server_name.partition(':')910911 host = host or sn_host or _host912 port = int(port or sn_port or _port)871 if debug is not None:872 self.debug = bool(debug)913 options.setdefault('use_reloader', self.debug)914 options.setdefault('use_debugger', self.debug)875 if debug:876 self.jinja_env.auto_reload = True915916 from werkzeug.serving import run_simple917918 try:919 run_simple(host, port, self, **options)920 finally:921 # reset the first request information if the development server
1286 unmodified lines
modified:flask/cli.py+7 added-1 removed
317 unmodified lines
318 this multiple times will just result in the already loaded app to319 be returned.320 """321 __traceback_hide__ = True322323 if self._loaded_app is not None:324 return self._loaded_app325326 if self.create_app is not None:327 rv = call_factory(self.create_app, self)328 else:329 if not self.app_import_path:
1 unmodified line
331 'Could not locate Flask application. You did not provide '332 'the FLASK_APP environment variable.\n\nFor more '333 'information see '334 'http://flask.pocoo.org/docs/latest/quickstart/')335336 rv = locate_app(self, self.app_import_path)337338 debug = get_debug_flag()339340 if debug is not None:336 rv.debug = debug341 rv._reconfigure_for_run_debug(debug)342343 self._loaded_app = rv344 return rv345346
330 unmodified lines
modified:CHANGES+3 added
77 unmodified lines
78 the response to make testing JSON response much easier. (`#2358`_)79- Removed error handler caching because it caused unexpected results for some80 exception inheritance hierarchies. Register handlers explicitly for each81 exception if you don't want to traverse the MRO. (`#2362`_)82- Template auto reloading will honor the ``run`` command's ``debug`` flag even83 if ``app.jinja_env`` was already accessed. (`#2373`_)8485.. _#1489: https://github.com/pallets/flask/pull/148986.. _#1621: https://github.com/pallets/flask/pull/162187.. _#1898: https://github.com/pallets/flask/pull/1898
15 unmodified lines
103.. _#2352: https://github.com/pallets/flask/pull/2352104.. _#2354: https://github.com/pallets/flask/pull/2354105.. _#2358: https://github.com/pallets/flask/pull/2358106.. _#2362: https://github.com/pallets/flask/pull/2362107.. _#2373: https://github.com/pallets/flask/pull/2373108109Version 0.12.2110--------------111
617 unmodified lines