当前位置: 首页>>代码示例>>Python>>正文


Python pyclbr.readmodule方法代码示例

本文整理汇总了Python中pyclbr.readmodule方法的典型用法代码示例。如果您正苦于以下问题:Python pyclbr.readmodule方法的具体用法?Python pyclbr.readmodule怎么用?Python pyclbr.readmodule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyclbr的用法示例。


在下文中一共展示了pyclbr.readmodule方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clearing_db_connection

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import readmodule [as 别名]
def clearing_db_connection(cls):
        """
        Only used by me
        :return:
        """
        # disconnect the connection with the db
        connection.disconnect()
        # remove the connection details
        connection._dbs = {}
        connection._connections = {}
        connection._connection_settings = {}
        # getting call classes defined in models.py
        models = pyclbr.readmodule("OnToology.models").keys()
        for class_model in models:
            # delete the collection to prevent automatically connecting with the old db (the live one)
            del globals()[class_model]._collection 
开发者ID:OnToology,项目名称:OnToology,代码行数:18,代码来源:__init__.py

示例2: GetSubList

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import readmodule [as 别名]
def GetSubList(self):
		mod, path = pywin.framework.scriptutils.GetPackageModuleName(self.path)
		win32ui.SetStatusText("Building class list - please wait...", 1)
		win32ui.DoWaitCursor(1)
		try:
			try:
				reader = pyclbr.readmodule_ex # Post 1.5.2 interface.
				extra_msg = " or functions"
			except AttributeError:
				reader = pyclbr.readmodule
				extra_msg = ""
			data = reader(mod, [path])
			if data:
				ret = []
				for item in data.itervalues():
					if item.__class__ != pyclbr.Class: # ie, it is a pyclbr Function instance (only introduced post 1.5.2)
						ret.append(HLICLBRFunction( item, " (function)" ) )
					else:
						ret.append(HLICLBRClass( item, " (class)") )
				ret.sort()
				return ret
			else:
				return [HLIErrorItem("No Python classes%s in module." % (extra_msg,))]
		finally:
			win32ui.DoWaitCursor(0)
			win32ui.SetStatusText(win32ui.LoadString(afxres.AFX_IDS_IDLEMESSAGE)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,代码来源:browseProjects.py

示例3: _MakeRoot

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import readmodule [as 别名]
def _MakeRoot(self):
        path = self.GetDocument().GetPathName()
        if not path:
            return HierListCLBRErrorRoot("Error: Can not browse a file until it is saved")
        else:
            mod, path = pywin.framework.scriptutils.GetPackageModuleName(path)
            if self.bDirty:
                what = "Refreshing"
                # Hack for pyclbr being too smart
                try:
                    del pyclbr._modules[mod]
                except (KeyError, AttributeError):
                    pass
            else:
                what = "Building"
            win32ui.SetStatusText("%s class list - please wait..." % (what,), 1)
            win32ui.DoWaitCursor(1)
            try:
                reader = pyclbr.readmodule_ex # new version post 1.5.2
            except AttributeError:
                reader = pyclbr.readmodule
            try:
                data = reader(mod, [path])
                if data:
                    return HierListCLBRModule(mod, data)
                else:
                    return HierListCLBRErrorRoot("No Python classes in module.")

            finally:
                win32ui.DoWaitCursor(0)
                win32ui.SetStatusText(win32ui.LoadString(afxres.AFX_IDS_IDLEMESSAGE)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:ModuleBrowser.py

示例4: get_models

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import readmodule [as 别名]
def get_models() -> list:
    """
    Scans `settings.apps_folder_name`.
    Find `models` modules in each of them and get all attributes there.
    Last step is to filter attributes to return only those,
    subclassed from MongoDBModel (or timestamped version).

    Used internally only by `create_indexes` function.

    :return: list of user-defined models (subclassed from MongoDBModel) in apps
    """
    from fastapi_contrib.db.models import MongoDBModel

    apps_folder_name = settings.apps_folder_name
    models = []
    for app in settings.apps:
        app_path = f"{apps_folder_name}/{app}"
        modules = [f[1] for f in pkgutil.walk_packages(path=[app_path])]
        if "models" in modules:
            path_to_models = f"{apps_folder_name}.{app}.models"
            try:
                module_models = pyclbr.readmodule(path_to_models).keys()
            except (AttributeError, ImportError):
                logger.warning(
                    f"Unable to read module attributes in {path_to_models}"
                )
                continue
            mudule = importlib.import_module(
                f"{apps_folder_name}.{app}.models"
            )
            models.extend([getattr(mudule, model) for model in module_models])

    return list(filter(lambda x: issubclass(x, MongoDBModel), models)) 
开发者ID:identixone,项目名称:fastapi_contrib,代码行数:35,代码来源:utils.py

示例5: import_executor

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import readmodule [as 别名]
def import_executor(
            self,
            folder: str,
            base_folder: str,
            executor: str,
            libraries: List[Tuple] = None
    ):

        sys.path.insert(0, base_folder)

        spec = self._build_spec(folder)
        was_installation = False

        folders = [
            p for p in glob(f'{folder}/*', recursive=True)
            if os.path.isdir(p) and not spec.match_file(p)
        ]
        folders += [folder]
        library_names = set(n for n, v in (libraries or []))
        library_versions = {n: v for n, v in (libraries or [])}

        for n in library_names:
            try:
                version = pkg_resources.get_distribution(n).version
                need_install = library_versions[n] != version
            except Exception:
                need_install = True

            if INSTALL_DEPENDENCIES and need_install:
                os.system(f'pip install {n}=={library_versions[n]}')
                was_installation = True

        def is_valid_class(cls: pyclbr.Class):
            return cls.name == executor or \
                   cls.name.lower() == executor or \
                   to_snake(cls.name) == executor

        def relative_name(path: str):
            rel = os.path.relpath(path, base_folder)
            parts = [str(p).split('.')[0] for p in rel.split(os.sep)]
            return '.'.join(parts)

        for (module_loader, module_name,
             ispkg) in pkgutil.iter_modules(folders):
            module = module_loader.find_module(module_name)
            rel_path = os.path.relpath(
                os.path.splitext(module.path)[0], base_folder
            ).replace('/', '.')
            try:
                classes = pyclbr.readmodule(rel_path, path=[base_folder])
            except Exception:
                continue
            for k, v in classes.items():
                if is_valid_class(v):
                    importlib.import_module(relative_name(module.path))
                    return True, was_installation

        return False, was_installation 
开发者ID:lightforever,项目名称:mlcomp,代码行数:60,代码来源:storage.py


注:本文中的pyclbr.readmodule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。