core.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Mocha 作者: mardix 项目源码 文件源码
def setup_installed_apps(cls):
        """
        To import 3rd party applications along with associated properties

        It is a list of dict or string.

        When a dict, it contains the `app` key and the configuration,
        if it's a string, it is just the app name

        If you require dependencies from other packages, dependencies
        must be placed before the calling package.

        It is required that __init__ in the package app has an entry point method
        -> 'main(**kw)' which will be used to setup the default app.

        As a dict
        INSTALLED_APPS = [
            "it.can.be.a.string.to.the.module",
            ("in.a.tuple.with.props.dict", {options}),
            [
                ("multi.app.list.in.a.list.of.tuple", {options}),
                ("multi.app.list.in.a.list.of.tuple2", {options})
            ]
        ]

        :return:
        """

        cls._installed_apps = cls._app.config.get("INSTALLED_APPS", [])
        if cls._installed_apps:
            def import_app(module, props={}):
                _ = werkzeug.import_string(module)
                setattr(_, "__options__", utils.dict_dot(props))

            for k in cls._installed_apps:
                if isinstance(k, six.string_types):  # One string
                    import_app(k, {})
                elif isinstance(k, tuple):
                    import_app(k[0], k[1])
                elif isinstance(k, list):  # list of tuple[(module props), ...]
                    for t in k:
                        import_app(t[0], t[1])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号