Metadata-Version: 2.1
Name: recurse-tree-process
Version: 0.0.2
Summary: A functional util for generic recursive tree processing
Author: Markus Peitl
Author-email: office@markuspeitl.com
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3
Description-Content-Type: text/markdown
License-File: LICENSE.txt

# A Functional util for recursive tree processing

### Usage
```python
from tree_utils.fs_recursion import RecursionStrategy, ProcessingFunctions, fs_tree_recursion, TreeNodeFunctions, get_children_paths
from tree_utils.tree_recursion import ProcessingFunctions, RecursionStrategy, TreeNodeFunctions

def example_extract_file_paths(root_dir_path: str, options={}, mode=RecursionStrategy.ANY):

    tree_node_functions: TreeNodeFunctions = TreeNodeFunctions()

    def process_file(path: str):
        logging.debug(f"Processing file: {path}")

        print(path)

        # Return the path as the desired content extracted from the node
        return path

    def process_dir(dir_path: str, children_paths: list[str], children_processing_results: list[str]):
        # The paths we returned in 'process_file' are collected and passed to the 'process_dir' function as the children_processing_results

        logging.debug(f"Processing dir: {dir_path}")
        return children_processing_results

    tree_node_functions.is_leaf = os.path.isfile
    tree_node_functions.is_node = os.path.isdir
    tree_node_functions.get_children_ids = get_children_paths
    tree_node_functions.process_leaf = process_file
    tree_node_functions.process_node = process_dir

    return fs_tree_recursion(root_dir_path, tree_node_functions, options, mode=mode)

example_extract_file_paths('/some/path')
```
