Deprecate flask.ext
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Add deprecation warning to ext pkg * Add docs on deprecation of flask.ext * Improve deprecation warnings * Add headers for better distinction, fix ordering issue of paragraphs
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent cc536c8 · Browse files · 4 files·+65 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+65 added−22 removed
- other:+65 added−22 removed
Provenance
- Commit
d3d8a46- Tree
1e59a82- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent
cc536c8
4 files changed+65 added−22 removed
modified:docs/extensiondev.rst+12 added-14 removed
358 unmodified lines359 extension author would like to move beyond the project, the project should360 find a new maintainer including full source hosting transition and PyPI361 access. If no maintainer is available, give access to the Flask core team.362 1. An approved Flask extension must provide exactly one package or module363- named ``flask_extensionname``. They might also reside inside a364- ``flaskext`` namespace packages though this is discouraged now.363+ named ``flask_extensionname``.364 2. It must ship a testing suite that can either be invoked with ``make test``365 or ``python setup.py test``. For test suites invoked with ``make366 test`` the extension has to ensure that all dependencies for the test367 are installed automatically. If tests are invoked with ``python setup.py29 unmodified lines397 398 Extension Import Transition399 ---------------------------400 402-For a while we recommended using namespace packages for Flask extensions.403-This turned out to be problematic in practice because many different404-competing namespace package systems exist and pip would automatically405-switch between different systems and this caused a lot of problems for406-users.401+In early versions of Flask we recommended using namespace packages for Flask402+extensions, of the form ``flaskext.foo``. This turned out to be problematic in403+practice because it meant that multiple ``flaskext`` packages coexist.404+Consequently we have recommended to name extensions ``flask_foo`` over405+``flaskext.foo`` for a long time.406 408-Instead we now recommend naming packages ``flask_foo`` instead of the now409-deprecated ``flaskext.foo``. Flask 0.8 introduces a redirect import410-system that lets uses import from ``flask.ext.foo`` and it will try411-``flask_foo`` first and if that fails ``flaskext.foo``.407+Flask 0.8 introduced a redirect import system as a compatibility aid for app408+developers: Importing ``flask.ext.foo`` would try ``flask_foo`` and409+``flaskext.foo`` in that order.410 413-Flask extensions should urge users to import from ``flask.ext.foo``414-instead of ``flask_foo`` or ``flaskext_foo`` so that extensions can415-transition to the new package name without affecting users.411+As of Flask 1.0, most Flask extensions have transitioned to the new naming412+schema. The ``flask.ext.foo`` compatibility alias is still in Flask 1.0 but is413+now deprecated -- you should use ``flask_foo``.414 415 416 .. _OAuth extension: http://pythonhosted.org/Flask-OAuth/417 .. _mailinglist: http://flask.pocoo.org/mailinglist/1 unmodified linemodified:docs/extensions.rst+4 added-3 removed
16 unmodified lines17 18 Extensions typically have documentation that goes along that shows how to19 use it. There are no general rules in how extensions are supposed to20 behave but they are imported from common locations. If you have an21-extension called ``Flask-Foo`` or ``Foo-Flask`` it will be always22-importable from ``flask.ext.foo``::21+extension called ``Flask-Foo`` or ``Foo-Flask`` it should be always22+importable from ``flask_foo``::23 24- from flask.ext import foo24+ import flask_foo25 26 Flask Before 0.827 ----------------28 14 unmodified lines43 44 Once the ``flaskext_compat`` module is activated the :data:`flask.ext` will45 exist and you can start importing from there.46 47+48 .. _Flask Extension Registry: http://flask.pocoo.org/extensions/49 .. _flaskext_compat.py: https://raw.githubusercontent.com/mitsuhiko/flask/master/scripts/flaskext_compat.pymodified:docs/upgrading.rst+25 added-4 removed
22 unmodified lines23 24 Version 1.025 -----------26 27+Debugging28++++++++++29+30 Flask 1.0 removed the ``debug_log_format`` attribute from Flask31 applications. Instead the new ``LOGGER_HANDLER_POLICY`` configuration can32 be used to disable the default log handlers and custom log handlers can be33 set up.34 35+Error handling36+++++++++++++++37+38 The behavior of error handlers was changed.39 The precedence of handlers used to be based on the decoration/call order of40 :meth:`~flask.Flask.errorhandler` and41 :meth:`~flask.Flask.register_error_handler`, respectively.42 Now the inheritance hierarchy takes precedence and handlers for more43 specific exception classes are executed instead of more general ones.44 See :ref:`error-handlers` for specifics.45 40-The :func:`~flask.templating.render_template_string` function has changed to41-autoescape template variables by default. This better matches the behavior42-of :func:`~flask.templating.render_template`.46+Trying to register a handler on an instance now raises :exc:`ValueError`.47 48 .. note::49 50 There used to be a logic error allowing you to register handlers51 only for exception *instances*. This was unintended and plain wrong,52 and therefore was replaced with the intended behavior of registering53 handlers only using exception classes and HTTP error codes.54+55+Templating56+++++++++++57+58+The :func:`~flask.templating.render_template_string` function has changed to59+autoescape template variables by default. This better matches the behavior60+of :func:`~flask.templating.render_template`.61 51- Trying to register a handler on an instance now raises :exc:`ValueError`.62+Extension imports63++++++++++++++++++64 65+Extension imports of the form ``flask.ext.foo`` are deprecated, you should use66+``flask_foo``.67+68+The old form still works, but Flask will issue a69+``flask.exthook.ExtDeprecationWarning`` for each extension you import the old70+way. We also provide a migration utility called `flask-ext-migrate71+<https://github.com/pocoo/flask-ext-migrate>`_ that is supposed to72+automatically rewrite your imports for this.73+74 .. _upgrading-to-010:75 76 Version 0.1077 ------------347 unmodified linesmodified:flask/exthook.py+24 added-1 removed
19 unmodified lines20 :license: BSD, see LICENSE for more details.21 """22 import sys23 import os24+import warnings25 from ._compat import reraise26 27 28+class ExtDeprecationWarning(DeprecationWarning):29+ pass30+31+warnings.simplefilter('always', ExtDeprecationWarning)32+33+34 class ExtensionImporter(object):35 """This importer redirects imports from this submodule to other locations.36 This makes it possible to transition from the old flaskext.name to the37 newer flask_name without people having a hard time.17 unmodified lines55 def install(self):56 sys.meta_path[:] = [x for x in sys.meta_path if self != x] + [self]57 58 def find_module(self, fullname, path=None):52- if fullname.startswith(self.prefix):59+ if fullname.startswith(self.prefix) and \60+ fullname != 'flask.ext.ExtDeprecationWarning':61 return self62 63 def load_module(self, fullname):64 if fullname in sys.modules:65 return sys.modules[fullname]66+67 modname = fullname.split('.', self.prefix_cutoff)[self.prefix_cutoff]68+69+ warnings.warn(70+ "Importing flask.ext.{x} is deprecated, use flask_{x} instead."71+ .format(x=modname), ExtDeprecationWarning72+ )73+74 for path in self.module_choices:75 realname = path % modname76 try:77 __import__(realname)19 unmodified lines97 continue98 module = sys.modules[fullname] = sys.modules[realname]99 if '.' not in modname:100 setattr(sys.modules[self.wrapper_module], modname, module)101+102+ if realname.startswith('flaskext.'):103+ warnings.warn(104+ "Detected extension named flaskext.{x}, please rename it "105+ "to flask_{x}. The old form is deprecated."106+ .format(x=modname), ExtDeprecationWarning107+ )108+109 return module110 raise ImportError('No module named %s' % fullname)111 112 def is_important_traceback(self, important_module, tb):31 unmodified lines