mass_driver.drivers.bricks

Patterns of PatchDriver that are reusable

Module Contents

Classes

SingleFileEditor

A PatchDriver that edits a single file

GlobFileEditor

A PatchDriver that edits multiple files via Glob

Functions

process_outcomes

Forward a OK PatchResult if an OK happened on any file

API

class mass_driver.drivers.bricks.SingleFileEditor[source]

Bases: mass_driver.models.patchdriver.PatchDriver

A PatchDriver that edits a single file

Reads target_file and calls process_file() with it string content, saving the file if process changes the file, or returns given PatchResult if any.

target_file: str = None

The file to edit

abstract process_file(file_contents: str) str | mass_driver.models.patchdriver.PatchResult[source]

Process the file, returning the new content or a PatchResult

run(repo: mass_driver.models.repository.ClonedRepo) mass_driver.models.patchdriver.PatchResult[source]

Edit the target file

class mass_driver.drivers.bricks.GlobFileEditor[source]

Bases: mass_driver.models.patchdriver.PatchDriver

A PatchDriver that edits multiple files via Glob

Reads target_glob and calls process_file() with each string content, saving the file if process changes each file.

The aggregated PatchResults are processed via process_outcomes(), see the fail_on_any_error parameter.

target_glob: str = None

The glob for files to edit, relative to project root

fail_on_any_error: bool = True

Whether or not to declare failure on any PATCH_ERRROR, or assume any OK as good

abstract process_file(filename, file_contents: str) str | mass_driver.models.patchdriver.PatchResult[source]

Process a file, returning the new content or a PatchResult

run(repo: mass_driver.models.repository.ClonedRepo) mass_driver.models.patchdriver.PatchResult[source]

Edit the target file

mass_driver.drivers.bricks.process_outcomes(outcomes: dict[str, mass_driver.models.patchdriver.PatchResult], fail_on_any_error: bool, logger: logging.Logger)[source]

Forward a OK PatchResult if an OK happened on any file