Source code for mpu.path

"""Functions for path manipulation and retrieval of files."""

# Core Library
import os
from typing import List

# Third party
import pkg_resources

[docs]def get_all_files(root: str, followlinks: bool = False) -> List: """ Get all files within the given root directory. Note that this list is not ordered. Parameters ---------- root : str Path to a directory followlinks : bool, optional (default: False) Returns ------- filepaths : List List of absolute paths to files """ filepaths = [] for path, _, files in os.walk(root, followlinks=followlinks): for name in files: filepaths.append(os.path.abspath(os.path.join(path, name))) return filepaths
[docs]def get_from_package(package_name: str, path: str) -> str: """ Get the absolute path to a file in a package. Parameters ---------- package_name : str e.g. 'mpu' path : str Path within a package Returns ------- filepath : str """ filepath = pkg_resources.resource_filename(package_name, path) return os.path.abspath(filepath)