當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。