Skip to content

file_search

Find Files.

Functions⚓︎

find_project_files ⚓︎

find_project_files(path_project, ignore_patterns)

Find project files in git version control.

Note: uses the relative project directory and verifies that each file exists

PARAMETER DESCRIPTION
path_project

Path to the project directory

TYPE: Path

ignore_patterns

glob ignore patterns

TYPE: List[str]

RETURNS DESCRIPTION
List[Path]

Dict[str, List[Path]]: where keys are the suffix (without leading dot) and values the list of paths

Source code in calcipy/file_search.py
@beartype
def find_project_files(path_project: Path, ignore_patterns: List[str]) -> List[Path]:
    """Find project files in git version control.

    > Note: uses the relative project directory and verifies that each file exists

    Args:
        path_project: Path to the project directory
        ignore_patterns: glob ignore patterns

    Returns:
        Dict[str, List[Path]]: where keys are the suffix (without leading dot) and values the list of paths

    """
    file_paths = []
    rel_filepaths = _get_all_files(cwd=path_project)
    filtered_rel_files = _filter_files(rel_filepaths=rel_filepaths, ignore_patterns=ignore_patterns)
    for rel_file in filtered_rel_files:
        path_file = path_project / rel_file
        if path_file.is_file():
            file_paths.append(path_file)
        else:  # pragma: no cover
            logger.warning('Could not find the specified file', path_file=path_file)
    return file_paths

find_project_files_by_suffix ⚓︎

find_project_files_by_suffix(path_project, *, ignore_patterns=None)

Find project files in git version control.

Note: uses the relative project directory and verifies that each file exists

PARAMETER DESCRIPTION
path_project

Path to the project directory

TYPE: Path

ignore_patterns

glob ignore patterns

TYPE: Optional[List[str]] DEFAULT: None

RETURNS DESCRIPTION
Dict[str, List[Path]]

Dict[str, List[Path]]: where keys are the suffix (without leading dot) and values the list of paths

Source code in calcipy/file_search.py
@beartype
def find_project_files_by_suffix(
    path_project: Path, *, ignore_patterns: Optional[List[str]] = None,
) -> Dict[str, List[Path]]:
    """Find project files in git version control.

    > Note: uses the relative project directory and verifies that each file exists

    Args:
        path_project: Path to the project directory
        ignore_patterns: glob ignore patterns

    Returns:
        Dict[str, List[Path]]: where keys are the suffix (without leading dot) and values the list of paths

    """
    file_lookup: Dict[str, List[Path]] = defaultdict(list)
    for path_file in find_project_files(path_project, ignore_patterns or []):
        file_lookup[path_file.suffix.lstrip('.')].append(path_file)
    return dict(file_lookup)