Skip to content

Commit

Permalink
fix minor issue in patch tool (#837)
Browse files Browse the repository at this point in the history
The patch tool currently throws an error while patching forks because options.prefix is None. This commit fixes it. Also updates the tool for install with pip (ethereum-spec-patch)
  • Loading branch information
gurukamath authored Sep 20, 2023
1 parent e69b389 commit 2f5de1c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ console_scripts =
ethereum-spec-sync = ethereum_spec_tools.sync:main
ethereum-spec-diff = ethereum_spec_tools.diff:main
ethereum-spec-new-fork = ethereum_spec_tools.new_fork:main
ethereum-spec-patch = ethereum_spec_tools.patch_tool:main
ethereum-spec-evm = ethereum_spec_tools.evm_tools:main

[options.extras_require]
Expand Down
84 changes: 46 additions & 38 deletions src/ethereum_spec_tools/patch_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,55 @@
help="Patch the tests instead",
)

options = parser.parse_args()

source_fork_path = options.prefix + options.source_fork[0]
def main() -> None:
"""
Patch the changes from one fork into the others.
"""
options = parser.parse_args()

if options.prefix == "tests/" and "dao_fork" in options.targets:
raise Exception("dao_fork has no tests")
if not options.prefix:
options.prefix = "src/ethereum/"

git_diff = subprocess.run(
["git", "diff", source_fork_path], capture_output=True, text=True
)

output_lines = git_diff.stdout.splitlines(keepends=True)
source_fork_path = options.prefix + options.source_fork[0]

for target in options.targets:
patch = ""
for line in output_lines:
if line.startswith("diff --git"):
pass
elif line.startswith("index"):
pass
elif line.startswith("--- a/"):
patch += line.replace(
"--- a/" + options.prefix + options.source_fork[0],
"--- " + options.prefix + target,
)
elif line.startswith("+++ b/"):
patch += line.replace(
"+++ b/" + options.prefix + options.source_fork[0],
"+++ " + options.prefix + target,
)
else:
patch += line
if options.prefix == "tests/" and "dao_fork" in options.targets:
raise Exception("dao_fork has no tests")

subprocess.run(
[
"patch",
"-p0",
"--no-backup-if-mismatch",
],
input=patch,
text=True,
stdout=stdout,
stderr=stderr,
git_diff = subprocess.run(
["git", "diff", source_fork_path], capture_output=True, text=True
)

output_lines = git_diff.stdout.splitlines(keepends=True)

for target in options.targets:
patch = ""
for line in output_lines:
if line.startswith("diff --git"):
pass
elif line.startswith("index"):
pass
elif line.startswith("--- a/"):
patch += line.replace(
"--- a/" + options.prefix + options.source_fork[0],
"--- " + options.prefix + target,
)
elif line.startswith("+++ b/"):
patch += line.replace(
"+++ b/" + options.prefix + options.source_fork[0],
"+++ " + options.prefix + target,
)
else:
patch += line

subprocess.run(
[
"patch",
"-p0",
"--no-backup-if-mismatch",
],
input=patch,
text=True,
stdout=stdout,
stderr=stderr,
)

0 comments on commit 2f5de1c

Please sign in to comment.