Batch / directory processing

The PyReprism.batch module analyzes or transforms whole source trees. Discovery skips junk folders (.git, node_modules, venv, …) and files with unrecognized extensions:

from PyReprism import batch

report = batch.analyze("myproject/")
report.totals()
report.by_language()
print(report.to_csv())

batch.transform("myproject/",
                lambda text, lang: lang.remove_comments(text),
                output="stripped/")

Batch/directory processing: analyze or transform whole source trees.

Discovery walks directories, skips common junk folders, and keeps only files whose extension maps to a supported language. analyze() returns aggregate metrics (per file, per language, and totals) exportable as JSON or CSV; transform() applies a text transformation across a tree, optionally writing a mirrored output directory.

class PyReprism.batch.BatchReport(files: ~typing.List[~PyReprism.batch.FileReport] = <factory>)

Bases: object

Aggregate report over a set of files.

by_language() Dict[str, Dict[str, int]]
property errors: List[FileReport]
files: List[FileReport]
property ok: List[FileReport]
to_csv() str
to_dict() dict
to_json(indent: int = 2) str
totals() Dict[str, int]
class PyReprism.batch.FileReport(path: str, language: str, stats: CodeStats | None = None, error: str | None = None)

Bases: object

Metrics for one processed file (stats is None on error).

error: str | None = None
language: str
path: str
stats: CodeStats | None = None
PyReprism.batch.analyze(paths: str | PathLike | Sequence[str | PathLike], *, engine: str = 'regex', recursive: bool = True, include: Sequence[str] | None = None, exclude: Sequence[str] | None = None) BatchReport

Walk paths and compute CodeStats for every supported file.

PyReprism.batch.iter_source_files(paths: str | PathLike | Sequence[str | PathLike], *, recursive: bool = True, include: Sequence[str] | None = None, exclude: Sequence[str] | None = None) Iterator[Tuple[Path, Path, type]]

Yield (base, path, language_cls) for every supported source file.

base is the top-level input the file was discovered under (used to mirror directory structure). Files with an unrecognized extension are skipped.

PyReprism.batch.transform(paths: str | PathLike | Sequence[str | PathLike], transformer: Callable[[str, type], str], *, output: str | PathLike | None = None, in_place: bool = False, recursive: bool = True, include: Sequence[str] | None = None, exclude: Sequence[str] | None = None) List[Tuple[str, str]]

Apply transformer(text, language_cls) to every discovered file.

With output the tree is mirrored under that directory; with in_place files are rewritten. Returns (path, status) pairs.