From 2d7c74c5355ded6df7425cd94a034f7f848bdaf8 Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 3 Oct 2018 15:11:21 +0200 Subject: [PATCH] switch to click 7.0 --- requirements.txt | 2 +- setup.py | 2 +- trezorctl | 16 +++++++++++++++- trezorlib/ui.py | 22 +--------------------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/requirements.txt b/requirements.txt index 37a872ff68..f1aac68bde 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ ecdsa>=0.9 mnemonic>=0.17 requests>=2.4.0 -click>=6.2 +click>=7,<8 pyblake2>=0.9.3 libusb1>=1.6.4 construct>=2.9 diff --git a/setup.py b/setup.py index 32a08c18b4..aa1624339a 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ install_requires = [ "ecdsa>=0.9", "mnemonic>=0.17", "requests>=2.4.0", - "click>=6.2", + "click>=7,<8", "pyblake2>=0.9.3", "libusb1>=1.6.4", "construct>=2.9", diff --git a/trezorctl b/trezorctl index 63e663a992..41287694e8 100755 --- a/trezorctl +++ b/trezorctl @@ -89,12 +89,26 @@ CHOICE_OUTPUT_SCRIPT_TYPE = ChoiceType( ) +class UnderscoreAgnosticGroup(click.Group): + """Command group that normalizes dashes and underscores. + + Click 7.0 silently switched all underscore_commands to dash-commands. + This implementation of `click.Group` responds to underscore_commands by invoking + the respective dash-command. + """ + def get_command(self, ctx, cmd_name): + cmd = super().get_command(ctx, cmd_name) + if cmd is None: + cmd = super().get_command(ctx, cmd_name.replace("_", "-")) + return cmd + + def enable_logging(): log.enable_debug_output() log.OMITTED_MESSAGES.add(proto.Features) -@click.group(context_settings={"max_content_width": 400}) +@click.command(cls=UnderscoreAgnosticGroup, context_settings={"max_content_width": 400}) @click.option( "-p", "--path", diff --git a/trezorlib/ui.py b/trezorlib/ui.py index d3681fb2fa..6796bac2d7 100644 --- a/trezorlib/ui.py +++ b/trezorlib/ui.py @@ -101,30 +101,10 @@ def mnemonic_words(expand=False, language="english"): return get_word -try: - # workaround for Click issue https://github.com/pallets/click/pull/1108 - import msvcrt - - def getchar(): - while True: - key = msvcrt.getwch() - if key == "\x03": - raise KeyboardInterrupt - if key in (0x00, 0xE0): - # skip special keys: read the scancode and repeat - msvcrt.getwch() - continue - return key - - -except ImportError: - getchar = click.getchar - - def matrix_words(type): while True: try: - ch = getchar() + ch = click.getchar() except (KeyboardInterrupt, EOFError): raise Cancelled from None