runtimeverification / runtimeverification/evm-semantics

Split `__main__.py`

Open
#1,661 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
KCL
Stars
591
Forks
156
Avg merge
2h 19m
Merged PRs (30d)
1

Description

Create a package cli with a module for each command. Then as a first approach, we can do something like

def exec_mycommand(**kwargs: Any) -> None:
   from .cli import mycommand
   mycommand.execute(**kwargs)

As a next step, we can abstract further by doing the imports dynamically (not tested):

def main() -> None:
    ...
    command_name = args.command.lower().replace('-', '_')
    try:
        command = importlib.import_module(f'kevm_pyk.cli.{command_name})
    except ImportError:
        raise RuntimeError(f'Unimplemented command: {args.command}')

    command.execute(**vars(args))

Rationale

For each command invocation, loading all the modules has significant overhead.

% poetry -C kevm-pyk run python3 -m cProfile -s cumtime -m kevm_pyk
usage: python3 -m kevm_pyk [-h]
                           {kompile,prove,view-kcfg,show-kcfg,run,compile,solc-to-k,foundry-kompile,foundry-prove,foundry-show,foundry-to-dot,foundry-list,foundry-view-kcfg,foundry-remove-node,foundry-simplify-node,foundry-step-node,foundry-section-edge}
                           ...
python3 -m kevm_pyk: error: the following arguments are required: command
         350601 function calls (343094 primitive calls) in 0.245 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       41    0.001    0.000    0.355    0.009 __init__.py:1(<module>)
    950/1    0.032    0.000    0.246    0.246 {built-in method builtins.exec}
        1    0.000    0.000    0.246    0.246 <string>:1(<module>)
        1    0.000    0.000    0.246    0.246 runpy.py:199(run_module)
        2    0.000    0.000    0.245    0.123 __main__.py:1(<module>)
        1    0.000    0.000    0.245    0.245 runpy.py:63(_run_code)
   443/11    0.001    0.000    0.234    0.021 <frozen importlib._bootstrap>:1022(_find_and_load)
   443/11    0.001    0.000    0.234    0.021 <frozen importlib._bootstrap>:987(_find_and_load_unlocked)
   428/12    0.001    0.000    0.233    0.019 <frozen importlib._bootstrap>:664(_load_unlocked)
   391/12    0.001    0.000    0.233    0.019 <frozen importlib._bootstrap_external>:877(exec_module)
   561/12    0.000    0.000    0.232    0.019 <frozen importlib._bootstrap>:233(_call_with_frames_removed)
    98/41    0.000    0.000    0.111    0.003 {built-in method builtins.__import__}
        1    0.000    0.000    0.102    0.102 tui.py:1(<module>)
        1    0.000    0.000    0.063    0.063 explore.py:1(<module>)
  292/143    0.000    0.000    0.061    0.000 <frozen importlib._bootstrap>:1053(_handle_fromlist)
        1    0.000    0.000    0.061    0.061 app.py:1(<module>)
1057/1044    0.008    0.000    0.055    0.000 {built-in method builtins.__build_class__}
      101    0.000    0.000    0.054    0.001 dataclasses.py:1174(wrap)
      101    0.003    0.000    0.054    0.001 dataclasses.py:881(_process_class)
        1    0.000    0.000    0.044    0.044 rpc.py:1(<module>)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with kevm_pyk/main.py and trace how the commands listed in the usage output are registered and invoked. Review the proposed cli package structure and import behavior, then verify that each command still works while startup loads only the selected command's modules and reduces the current import overhead.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.