remove deprecated flask.ext
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 4c56477 · Browse files · 6 files·+4 added−495 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+4 added−495 removed
- tests:+0 added−197 removed
- other:+4 added−298 removed
Provenance
- Commit
715a9a3- Tree
ad7c211- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
4c56477
6 files changed+4 added−495 removed
deleted:flask/ext/__init__.py-29 removed
1-# -*- coding: utf-8 -*-2-"""3- flask.ext4- ~~~~~~~~~5-6- Redirect imports for extensions. This module basically makes it possible7- for us to transition from flaskext.foo to flask_foo without having to8- force all extensions to upgrade at the same time.9-10- When a user does ``from flask.ext.foo import bar`` it will attempt to11- import ``from flask_foo import bar`` first and when that fails it will12- try to import ``from flaskext.foo import bar``.13-14- We're switching from namespace packages because it was just too painful for15- everybody involved.16-17- :copyright: (c) 2015 by Armin Ronacher.18- :license: BSD, see LICENSE for more details.19-"""20-21-22-def setup():23- from ..exthook import ExtensionImporter24- importer = ExtensionImporter(['flask_%s', 'flaskext.%s'], __name__)25- importer.install()26-27-28-setup()29-del setupdeleted:flask/exthook.py-143 removed
1-# -*- coding: utf-8 -*-2-"""3- flask.exthook4- ~~~~~~~~~~~~~5-6- Redirect imports for extensions. This module basically makes it possible7- for us to transition from flaskext.foo to flask_foo without having to8- force all extensions to upgrade at the same time.9-10- When a user does ``from flask.ext.foo import bar`` it will attempt to11- import ``from flask_foo import bar`` first and when that fails it will12- try to import ``from flaskext.foo import bar``.13-14- We're switching from namespace packages because it was just too painful for15- everybody involved.16-17- This is used by `flask.ext`.18-19- :copyright: (c) 2015 by Armin Ronacher.20- :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.38- """39-40- def __init__(self, module_choices, wrapper_module):41- self.module_choices = module_choices42- self.wrapper_module = wrapper_module43- self.prefix = wrapper_module + '.'44- self.prefix_cutoff = wrapper_module.count('.') + 145-46- def __eq__(self, other):47- return self.__class__.__module__ == other.__class__.__module__ and \48- self.__class__.__name__ == other.__class__.__name__ and \49- self.wrapper_module == other.wrapper_module and \50- self.module_choices == other.module_choices51-52- def __ne__(self, other):53- return not self.__eq__(other)54-55- 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):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), ExtDeprecationWarning, stacklevel=272- )73-74- for path in self.module_choices:75- realname = path % modname76- try:77- __import__(realname)78- except ImportError:79- exc_type, exc_value, tb = sys.exc_info()80- # since we only establish the entry in sys.modules at the81- # very this seems to be redundant, but if recursive imports82- # happen we will call into the move import a second time.83- # On the second invocation we still don't have an entry for84- # fullname in sys.modules, but we will end up with the same85- # fake module name and that import will succeed since this86- # one already has a temporary entry in the modules dict.87- # Since this one "succeeded" temporarily that second88- # invocation now will have created a fullname entry in89- # sys.modules which we have to kill.90- sys.modules.pop(fullname, None)91-92- # If it's an important traceback we reraise it, otherwise93- # we swallow it and try the next choice. The skipped frame94- # is the one from __import__ above which we don't care about95- if self.is_important_traceback(realname, tb):96- reraise(exc_type, exc_value, tb.tb_next)97- 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):113- """Walks a traceback's frames and checks if any of the frames114- originated in the given important module. If that is the case then we115- were able to import the module itself but apparently something went116- wrong when the module was imported. (Eg: import of an import failed).117- """118- while tb is not None:119- if self.is_important_frame(important_module, tb):120- return True121- tb = tb.tb_next122- return False123-124- def is_important_frame(self, important_module, tb):125- """Checks a single frame if it's important."""126- g = tb.tb_frame.f_globals127- if '__name__' not in g:128- return False129-130- module_name = g['__name__']131-132- # Python 2.7 Behavior. Modules are cleaned up late so the133- # name shows up properly here. Success!134- if module_name == important_module:135- return True136-137- # Some python versions will clean up modules so early that the138- # module name at that point is no longer set. Try guessing from139- # the filename then.140- filename = os.path.abspath(tb.tb_frame.f_code.co_filename)141- test_string = os.path.sep + important_module.replace('.', os.path.sep)142- return test_string + '.py' in filename or \143- test_string + os.path.sep + '__init__.py' in filenamedeleted:scripts/flaskext_compat.py-125 removed
1-# -*- coding: utf-8 -*-2-"""3- flaskext_compat4- ~~~~~~~~~~~~~~~5-6- Implements the ``flask.ext`` virtual package for versions of Flask7- older than 0.7. This module is a noop if Flask 0.8 was detected.8-9- Usage::10-11- import flaskext_compat12- flaskext_compat.activate()13- from flask.ext import foo14-15- :copyright: (c) 2015 by Armin Ronacher.16- :license: BSD, see LICENSE for more details.17-"""18-import types19-import sys20-import os21-22-23-class ExtensionImporter(object):24- """This importer redirects imports from this submodule to other locations.25- This makes it possible to transition from the old flaskext.name to the26- newer flask_name without people having a hard time.27- """28-29- def __init__(self, module_choices, wrapper_module):30- self.module_choices = module_choices31- self.wrapper_module = wrapper_module32- self.prefix = wrapper_module + '.'33- self.prefix_cutoff = wrapper_module.count('.') + 134-35- def __eq__(self, other):36- return self.__class__.__module__ == other.__class__.__module__ and \37- self.__class__.__name__ == other.__class__.__name__ and \38- self.wrapper_module == other.wrapper_module and \39- self.module_choices == other.module_choices40-41- def __ne__(self, other):42- return not self.__eq__(other)43-44- def install(self):45- sys.meta_path[:] = [x for x in sys.meta_path if self != x] + [self]46-47- def find_module(self, fullname, path=None):48- if fullname.startswith(self.prefix):49- return self50-51- def load_module(self, fullname):52- if fullname in sys.modules:53- return sys.modules[fullname]54- modname = fullname.split('.', self.prefix_cutoff)[self.prefix_cutoff]55- for path in self.module_choices:56- realname = path % modname57- try:58- __import__(realname)59- except ImportError:60- exc_type, exc_value, tb = sys.exc_info()61- # since we only establish the entry in sys.modules at the62- # end this seems to be redundant, but if recursive imports63- # happen we will call into the move import a second time.64- # On the second invocation we still don't have an entry for65- # fullname in sys.modules, but we will end up with the same66- # fake module name and that import will succeed since this67- # one already has a temporary entry in the modules dict.68- # Since this one "succeeded" temporarily that second69- # invocation now will have created a fullname entry in70- # sys.modules which we have to kill.71- sys.modules.pop(fullname, None)72-73- # If it's an important traceback we reraise it, otherwise74- # we swallow it and try the next choice. The skipped frame75- # is the one from __import__ above which we don't care about.76- if self.is_important_traceback(realname, tb):77- raise exc_type, exc_value, tb.tb_next78- continue79- module = sys.modules[fullname] = sys.modules[realname]80- if '.' not in modname:81- setattr(sys.modules[self.wrapper_module], modname, module)82- return module83- raise ImportError('No module named %s' % fullname)84-85- def is_important_traceback(self, important_module, tb):86- """Walks a traceback's frames and checks if any of the frames87- originated in the given important module. If that is the case then we88- were able to import the module itself but apparently something went89- wrong when the module was imported. (Eg: import of an import failed).90- """91- while tb is not None:92- if self.is_important_frame(important_module, tb):93- return True94- tb = tb.tb_next95- return False96-97- def is_important_frame(self, important_module, tb):98- """Checks a single frame if it's important."""99- g = tb.tb_frame.f_globals100- if '__name__' not in g:101- return False102-103- module_name = g['__name__']104-105- # Python 2.7 Behavior. Modules are cleaned up late so the106- # name shows up properly here. Success!107- if module_name == important_module:108- return True109-110- # Some python versions will clean up modules so early that the111- # module name at that point is no longer set. Try guessing from112- # the filename then.113- filename = os.path.abspath(tb.tb_frame.f_code.co_filename)114- test_string = os.path.sep + important_module.replace('.', os.path.sep)115- return test_string + '.py' in filename or \116- test_string + os.path.sep + '__init__.py' in filename117-118-119-def activate():120- import flask121- ext_module = types.ModuleType('flask.ext')122- ext_module.__path__ = []123- flask.ext = sys.modules['flask.ext'] = ext_module124- importer = ExtensionImporter(['flask_%s', 'flaskext.%s'], 'flask.ext')125- importer.install()deleted:tests/test_ext.py-197 removed
1-# -*- coding: utf-8 -*-2-"""3- tests.ext4- ~~~~~~~~~~~~~~~~~~~5-6- Tests the extension import thing.7-8- :copyright: (c) 2015 by Armin Ronacher.9- :license: BSD, see LICENSE for more details.10-"""11-12-import sys13-import pytest14-15-try:16- from imp import reload as reload_module17-except ImportError:18- reload_module = reload19-20-from flask._compat import PY221-22-23-@pytest.fixture(autouse=True)24-def disable_extwarnings(recwarn):25- from flask.exthook import ExtDeprecationWarning26-27- yield28-29- assert set(w.category for w in recwarn.list) \30- <= set([ExtDeprecationWarning])31- recwarn.clear()32-33-34-@pytest.fixture(autouse=True)35-def importhook_setup(monkeypatch):36- # we clear this out for various reasons. The most important one is37- # that a real flaskext could be in there which would disable our38- # fake package. Secondly we want to make sure that the flaskext39- # import hook does not break on reloading.40- for entry, value in list(sys.modules.items()):41- if (42- entry.startswith('flask.ext.') or43- entry.startswith('flask_') or44- entry.startswith('flaskext.') or45- entry == 'flaskext'46- ) and value is not None:47- monkeypatch.delitem(sys.modules, entry)48- from flask import ext49- reload_module(ext)50-51- # reloading must not add more hooks52- import_hooks = 053- for item in sys.meta_path:54- cls = type(item)55- if cls.__module__ == 'flask.exthook' and \56- cls.__name__ == 'ExtensionImporter':57- import_hooks += 158- assert import_hooks == 159-60- yield61-62- from flask import ext63- for key in ext.__dict__:64- assert '.' not in key65-66-67-@pytest.fixture68-def newext_simple(modules_tmpdir):69- x = modules_tmpdir.join('flask_newext_simple.py')70- x.write('ext_id = "newext_simple"')71-72-73-@pytest.fixture74-def oldext_simple(modules_tmpdir):75- flaskext = modules_tmpdir.mkdir('flaskext')76- flaskext.join('__init__.py').write('\n')77- flaskext.join('oldext_simple.py').write('ext_id = "oldext_simple"')78-79-80-@pytest.fixture81-def newext_package(modules_tmpdir):82- pkg = modules_tmpdir.mkdir('flask_newext_package')83- pkg.join('__init__.py').write('ext_id = "newext_package"')84- pkg.join('submodule.py').write('def test_function():\n return 42\n')85-86-87-@pytest.fixture88-def oldext_package(modules_tmpdir):89- flaskext = modules_tmpdir.mkdir('flaskext')90- flaskext.join('__init__.py').write('\n')91- oldext = flaskext.mkdir('oldext_package')92- oldext.join('__init__.py').write('ext_id = "oldext_package"')93- oldext.join('submodule.py').write('def test_function():\n'94- ' return 42')95-96-97-@pytest.fixture98-def flaskext_broken(modules_tmpdir):99- ext = modules_tmpdir.mkdir('flask_broken')100- ext.join('b.py').write('\n')101- ext.join('__init__.py').write('import flask.ext.broken.b\n'102- 'import missing_module')103-104-105-def test_flaskext_new_simple_import_normal(newext_simple):106- from flask.ext.newext_simple import ext_id107- assert ext_id == 'newext_simple'108-109-110-def test_flaskext_new_simple_import_module(newext_simple):111- from flask.ext import newext_simple112- assert newext_simple.ext_id == 'newext_simple'113- assert newext_simple.__name__ == 'flask_newext_simple'114-115-116-def test_flaskext_new_package_import_normal(newext_package):117- from flask.ext.newext_package import ext_id118- assert ext_id == 'newext_package'119-120-121-def test_flaskext_new_package_import_module(newext_package):122- from flask.ext import newext_package123- assert newext_package.ext_id == 'newext_package'124- assert newext_package.__name__ == 'flask_newext_package'125-126-127-def test_flaskext_new_package_import_submodule_function(newext_package):128- from flask.ext.newext_package.submodule import test_function129- assert test_function() == 42130-131-132-def test_flaskext_new_package_import_submodule(newext_package):133- from flask.ext.newext_package import submodule134- assert submodule.__name__ == 'flask_newext_package.submodule'135- assert submodule.test_function() == 42136-137-138-def test_flaskext_old_simple_import_normal(oldext_simple):139- from flask.ext.oldext_simple import ext_id140- assert ext_id == 'oldext_simple'141-142-143-def test_flaskext_old_simple_import_module(oldext_simple):144- from flask.ext import oldext_simple145- assert oldext_simple.ext_id == 'oldext_simple'146- assert oldext_simple.__name__ == 'flaskext.oldext_simple'147-148-149-def test_flaskext_old_package_import_normal(oldext_package):150- from flask.ext.oldext_package import ext_id151- assert ext_id == 'oldext_package'152-153-154-def test_flaskext_old_package_import_module(oldext_package):155- from flask.ext import oldext_package156- assert oldext_package.ext_id == 'oldext_package'157- assert oldext_package.__name__ == 'flaskext.oldext_package'158-159-160-def test_flaskext_old_package_import_submodule(oldext_package):161- from flask.ext.oldext_package import submodule162- assert submodule.__name__ == 'flaskext.oldext_package.submodule'163- assert submodule.test_function() == 42164-165-166-def test_flaskext_old_package_import_submodule_function(oldext_package):167- from flask.ext.oldext_package.submodule import test_function168- assert test_function() == 42169-170-171-def test_flaskext_broken_package_no_module_caching(flaskext_broken):172- for x in range(2):173- with pytest.raises(ImportError):174- import flask.ext.broken175-176-177-def test_no_error_swallowing(flaskext_broken):178- with pytest.raises(ImportError) as excinfo:179- import flask.ext.broken180- # python3.6 raises a subclass of ImportError: 'ModuleNotFoundError'181- assert issubclass(excinfo.type, ImportError)182- if PY2:183- message = 'No module named missing_module'184- else:185- message = 'No module named \'missing_module\''186- assert str(excinfo.value) == message187- assert excinfo.tb.tb_frame.f_globals is globals()188-189- # reraise() adds a second frame so we need to skip that one too.190- # On PY3 we even have another one :(191- next = excinfo.tb.tb_next.tb_next192- if not PY2:193- next = next.tb_next194-195- import os.path196- assert os.path.join('flask_broken', '__init__.py') in \197- next.tb_frame.f_code.co_filenamemodified:CHANGES+3 added
82 unmodified lines83 - Template auto reloading will honor the ``run`` command's ``debug`` flag even84 if ``app.jinja_env`` was already accessed. (`#2373`_)85 - The following old deprecated code was removed. (`#2385`_)86 87+ - ``flask.ext`` - import extensions directly by their name instead of88+ through the ``flask.ext`` namespace. For example,89+ ``import flask.ext.sqlalchemy`` becomes ``import flask_sqlalchemy``.90 - ``Flask.init_jinja_globals`` - extend ``Flask.create_jinja_environment``91 instead.92 - ``Flask.error_handlers`` - tracked by ``Flask.error_handler_spec``,93 use ``@app.errorhandler`` to register handlers.651 unmodified linesmodified:setup.py+1 added-1 removed
62 unmodified lines63 author_email='armin.ronacher@active-4.com',64 description='A microframework based on Werkzeug, Jinja2 '65 'and good intentions',66 long_description=__doc__,67- packages=['flask', 'flask.ext', 'flask.json'],67+ packages=['flask', 'flask.json'],68 include_package_data=True,69 zip_safe=False,70 platforms='any',71 install_requires=[39 unmodified lines