Skip to content
20 changes: 20 additions & 0 deletions src/ethereum_spec_tools/new_fork/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ def _to_args(

return commands

@dataclass
class ClearDocstring(CodemodArgs):
"""
Describe how to clear the docstring in __init__.py to libcst.tool:main.
"""
@override
def _to_args(
self, fork_builder: "ForkBuilder", working_directory: Path
) -> list[list[str]]:
init_path = working_directory / "ethereum" / fork_builder.new_fork / "__init__.py"
return [
[
"codemod",
"remove_docstring.RemoveDocstringCommand",
"--no-format",
str(init_path),
]
]


class ForkBuilder:
"""
Expand Down Expand Up @@ -353,6 +372,7 @@ def __init__(
RenameFork(),
SetForkCriteria(),
ReplaceForkName(),
ReplaceForkName(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ClearDocstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should be ClearDocstring, I'm sorry for the mixup

]

def _create_working_directory(self) -> TemporaryDirectory:
Expand Down
32 changes: 32 additions & 0 deletions src/ethereum_spec_tools/new_fork/codemod/remove_docstring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
libcst codemod that removes the module docstring.
"""
import libcst as cst
from libcst.codemod import CodemodCommand, CodemodContext
from typing_extensions import override

class RemoveDocstringCommand(CodemodCommand):
"""
Removes the module docstring if it exists.
"""
DESCRIPTION: str = "Remove the module docstring."

@override
def transform_module_impl(self, tree: cst.Module) -> cst.Module:
"""
Transform the tree by removing the docstring.
"""
if len(tree.body) == 0:
return tree
first_stmt = tree.body[0]
if not isinstance(first_stmt, cst.SimpleStatementLine):
return tree
if len(first_stmt.body) != 1:
return tree
expr = first_stmt.body[0]
if not isinstance(expr, cst.Expr):
return tree
if not isinstance(expr.value, cst.SimpleString):
return tree
new_body = tree.body[1:]
return tree.with_changes(body=new_body)
2 changes: 1 addition & 1 deletion vulture_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from ethereum_spec_tools.lint.lints.import_hygiene import ImportHygiene
from ethereum_spec_tools.new_fork.codemod.constant import SetConstantCommand
from ethereum_spec_tools.new_fork.codemod.string import StringReplaceCommand
from ethereum_spec_tools.new_fork.codemod.string_replace import StringReplaceCommand
from ethereum_spec_tools.new_fork.codemod.comment import CommentReplaceCommand
from ethereum.trace import EvmTracer

Expand Down
Loading