polymerist.genutils.importutils.pkginspect ========================================== .. py:module:: polymerist.genutils.importutils.pkginspect .. autoapi-nested-parse:: For checking whether object are valid Python modules and packages, and if so for gathering info from within them Functions --------- .. autoapisummary:: polymerist.genutils.importutils.pkginspect.is_module polymerist.genutils.importutils.pkginspect.is_package polymerist.genutils.importutils.pkginspect.flexible_module_pass polymerist.genutils.importutils.pkginspect.module_parts polymerist.genutils.importutils.pkginspect.module_stem polymerist.genutils.importutils.pkginspect.relative_module_name polymerist.genutils.importutils.pkginspect.get_resource_path_within_package polymerist.genutils.importutils.pkginspect.get_dir_path_within_package polymerist.genutils.importutils.pkginspect.get_file_path_within_package Module Contents --------------- .. py:function:: is_module(module: importlib.resources.Package) -> bool Determine whether a given Package-like (i.e. str or ModuleType) is a valid Python module This will return True for packages, bottom-level modules (i.e. *.py) and Python scripts .. py:function:: is_package(package: importlib.resources.Package) -> bool Determine whether a given Package-like (i.e. str or ModuleType) is a valid Python package .. py:function:: flexible_module_pass(module: Union[str, pathlib.Path, types.ModuleType]) -> types.ModuleType Flexible interface for supplying a ModuleType object as an argument Allows for passing a name (either module name or string path), Path location, or a module proper .. py:function:: module_parts(module: Union[str, types.ModuleType]) -> tuple[Optional[str], str] Takes a module (as its name or as ModuleType) and returns its parent package name and relative module name .. py:function:: module_stem(module: Union[str, types.ModuleType]) -> tuple[Optional[str], str] Takes a module (as its name or as ModuleType) and returns its relative module name .. py:function:: relative_module_name(module: types.ModuleType, relative_to: Optional[types.ModuleType] = None, remove_leading_dot: bool = True) -> str Gets the name of a module relative to another (presumably toplevel) module If the given module is not in the path of the toplevel module, will simply return as module.__name__ .. py:function:: get_resource_path_within_package(relative_path: Union[str, pathlib.Path], package: importlib.resources.Package) -> pathlib.Path Get the Path to a resource (i.e. either a directory or a file) which lives within a Python package .. py:function:: get_dir_path_within_package(relative_path: Union[str, pathlib.Path], package: importlib.resources.Package) -> pathlib.Path Get the Path to a directory which lives within a Python package .. py:function:: get_file_path_within_package(relative_path: Union[str, pathlib.Path], package: importlib.resources.Package) -> pathlib.Path Get the Path to a (non-directory) file which lives within a Python package