Skip to content
Myr

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

4 files+65 added−22 removed

modified:docs/extensiondev.rst+12 added-14 removed
358 unmodified lines
359 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.3621. 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``.3642. 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.py
29 unmodified lines
397398Extension Import Transition399---------------------------400402For a while we recommended using namespace packages for Flask extensions.403This turned out to be problematic in practice because many different404competing namespace package systems exist and pip would automatically405switch between different systems and this caused a lot of problems for406users.401In early versions of Flask we recommended using namespace packages for Flask402extensions, of the form ``flaskext.foo``. This turned out to be problematic in403practice because it meant that multiple ``flaskext`` packages coexist.404Consequently we have recommended to name extensions ``flask_foo`` over405``flaskext.foo`` for a long time.406408Instead we now recommend naming packages ``flask_foo`` instead of the now409deprecated ``flaskext.foo``. Flask 0.8 introduces a redirect import410system that lets uses import from ``flask.ext.foo`` and it will try411``flask_foo`` first and if that fails ``flaskext.foo``.407Flask 0.8 introduced a redirect import system as a compatibility aid for app408developers: Importing ``flask.ext.foo`` would try ``flask_foo`` and409``flaskext.foo`` in that order.410413Flask extensions should urge users to import from ``flask.ext.foo``414instead of ``flask_foo`` or ``flaskext_foo`` so that extensions can415transition to the new package name without affecting users.411As of Flask 1.0, most Flask extensions have transitioned to the new naming412schema. The ``flask.ext.foo`` compatibility alias is still in Flask 1.0 but is413now deprecated -- you should use ``flask_foo``.414415416.. _OAuth extension: http://pythonhosted.org/Flask-OAuth/417.. _mailinglist: http://flask.pocoo.org/mailinglist/
1 unmodified line
modified:docs/extensions.rst+4 added-3 removed
16 unmodified lines
1718Extensions typically have documentation that goes along that shows how to19use it. There are no general rules in how extensions are supposed to20behave but they are imported from common locations. If you have an21extension called ``Flask-Foo`` or ``Foo-Flask`` it will be always22importable from ``flask.ext.foo``::21extension called ``Flask-Foo`` or ``Foo-Flask`` it should be always22importable from ``flask_foo``::2324 from flask.ext import foo24 import flask_foo2526Flask Before 0.827----------------28
14 unmodified lines
4344Once the ``flaskext_compat`` module is activated the :data:`flask.ext` will45exist and you can start importing from there.464748.. _Flask Extension Registry: http://flask.pocoo.org/extensions/49.. _flaskext_compat.py: https://raw.githubusercontent.com/mitsuhiko/flask/master/scripts/flaskext_compat.py
modified:docs/upgrading.rst+25 added-4 removed
22 unmodified lines
2324Version 1.025-----------2627Debugging28+++++++++2930Flask 1.0 removed the ``debug_log_format`` attribute from Flask31applications. Instead the new ``LOGGER_HANDLER_POLICY`` configuration can32be used to disable the default log handlers and custom log handlers can be33set up.3435Error handling36++++++++++++++3738The behavior of error handlers was changed.39The 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.42Now the inheritance hierarchy takes precedence and handlers for more43specific exception classes are executed instead of more general ones.44See :ref:`error-handlers` for specifics.4540The :func:`~flask.templating.render_template_string` function has changed to41autoescape template variables by default. This better matches the behavior42of :func:`~flask.templating.render_template`.46Trying to register a handler on an instance now raises :exc:`ValueError`.4748.. note::4950 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.5455Templating56++++++++++5758The :func:`~flask.templating.render_template_string` function has changed to59autoescape template variables by default. This better matches the behavior60of :func:`~flask.templating.render_template`.61 51 Trying to register a handler on an instance now raises :exc:`ValueError`.62Extension imports63+++++++++++++++++6465Extension imports of the form ``flask.ext.foo`` are deprecated, you should use66``flask_foo``.6768The old form still works, but Flask will issue a69``flask.exthook.ExtDeprecationWarning`` for each extension you import the old70way. We also provide a migration utility called `flask-ext-migrate71<https://github.com/pocoo/flask-ext-migrate>`_ that is supposed to72automatically rewrite your imports for this.7374.. _upgrading-to-010:7576Version 0.1077------------
347 unmodified lines
modified:flask/exthook.py+24 added-1 removed
19 unmodified lines
20 :license: BSD, see LICENSE for more details.21"""22import sys23import os24import warnings25from ._compat import reraise262728class ExtDeprecationWarning(DeprecationWarning):29 pass3031warnings.simplefilter('always', ExtDeprecationWarning)323334class 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 lines
55 def install(self):56 sys.meta_path[:] = [x for x in sys.meta_path if self != x] + [self]5758 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 self6263 def load_module(self, fullname):64 if fullname in sys.modules:65 return sys.modules[fullname]6667 modname = fullname.split('.', self.prefix_cutoff)[self.prefix_cutoff]6869 warnings.warn(70 "Importing flask.ext.{x} is deprecated, use flask_{x} instead."71 .format(x=modname), ExtDeprecationWarning72 )7374 for path in self.module_choices:75 realname = path % modname76 try:77 __import__(realname)
19 unmodified lines
97 continue98 module = sys.modules[fullname] = sys.modules[realname]99 if '.' not in modname:100 setattr(sys.modules[self.wrapper_module], modname, module)101102 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 )108109 return module110 raise ImportError('No module named %s' % fullname)111112 def is_important_traceback(self, important_module, tb):
31 unmodified lines