palgen.machinery.filesystem
#
Module Contents#
- palgen.machinery.filesystem.gitignore(path)#
This function creates a PathSpec object from a .gitignore file.
- Parameters:
path (
Path
) – The path to the .gitignore file.- Returns:
A PathSpec object
- Return type:
PathSpec
- palgen.machinery.filesystem.walk(path, ignores=PathSpec([]), jobs=None)#
Traverse a directory tree and return a list of Path objects representing the files and folders found in the directory.
- Parameters:
path (
Path
) – Path to the directory to traverseignores (
PathSpec
) – A PathSpec object representing the patterns to ignore when traversing the directory.jobs (
Optional[int], optional
) – An integer representing the number of concurrent jobs to use for traversal. Defaults to None, meaning however many CPU cores the system has.
- Returns:
An iterable object representing the files and folders found in the directory.
- Return type:
Iterable[Path]
- palgen.machinery.filesystem.discover(paths, ignores=None, jobs=None)#
Walks through every folder in
paths
, returns list of all non-ignored files and folders.- Parameters:
paths (
list[Path]
) – List of paths to walk throughignores (
Optional[PathSpec], optional
) – Patterns to match files and folders which ought to be ignored. You probably want to usegitignore(...)
to get aPathSpec
object for this parameter.jobs (
Optional[int], optional
) – Amount of jobs to run this at. Defaults to None, meaning however many cpu cores the system has.
- Returns:
_description_
- Return type:
list[Path]
- palgen.machinery.filesystem.find_backwards(filename, source_dir=None)#
Traverse up the folder hierarchy until any of the parent folders contain the file we’re looking for.
- Parameters:
filename (
str
) – Name of the file to be foundsource_dir (
Optional[Path], optional
) – What folder to start searching in. Defaults to the current working directory.
- Raises:
FileNotFoundError – File wasn’t found
- Returns:
Path to the file if it was found
- Return type:
Path