From 6751d84236d69ec8de6aa38bef379b9642b9b266 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Tue, 3 Jul 2018 14:28:17 +0200 Subject: [PATCH] style: skip formatting in special cases --- src/apps/common/coininfo.py | 3 +- src/apps/common/storage.py | 2 ++ src/apps/ethereum/networks.py | 47 ++++++++++++++-------------- src/main.py | 2 ++ src/trezor/ui/__init__.py | 58 +++++++++++++++++------------------ src/usb.py | 2 ++ 6 files changed, 60 insertions(+), 54 deletions(-) diff --git a/src/apps/common/coininfo.py b/src/apps/common/coininfo.py index a36d9caee..4df19faa5 100644 --- a/src/apps/common/coininfo.py +++ b/src/apps/common/coininfo.py @@ -45,8 +45,9 @@ class CoinInfo: self.sign_hash_double = True -# the following list is generated using tools/codegen/gen_coins.py +# generated using tools/codegen/gen_coins.py # do not edit manually! +# fmt: off COINS = [ CoinInfo( coin_name='Bitcoin', diff --git a/src/apps/common/storage.py b/src/apps/common/storage.py index c186a63f8..b3406cf9e 100644 --- a/src/apps/common/storage.py +++ b/src/apps/common/storage.py @@ -8,6 +8,7 @@ HOMESCREEN_MAXSIZE = 16384 _STORAGE_VERSION = b'\x01' +# fmt: off _APP = const(0x01) # app namespace _DEVICE_ID = const(0x00) # bytes _VERSION = const(0x01) # int @@ -22,6 +23,7 @@ _U2F_COUNTER = const(0x09) # int _PASSPHRASE_SOURCE = const(0x0A) # int _UNFINISHED_BACKUP = const(0x0B) # bool (0x01 or empty) _AUTOLOCK_DELAY_MS = const(0x0C) # int +# fmt: on def _new_device_id() -> str: diff --git a/src/apps/ethereum/networks.py b/src/apps/ethereum/networks.py index 043b965d7..8981bba0a 100644 --- a/src/apps/ethereum/networks.py +++ b/src/apps/ethereum/networks.py @@ -1,3 +1,25 @@ +def shortcut_by_chain_id(chain_id, tx_type=None): + if tx_type in [1, 6] and chain_id in [1, 3]: + return 'WAN' + else: + n = by_chain_id(chain_id) + return n.shortcut if n is not None else 'UNKN' + + +def by_chain_id(chain_id): + for n in NETWORKS: + if n.chain_id == chain_id: + return n + return None + + +def by_slip44(slip44): + for n in NETWORKS: + if n.slip44 == slip44: + return n + return None + + class NetworkInfo: def __init__( @@ -15,8 +37,9 @@ class NetworkInfo: self.rskip60 = rskip60 -# the following list is generated using tools/codegen/gen_eth_networks.py +# generated using tools/codegen/gen_eth_networks.py # do not edit manually! +# fmt: off NETWORKS = [ NetworkInfo( chain_id=1, @@ -124,25 +147,3 @@ NETWORKS = [ rskip60=False, ), ] - - -def shortcut_by_chain_id(chain_id, tx_type=None): - if tx_type in [1, 6] and chain_id in [1, 3]: - return 'WAN' - else: - n = by_chain_id(chain_id) - return n.shortcut if n is not None else 'UNKN' - - -def by_chain_id(chain_id): - for n in NETWORKS: - if n.chain_id == chain_id: - return n - return None - - -def by_slip44(slip44): - for n in NETWORKS: - if n.slip44 == slip44: - return n - return None diff --git a/src/main.py b/src/main.py index 0c239327c..a78d76086 100644 --- a/src/main.py +++ b/src/main.py @@ -1,3 +1,5 @@ +# isort:skip_file + # unlock the device import boot # noqa: F401 diff --git a/src/trezor/ui/__init__.py b/src/trezor/ui/__init__.py index 4465c92b7..8280f2f11 100644 --- a/src/trezor/ui/__init__.py +++ b/src/trezor/ui/__init__.py @@ -1,35 +1,31 @@ -from micropython import const - import math import utime - +from micropython import const from trezorui import Display -from trezor import io -from trezor import loop -from trezor import res -from trezor import workflow +from trezor import io, loop, res, workflow from trezor.utils import model display = Display() # in debug mode, display an indicator in top right corner if __debug__: + def debug_display_refresh(): display.bar(Display.WIDTH - 8, 0, 8, 8, 0xF800) display.refresh() + loop.after_step_hook = debug_display_refresh # in both debug and production, emulator needs to draw the screen explicitly -elif model() == 'EMU': +elif model() == "EMU": loop.after_step_hook = display.refresh -# import constants from modtrezorui - -SIZE = Display.FONT_SIZE +# re-export constants from modtrezorui NORMAL = Display.FONT_NORMAL BOLD = Display.FONT_BOLD MONO = Display.FONT_MONO +SIZE = Display.FONT_SIZE WIDTH = Display.WIDTH HEIGHT = Display.HEIGHT @@ -46,10 +42,12 @@ def blend(ca: int, cb: int, t: float) -> int: return rgb( lerpi((ca >> 8) & 0xF8, (cb >> 8) & 0xF8, t), lerpi((ca >> 3) & 0xFC, (cb >> 3) & 0xFC, t), - lerpi((ca << 3) & 0xF8, (cb << 3) & 0xF8, t)) + lerpi((ca << 3) & 0xF8, (cb << 3) & 0xF8, t), + ) -from trezor.ui.style import * +# import style definitions +from trezor.ui.style import * # isort:skip def contains(area: tuple, pos: tuple) -> bool: @@ -77,7 +75,7 @@ def pulse(delay: int): yield 0.5 + 0.5 * math.sin(utime.ticks_us() / delay) -async def alert(count: int=3): +async def alert(count: int = 3): short_sleep = loop.sleep(20000) long_sleep = loop.sleep(80000) current = display.backlight() @@ -104,7 +102,7 @@ async def click() -> tuple: return pos -async def backlight_slide(val: int, delay: int=35000, step: int=20): +async def backlight_slide(val: int, delay: int = 35000, step: int = 20): sleep = loop.sleep(delay) current = display.backlight() for i in range(current, val, -step if current > val else step): @@ -129,11 +127,9 @@ def layout(f): return inner -def header(title: str, - icon: bytes=ICON_DEFAULT, - fg: int=FG, - bg: int=BG, - ifg: int=GREEN): +def header( + title: str, icon: bytes = ICON_DEFAULT, fg: int = FG, bg: int = BG, ifg: int = GREEN +): if icon is not None: display.icon(14, 15, res.load(icon), ifg, bg) display.text(44, 35, title, BOLD, fg, bg) @@ -143,16 +139,18 @@ VIEWX = const(6) VIEWY = const(9) -def grid(i: int, - n_x: int=3, - n_y: int=5, - start_x: int=VIEWX, - start_y: int=VIEWY, - end_x: int=(WIDTH - VIEWX), - end_y: int=(HEIGHT - VIEWY), - cells_x: int=1, - cells_y: int=1, - spacing: int=0): +def grid( + i: int, + n_x: int = 3, + n_y: int = 5, + start_x: int = VIEWX, + start_y: int = VIEWY, + end_x: int = (WIDTH - VIEWX), + end_y: int = (HEIGHT - VIEWY), + cells_x: int = 1, + cells_y: int = 1, + spacing: int = 0, +): w = (end_x - start_x) // n_x h = (end_y - start_y) // n_y x = (i % n_x) * w diff --git a/src/usb.py b/src/usb.py index 65597ec0e..53f0bfee4 100644 --- a/src/usb.py +++ b/src/usb.py @@ -2,6 +2,8 @@ from trezor import io from apps.common.storage import get_device_id +# fmt: off + # interface used for trezor wire protocol iface_wire = io.WebUSB( iface_num=0,