Skip to content

Commit

Permalink
🤡 Temp new pytypes generator
Browse files Browse the repository at this point in the history
  • Loading branch information
michprev committed Sep 23, 2024
1 parent b3dee23 commit 1ef08e1
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 26 deletions.
14 changes: 11 additions & 3 deletions wake/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ async def run_init_pytypes(
return_tx: bool,
warnings: bool,
watch: bool,
revm: bool,
incremental: Optional[bool],
):
import glob
Expand All @@ -300,7 +301,7 @@ async def run_init_pytypes(
def callback(build: ProjectBuild, build_info: ProjectBuildInfo):
start = time.perf_counter()
with console.status("[bold green]Generating pytypes..."):
type_generator = TypeGenerator(config, return_tx)
type_generator = TypeGenerator(config, return_tx, revm)
type_generator.generate_types(compiler)
end = time.perf_counter()
console.log(f"[green]Generated pytypes in [bold green]{end - start:.2f} s[/]")
Expand Down Expand Up @@ -364,7 +365,7 @@ def callback(build: ProjectBuild, build_info: ProjectBuildInfo):

start = time.perf_counter()
with console.status("[bold green]Generating pytypes..."):
type_generator = TypeGenerator(config, return_tx)
type_generator = TypeGenerator(config, return_tx, revm)
type_generator.generate_types(compiler)
end = time.perf_counter()
console.log(f"[green]Generated pytypes in [bold green]{end - start:.2f} s[/]")
Expand Down Expand Up @@ -406,6 +407,12 @@ def callback(build: ProjectBuild, build_info: ProjectBuildInfo):
default=False,
help="Watch for changes in the project and regenerate pytypes on change.",
)
@click.option(
"--revm",
is_flag=True,
default=False,
help="Generate revm pytypes.",
)
@click.option(
"--incremental/--no-incremental",
is_flag=True,
Expand Down Expand Up @@ -496,6 +503,7 @@ def init_pytypes(
return_tx: bool,
warnings: bool,
watch: bool,
revm: bool,
incremental: Optional[bool],
allow_paths: Tuple[str],
evm_version: Optional[str],
Expand Down Expand Up @@ -544,7 +552,7 @@ def init_pytypes(

config.update({"compiler": {"solc": new_options}}, deleted_options)

asyncio.run(run_init_pytypes(config, return_tx, warnings, watch, incremental))
asyncio.run(run_init_pytypes(config, return_tx, warnings, watch, revm, incremental))


@run_init.command(name="config")
Expand Down
40 changes: 31 additions & 9 deletions wake/development/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,42 @@
from wake.development.transactions import TransactionAbc, TransactionRevertedError
"""

DEFAULT_REVM_IMPORTS: str = """
from __future__ import annotations
import dataclasses
from typing import List, Dict, Optional, overload, Union, Callable, Tuple
from typing_extensions import Literal
from wake.development.core import RequestType
from wake.development.primitive_types import *
from wake.development.transactions import TransactionAbc, TransactionRevertedError
from wake_rs import Contract, Library, Address, Account, Chain
"""

INIT_CONTENT: str = """
import wake.development.core
from wake.utils import get_package_version
if get_package_version("eth-wake") != "{version}":
raise RuntimeError("Pytypes generated for a different version of wake. Please regenerate.")
wake.development.core.errors = {errors}
wake.development.core.events = {events}
wake.development.core.contracts_by_fqn = {contracts_by_fqn}
wake.development.core.contracts_by_metadata = {contracts_by_metadata}
wake.development.core.contracts_inheritance = {contracts_inheritance}
wake.development.core.contracts_revert_constructor_index = {contracts_revert_constructor_index}
wake.development.core.contracts_revert_index = {contracts_revert_index}
wake.development.core.creation_code_index = {creation_code_index}
wake.development.core.user_defined_value_types_index = {user_defined_value_types_index}
def recursive_update(d, u):
for k, v in u.items():
if isinstance(v, dict):
d[k] = recursive_update(d.get(k, {{}}), v)
else:
d[k] = v
return d
recursive_update(wake.development.core.errors, {errors})
recursive_update(wake.development.core.events, {events})
wake.development.core.contracts_by_fqn.update({contracts_by_fqn})
wake.development.core.contracts_by_metadata.update({contracts_by_metadata})
wake.development.core.contracts_inheritance.update({contracts_inheritance})
wake.development.core.contracts_revert_constructor_index.update({contracts_revert_constructor_index})
wake.development.core.contracts_revert_index.update({contracts_revert_index})
wake.development.core.creation_code_index.extend({creation_code_index})
wake.development.core.user_defined_value_types_index.update({user_defined_value_types_index})
"""
Loading

0 comments on commit 1ef08e1

Please sign in to comment.