"""Provides a function to report all internal modules for using freezingtools."""from__future__importannotationsimporttypesfromtypingimportIterator
[docs]deffreeze_includes()->list[str]:"""Return a list of module names used by pytest that should be included by cx_freeze."""import_pytestresult=list(_iter_all_modules(_pytest))returnresult
def_iter_all_modules(package:str|types.ModuleType,prefix:str="",)->Iterator[str]:"""Iterate over the names of all modules that can be found in the given package, recursively. >>> import _pytest >>> list(_iter_all_modules(_pytest)) ['_pytest._argcomplete', '_pytest._code.code', ...] """importosimportpkgutilifisinstance(package,str):path=packageelse:# Type ignored because typeshed doesn't define ModuleType.__path__# (only defined on packages).package_path=package.__path__path,prefix=package_path[0],package.__name__+"."for_,name,is_packageinpkgutil.iter_modules([path]):ifis_package:formin_iter_all_modules(os.path.join(path,name),prefix=name+"."):yieldprefix+melse:yieldprefix+name