fpf
¶
Extensible File Path Filtering.
Simple FPF implementations
Example usage with a simple function filter:
from fpf import filter_file_paths
def filter1(file_path):
'''Filter out all files not ending with `.yml`'''
return file_path.endswith('.yml')
list(filter_file_paths(root_dir='.', path_filter=filter1))
Example usage with an fpf filter:
from fpf import filter_file_paths, YamlIgnoreFilter
# Read pathspec from `.myproject-yaml-ignore-file` and only include yml files.
filter2 = YamlIgnoreFilter('.myproject-yaml-ignore-file')
list(filter_file_paths(root_dir='.', path_filter=filter2))
Functions¶
file_path_filter()
: Filter file paths/names relative to the root based on a filter.filter_file_paths()
: Filter file paths/names relative to the root based on a filter.fpf()
: Filter file paths/names relative to the root based on a filter.
- fpf.file_path_filter(root_dir, path_filter=<fpf.filters.DummyFilter object>, relative_paths=True)[source]¶
Filter file paths/names relative to the root based on a filter.
- Parameters
root_dir (str) – root directory to filter through.
path_filter (Callable[[str], bool]) – A filter function. Returns false for files/paths that should be excluded.
relative_paths (bool, optional) – return relative paths to the root dir, alternative is full absolute paths on the file system, defaults to True.
- Yield
file path/name that passes the filter.
- Return type
Generator[str, None, None]
- fpf.filter_file_paths(root_dir, path_filter=<fpf.filters.DummyFilter object>, relative_paths=True)¶
Filter file paths/names relative to the root based on a filter.
- Parameters
root_dir (str) – root directory to filter through.
path_filter (Callable[[str], bool]) – A filter function. Returns false for files/paths that should be excluded.
relative_paths (bool, optional) – return relative paths to the root dir, alternative is full absolute paths on the file system, defaults to True.
- Yield
file path/name that passes the filter.
- Return type
Generator[str, None, None]
- fpf.fpf(root_dir, path_filter=<fpf.filters.DummyFilter object>, relative_paths=True)¶
Filter file paths/names relative to the root based on a filter.
- Parameters
root_dir (str) – root directory to filter through.
path_filter (Callable[[str], bool]) – A filter function. Returns false for files/paths that should be excluded.
relative_paths (bool, optional) – return relative paths to the root dir, alternative is full absolute paths on the file system, defaults to True.
- Yield
file path/name that passes the filter.
- Return type
Generator[str, None, None]