|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | from __future__ import absolute_import, print_function, unicode_literals
|
| 3 | +import sys |
| 4 | +import types |
3 | 5 |
|
4 | 6 |
|
5 |
| -if True: # skipping importanize, imports need to be in this order for py2 |
6 |
| - from .column import * # noqa |
7 |
| - from .model import * # noqa |
8 |
| - from .composite import * # noqa |
9 |
| - from .relations import * # noqa |
| 7 | +class lazy_module(types.ModuleType): |
| 8 | + def __init__(self, name, old_module, origins): |
| 9 | + super(lazy_module, self).__init__(name) |
| 10 | + self.origins = origins or {} |
| 11 | + self.__dict__.update( |
| 12 | + { |
| 13 | + "__file__": old_module.__file__, |
| 14 | + "__package__": old_module.__package__, |
| 15 | + "__path__": old_module.__path__, |
| 16 | + "__doc__": old_module.__doc__, |
| 17 | + } |
| 18 | + ) |
| 19 | + |
| 20 | + def __getattr__(self, name): |
| 21 | + if name in self.origins: |
| 22 | + module = __import__(self.__name__ + "." + self.origins[name], None, None, [name]) |
| 23 | + return getattr(module, name) |
| 24 | + return types.ModuleType.__getattribute__(self, name) |
| 25 | + |
| 26 | + |
| 27 | +old_module = sys.modules[__name__] |
| 28 | +sys.modules[__name__] = lazy_module( |
| 29 | + __name__, |
| 30 | + old_module, |
| 31 | + {"model_info": "model", "Identity": "model", "relation_info": "relations", "column_info": "column"}, |
| 32 | +) |
0 commit comments