-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use codemod execution context to store results
- Loading branch information
Showing
9 changed files
with
73 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from pathlib import Path | ||
from dataclasses import dataclass | ||
|
||
from codemodder.codemods.change import Change | ||
|
||
|
||
@dataclass | ||
class ChangeSet: | ||
"""A set of changes made to a file at `path`""" | ||
|
||
path: str | ||
diff: str | ||
changes: list[Change] | ||
|
||
def to_json(self): | ||
return {"path": self.path, "diff": self.diff, "changes": self.changes} | ||
|
||
|
||
class CodemodExecutionContext: | ||
results_by_codemod: dict[str, list[ChangeSet]] = {} | ||
directory: Path | ||
dry_run: bool = False | ||
|
||
def __init__(self, directory, dry_run): | ||
self.directory = directory | ||
self.dry_run = dry_run | ||
self.results_by_codemod = {} | ||
|
||
def add_result(self, codemod_name, change_set): | ||
self.results_by_codemod.setdefault(codemod_name, []).append(change_set) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters