mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-15 19:18:11 +00:00
chore(core): add type hints to emu.py
This commit is contained in:
parent
85f0d3a741
commit
5671bd037b
64
core/emu.py
64
core/emu.py
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
@ -6,8 +8,8 @@ import signal
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import TextIO
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ TREZOR_STORAGE_FILES = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def run_command_with_emulator(emulator, command):
|
def run_command_with_emulator(emulator: CoreEmulator, command: list[str]) -> int:
|
||||||
with emulator:
|
with emulator:
|
||||||
# first start the subprocess
|
# first start the subprocess
|
||||||
process = subprocess.Popen(command)
|
process = subprocess.Popen(command)
|
||||||
@ -47,13 +49,14 @@ def run_command_with_emulator(emulator, command):
|
|||||||
return process.wait()
|
return process.wait()
|
||||||
|
|
||||||
|
|
||||||
def run_emulator(emulator):
|
def run_emulator(emulator: CoreEmulator) -> int:
|
||||||
with emulator:
|
with emulator:
|
||||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||||
return emulator.wait()
|
return emulator.wait()
|
||||||
|
|
||||||
|
|
||||||
def watch_emulator(emulator):
|
def watch_emulator(emulator: CoreEmulator) -> int:
|
||||||
|
assert inotify is not None
|
||||||
watch = inotify.adapters.InotifyTree(str(SRC_DIR))
|
watch = inotify.adapters.InotifyTree(str(SRC_DIR))
|
||||||
try:
|
try:
|
||||||
for _, type_names, _, _ in watch.event_gen(yield_nones=False):
|
for _, type_names, _, _ in watch.event_gen(yield_nones=False):
|
||||||
@ -64,23 +67,23 @@ def watch_emulator(emulator):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def run_debugger(emulator):
|
def run_debugger(emulator: CoreEmulator) -> None:
|
||||||
os.chdir(emulator.workdir)
|
os.chdir(emulator.workdir)
|
||||||
env = emulator.make_env()
|
env = emulator.make_env()
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
env["PATH"] = "/usr/bin"
|
env["PATH"] = "/usr/bin"
|
||||||
os.execvpe(
|
os.execvpe(
|
||||||
"lldb",
|
"lldb",
|
||||||
["lldb", "-f", emulator.executable, "--"] + emulator.make_args(),
|
["lldb", "-f", str(emulator.executable), "--"] + emulator.make_args(),
|
||||||
env,
|
env,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
os.execvpe(
|
os.execvpe(
|
||||||
"gdb", ["gdb", "--args", emulator.executable] + emulator.make_args(), env
|
"gdb", ["gdb", "--args", str(emulator.executable)] + emulator.make_args(), env
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _from_env(name):
|
def _from_env(name: str) -> bool:
|
||||||
return os.environ.get(name) == "1"
|
return os.environ.get(name) == "1"
|
||||||
|
|
||||||
|
|
||||||
@ -112,28 +115,28 @@ def _from_env(name):
|
|||||||
# fmt: on
|
# fmt: on
|
||||||
@click.argument("command", nargs=-1, type=click.UNPROCESSED)
|
@click.argument("command", nargs=-1, type=click.UNPROCESSED)
|
||||||
def cli(
|
def cli(
|
||||||
disable_animation,
|
disable_animation: bool,
|
||||||
run_command,
|
run_command: bool,
|
||||||
production,
|
production: bool,
|
||||||
debugger,
|
debugger: bool,
|
||||||
erase,
|
erase: bool,
|
||||||
executable,
|
executable: str | Path,
|
||||||
profiling,
|
profiling: bool,
|
||||||
alloc_profiling,
|
alloc_profiling: bool,
|
||||||
headless,
|
headless: bool,
|
||||||
heap_size,
|
heap_size: str,
|
||||||
main,
|
main: str,
|
||||||
mnemonics,
|
mnemonics: list[str],
|
||||||
log_memory,
|
log_memory: bool,
|
||||||
profile,
|
profile: str,
|
||||||
port,
|
port: int,
|
||||||
output,
|
output: TextIO | None,
|
||||||
quiet,
|
quiet: bool,
|
||||||
slip0014,
|
slip0014: bool,
|
||||||
temporary_profile,
|
temporary_profile: bool,
|
||||||
watch,
|
watch: bool,
|
||||||
extra_args,
|
extra_args: list[str],
|
||||||
command,
|
command: list[str],
|
||||||
):
|
):
|
||||||
"""Run the trezor-core emulator.
|
"""Run the trezor-core emulator.
|
||||||
|
|
||||||
@ -261,6 +264,7 @@ def cli(
|
|||||||
else:
|
else:
|
||||||
label = "Emulator"
|
label = "Emulator"
|
||||||
|
|
||||||
|
assert emulator.client is not None
|
||||||
trezorlib.device.wipe(emulator.client)
|
trezorlib.device.wipe(emulator.client)
|
||||||
trezorlib.debuglink.load_device(
|
trezorlib.debuglink.load_device(
|
||||||
emulator.client,
|
emulator.client,
|
||||||
|
Loading…
Reference in New Issue
Block a user