Metadata-Version: 2.4
Name: rprocess
Version: 0.1.0
Summary: Incremental file processing with persistent savepoints.
Author-email: Fabian Benschuh <rprocess@bencado.com>
License: MIT License
        
        Copyright (c) 2026 Your Name
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/Cutyno/rprocess
Project-URL: Issues, https://github.com/Cutyno/rprocess/issues
Keywords: python,processing,incremental,cache,savepoint
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: build>=1.0.0; extra == "dev"
Requires-Dist: pytest>=8.0.0; extra == "dev"
Requires-Dist: twine>=5.0.0; extra == "dev"
Dynamic: license-file

# rprocess

rprocess provides glob_rprocessor, a utility to process files matched by a glob pattern with persistent savepoints.

The savepoint file stores per-file results keyed by content hash. This makes reruns faster when files are unchanged, and supports incremental recovery when interruptions happen.

## Installation

```bash
pip install rprocess
```

## Quick Start

```python
from rprocess import glob_rprocessor


def parse_file(path: str) -> int:
	with open(path, "r", encoding="utf-8") as f:
		return len(f.read())


def collect(total, current):
	if total is None:
		return current
	return total + current


total_chars = glob_rprocessor(
	pathname="data/**/*.txt",
	file_function=parse_file,
	safepoint_path=".rprocess.savepoint.pkl",
	cumulative_function=collect,
	recursive=True,
	increment_savepoint=True,
)

print(total_chars)
```

## How Savepoints Work

1. Each matched file is hashed using SHA-256.
2. If the hash already exists in the savepoint, the previous result is reused.
3. If it is new, file_function(path) runs and the result is cached.
4. Savepoint entries for files that no longer exist in the glob result are removed.

This enables fast incremental processing because unchanged files are skipped.

## Interruption and Incremental Recovery

Use increment_savepoint=True to write the savepoint after each newly processed file.

This is useful for long-running jobs:
- If execution is interrupted, progress from already-processed files is preserved.
- The next run resumes with cached results for files completed before the interruption.

If increment_savepoint=False (default), savepoint updates are written at the end when changes occurred.

## API

```python
glob_rprocessor(
	pathname,
	file_function,
	safepoint_path,
	cumulative_function=None,
	root_dir=None,
	dir_fd=None,
	recursive=False,
	verbose=False,
	increment_savepoint=False,
)
```

- pathname: glob pattern to select files.
- file_function: function called per file path.
- safepoint_path: pickle file path used to persist cached results.
- cumulative_function: optional reducer that combines per-file outputs.
- recursive: enable recursive glob patterns like **.
- verbose: print progress and savepoint maintenance messages.
- increment_savepoint: write savepoint after each new file result.

## Development

```bash
python -m pip install --upgrade build twine pytest
python -m pytest
python -m build
python -m twine check dist/*
```
