def get_class(connector_module: Optional[ModuleType]) -> Optional[Type]: if not connector_module: # pragma: no cover return False classes = Meta.get_new_classes_from_module(connector_module) for connector_class in classes.values(): if issubclass(connector_class, Connector): return connector_class return None # pragma: no cover
def extract_endpoints(self, base_dir: Path) -> List[Type[EndpointResource]]: endpoints_classes: List[Type[EndpointResource]] = [] # get last item of the path # normpath is required to strip final / if any base_module = base_dir.name apis_dir = base_dir.joinpath("endpoints") apiclass_module = f"{base_module}.endpoints" for epfile in apis_dir.glob("*.py"): # get module name (es: endpoints.filename) module_name = f"{apiclass_module}.{epfile.stem}" # Convert module name into a module log.debug("Importing {}", module_name) module = Meta.get_module_from_string( module_name, exit_on_fail=True, ) # Extract classes from the module # module can't be none because of exit_on_fail=True... # but my-py can't understand this classes = Meta.get_new_classes_from_module(module) # type: ignore for class_name, epclss in classes.items(): # Filtering out classes without expected data if ( not hasattr(epclss, "methods") or epclss.methods is None ): # pragma: no cover continue log.debug("Importing {} from {}", class_name, module_name) skip, dependency = self.skip_endpoint(epclss.depends_on) if skip: log.debug( "Skipping '{} {}' due to unmet dependency: {}", module_name, class_name, dependency, ) continue endpoints_classes.append(epclss) return endpoints_classes
def extract_endpoints(self, base_dir): endpoints_classes = [] # get last item of the path # normpath is required to strip final / if any base_module = os.path.basename(os.path.normpath(base_dir)) apis_dir = os.path.join(base_dir, "endpoints") apiclass_module = f"{base_module}.endpoints" for epfiles in glob.glob(f"{apis_dir}/*.py"): # get module name (es: endpoints.filename) module_file = os.path.basename(os.path.splitext(epfiles)[0]) module_name = f"{apiclass_module}.{module_file}" # Convert module name into a module log.debug("Importing {}", module_name) module = Meta.get_module_from_string( module_name, exit_on_fail=True, ) # Extract classes from the module # module can't be none because of exit_on_fail=True... # but my-py can't understand this classes = Meta.get_new_classes_from_module(module) # type: ignore for class_name, epclss in classes.items(): # Filtering out classes without expected data if not hasattr(epclss, "methods") or epclss.methods is None: continue log.debug("Importing {} from {}.{}", class_name, apis_dir, module_file) skip, dependency = self.skip_endpoint(epclss.depends_on) if skip: log.debug( "Skipping '{} {}' due to unmet dependency: {}", module_name, class_name, dependency, ) continue endpoints_classes.append(epclss) return endpoints_classes