Python pyclbr.readmodule() Examples
The following are 5
code examples of pyclbr.readmodule().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyclbr
, or try the search function
.
Example #1
Source File: __init__.py From OnToology with Apache License 2.0 | 6 votes |
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
Example #2
Source File: browseProjects.py From ironpython2 with Apache License 2.0 | 5 votes |
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))
Example #3
Source File: ModuleBrowser.py From ironpython2 with Apache License 2.0 | 5 votes |
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))
Example #4
Source File: utils.py From fastapi_contrib with MIT License | 5 votes |
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))
Example #5
Source File: storage.py From mlcomp with Apache License 2.0 | 4 votes |
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