mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 04:18:10 +00:00
style(python): implement isort 5 for trezorlib
[no changelog]
This commit is contained in:
parent
a12bc416ed
commit
821d70dd8d
@ -3,7 +3,6 @@ SETUP=$(PYTHON) setup.py
|
|||||||
|
|
||||||
EXCLUDES=.vscode
|
EXCLUDES=.vscode
|
||||||
STYLE_TARGETS=src/trezorlib setup.py
|
STYLE_TARGETS=src/trezorlib setup.py
|
||||||
EXCLUDE_TARGETS=messages
|
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
@ -46,20 +45,20 @@ git-clean:
|
|||||||
|
|
||||||
style:
|
style:
|
||||||
black $(STYLE_TARGETS)
|
black $(STYLE_TARGETS)
|
||||||
isort --apply --recursive $(STYLE_TARGETS) --skip-glob "$(EXCLUDE_TARGETS)/*"
|
isort --apply --recursive $(STYLE_TARGETS)
|
||||||
autoflake -i --remove-all-unused-imports -r $(STYLE_TARGETS) --exclude "$(EXCLUDE_TARGETS)"
|
autoflake -i --remove-all-unused-imports -r $(STYLE_TARGETS)
|
||||||
flake8
|
flake8
|
||||||
make pyright
|
make pyright
|
||||||
|
|
||||||
style_check:
|
style_check:
|
||||||
black --check $(STYLE_TARGETS)
|
black --check $(STYLE_TARGETS)
|
||||||
isort --check-only --recursive $(STYLE_TARGETS) --skip-glob "$(EXCLUDE_TARGETS)/*"
|
isort --check-only $(STYLE_TARGETS)
|
||||||
flake8
|
flake8
|
||||||
make pyright
|
make pyright
|
||||||
|
|
||||||
style_quick_check:
|
style_quick_check:
|
||||||
black --check $(STYLE_TARGETS)
|
black --check $(STYLE_TARGETS)
|
||||||
isort --check-only --recursive $(STYLE_TARGETS) --skip-glob "$(EXCLUDE_TARGETS)/*"
|
isort --check-only $(STYLE_TARGETS)
|
||||||
|
|
||||||
.PHONY: all build install clean style style_check git-clean clean-build clean-pyc clean-test
|
.PHONY: all build install clean style style_check git-clean clean-build clean-pyc clean-test
|
||||||
|
|
||||||
|
@ -28,15 +28,7 @@ per-file-ignores =
|
|||||||
known-modules = libusb1:[usb1],hidapi:[hid],PyQt5:[PyQt5.QtWidgets,PyQt5.QtGui,PyQt5.QtCore],simple-rlp:[rlp]
|
known-modules = libusb1:[usb1],hidapi:[hid],PyQt5:[PyQt5.QtWidgets,PyQt5.QtGui,PyQt5.QtCore],simple-rlp:[rlp]
|
||||||
|
|
||||||
[isort]
|
[isort]
|
||||||
multi_line_output = 3
|
profile = black
|
||||||
include_trailing_comma = True
|
|
||||||
force_grid_wrap = 0
|
|
||||||
combine_as_imports = True
|
|
||||||
line_length = 88
|
|
||||||
not_skip=__init__.py
|
|
||||||
known_first_party=trezorlib
|
|
||||||
known_third_party=hidapi, rlp, ethjsonrpc, ecdsa, mnemonic, shamir_mnemonic, requests, click, pyblake2, \
|
|
||||||
usb, construct, pytest
|
|
||||||
|
|
||||||
[mypy]
|
[mypy]
|
||||||
check_untyped_defs = True
|
check_untyped_defs = True
|
||||||
|
@ -22,8 +22,8 @@ from .tools import expect, session
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
from .tools import Address
|
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
|
from .tools import Address
|
||||||
|
|
||||||
|
|
||||||
@expect(messages.BinanceAddress, field="address", ret_type=str)
|
@expect(messages.BinanceAddress, field="address", ret_type=str)
|
||||||
|
@ -27,8 +27,8 @@ from .tools import expect, prepare_message_bytes, session
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
from .tools import Address
|
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
|
from .tools import Address
|
||||||
|
|
||||||
class ScriptSig(TypedDict):
|
class ScriptSig(TypedDict):
|
||||||
asm: str
|
asm: str
|
||||||
|
@ -26,13 +26,14 @@ from ..client import TrezorClient
|
|||||||
from ..ui import ClickUI, ScriptUI
|
from ..ui import ClickUI, ScriptUI
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..transport import Transport
|
|
||||||
from ..ui import TrezorClientUI
|
|
||||||
|
|
||||||
# Needed to enforce a return value from decorators
|
# Needed to enforce a return value from decorators
|
||||||
# More details: https://www.python.org/dev/peps/pep-0612/
|
# More details: https://www.python.org/dev/peps/pep-0612/
|
||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
from typing_extensions import ParamSpec, Concatenate
|
|
||||||
|
from typing_extensions import Concatenate, ParamSpec
|
||||||
|
|
||||||
|
from ..transport import Transport
|
||||||
|
from ..ui import TrezorClientUI
|
||||||
|
|
||||||
P = ParamSpec("P")
|
P = ParamSpec("P")
|
||||||
R = TypeVar("R")
|
R = TypeVar("R")
|
||||||
|
@ -22,8 +22,8 @@ from .. import cosi, tools
|
|||||||
from . import with_client
|
from . import with_client
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..client import TrezorClient
|
|
||||||
from .. import messages
|
from .. import messages
|
||||||
|
from ..client import TrezorClient
|
||||||
|
|
||||||
PATH_HELP = "BIP-32 path, e.g. m/10018'/0'"
|
PATH_HELP = "BIP-32 path, e.g. m/10018'/0'"
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ from . import ChoiceType, with_client
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..client import TrezorClient
|
from ..client import TrezorClient
|
||||||
from . import TrezorConnection
|
|
||||||
from ..protobuf import MessageType
|
from ..protobuf import MessageType
|
||||||
|
from . import TrezorConnection
|
||||||
|
|
||||||
RECOVERY_TYPE = {
|
RECOVERY_TYPE = {
|
||||||
"scrambled": messages.RecoveryDeviceType.ScrambledWords,
|
"scrambled": messages.RecoveryDeviceType.ScrambledWords,
|
||||||
|
@ -23,8 +23,8 @@ from .. import eos, tools
|
|||||||
from . import with_client
|
from . import with_client
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..client import TrezorClient
|
|
||||||
from .. import messages
|
from .. import messages
|
||||||
|
from ..client import TrezorClient
|
||||||
|
|
||||||
PATH_HELP = "BIP-32 path, e.g. m/44'/194'/0'/0/0"
|
PATH_HELP = "BIP-32 path, e.g. m/44'/194'/0'/0/0"
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ from . import with_client
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import web3
|
import web3
|
||||||
|
|
||||||
from ..client import TrezorClient
|
from ..client import TrezorClient
|
||||||
|
|
||||||
PATH_HELP = "BIP-32 path, e.g. m/44'/60'/0'/0/0"
|
PATH_HELP = "BIP-32 path, e.g. m/44'/60'/0'/0/0"
|
||||||
|
@ -28,8 +28,8 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from stellar_sdk import (
|
from stellar_sdk import (
|
||||||
parse_transaction_envelope_from_xdr,
|
|
||||||
FeeBumpTransactionEnvelope,
|
FeeBumpTransactionEnvelope,
|
||||||
|
parse_transaction_envelope_from_xdr,
|
||||||
)
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
@ -28,8 +28,8 @@ from .tools import expect, parse_path, session
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
from .ui import TrezorClientUI
|
|
||||||
from .transport import Transport
|
from .transport import Transport
|
||||||
|
from .ui import TrezorClientUI
|
||||||
|
|
||||||
UI = TypeVar("UI", bound="TrezorClientUI")
|
UI = TypeVar("UI", bound="TrezorClientUI")
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ from .tools import expect
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
from .tools import Address
|
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
|
from .tools import Address
|
||||||
|
|
||||||
# XXX, these could be NewType's, but that would infect users of the cosi module with these types as well.
|
# XXX, these could be NewType's, but that would infect users of the cosi module with these types as well.
|
||||||
# Unsure if we want that.
|
# Unsure if we want that.
|
||||||
|
@ -51,8 +51,8 @@ from .log import DUMP_BYTES
|
|||||||
from .tools import expect
|
from .tools import expect
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .transport import Transport
|
|
||||||
from .messages import PinMatrixRequestType
|
from .messages import PinMatrixRequestType
|
||||||
|
from .transport import Transport
|
||||||
|
|
||||||
ExpectedMessage = Union[
|
ExpectedMessage = Union[
|
||||||
protobuf.MessageType, Type[protobuf.MessageType], "MessageFilter"
|
protobuf.MessageType, Type[protobuf.MessageType], "MessageFilter"
|
||||||
|
@ -22,8 +22,8 @@ from .tools import b58decode, expect, session
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
from .tools import Address
|
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
|
from .tools import Address
|
||||||
|
|
||||||
|
|
||||||
def name_to_number(name: str) -> int:
|
def name_to_number(name: str) -> int:
|
||||||
|
@ -22,8 +22,8 @@ from .tools import expect, prepare_message_bytes, session, unharden
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
from .tools import Address
|
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
|
from .tools import Address
|
||||||
|
|
||||||
|
|
||||||
def int_to_big_endian(value: int) -> bytes:
|
def int_to_big_endian(value: int) -> bytes:
|
||||||
|
@ -20,9 +20,9 @@ from . import messages
|
|||||||
from .tools import expect
|
from .tools import expect
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .tools import Address
|
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
|
from .tools import Address
|
||||||
|
|
||||||
|
|
||||||
@expect(messages.Entropy, field="entropy", ret_type=bytes)
|
@expect(messages.Entropy, field="entropy", ret_type=bytes)
|
||||||
|
@ -21,8 +21,8 @@ from .tools import expect
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
from .tools import Address
|
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
|
from .tools import Address
|
||||||
|
|
||||||
|
|
||||||
# MAINNET = 0
|
# MAINNET = 0
|
||||||
|
@ -22,8 +22,8 @@ from .tools import expect
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
from .tools import Address
|
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
|
from .tools import Address
|
||||||
|
|
||||||
TYPE_TRANSACTION_TRANSFER = 0x0101
|
TYPE_TRANSACTION_TRANSFER = 0x0101
|
||||||
TYPE_IMPORTANCE_TRANSFER = 0x0801
|
TYPE_IMPORTANCE_TRANSFER = 0x0801
|
||||||
|
@ -19,33 +19,33 @@ import sys
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtCore import QT_VERSION_STR, QRegExp, Qt
|
||||||
QPushButton,
|
|
||||||
QLineEdit,
|
|
||||||
QSizePolicy,
|
|
||||||
QLabel,
|
|
||||||
QApplication,
|
|
||||||
QWidget,
|
|
||||||
QGridLayout,
|
|
||||||
QVBoxLayout,
|
|
||||||
QHBoxLayout,
|
|
||||||
)
|
|
||||||
from PyQt5.QtGui import QRegExpValidator
|
from PyQt5.QtGui import QRegExpValidator
|
||||||
from PyQt5.QtCore import QRegExp, Qt, QT_VERSION_STR
|
from PyQt5.QtWidgets import (
|
||||||
except Exception:
|
|
||||||
from PyQt4.QtGui import ( # noqa: I
|
|
||||||
QPushButton,
|
|
||||||
QLineEdit,
|
|
||||||
QSizePolicy,
|
|
||||||
QRegExpValidator,
|
|
||||||
QLabel,
|
|
||||||
QApplication,
|
QApplication,
|
||||||
QWidget,
|
|
||||||
QGridLayout,
|
QGridLayout,
|
||||||
QVBoxLayout,
|
|
||||||
QHBoxLayout,
|
QHBoxLayout,
|
||||||
|
QLabel,
|
||||||
|
QLineEdit,
|
||||||
|
QPushButton,
|
||||||
|
QSizePolicy,
|
||||||
|
QVBoxLayout,
|
||||||
|
QWidget,
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
from PyQt4.QtCore import QT_VERSION_STR, SIGNAL, QObject, QRegExp, Qt # noqa: I
|
||||||
|
from PyQt4.QtGui import ( # noqa: I
|
||||||
|
QApplication,
|
||||||
|
QGridLayout,
|
||||||
|
QHBoxLayout,
|
||||||
|
QLabel,
|
||||||
|
QLineEdit,
|
||||||
|
QPushButton,
|
||||||
|
QRegExpValidator,
|
||||||
|
QSizePolicy,
|
||||||
|
QVBoxLayout,
|
||||||
|
QWidget,
|
||||||
)
|
)
|
||||||
from PyQt4.QtCore import QObject, SIGNAL, QRegExp, Qt, QT_VERSION_STR # noqa: I
|
|
||||||
|
|
||||||
|
|
||||||
class PinButton(QPushButton):
|
class PinButton(QPushButton):
|
||||||
|
@ -22,8 +22,8 @@ from .tools import dict_from_camelcase, expect
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
from .tools import Address
|
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
|
from .tools import Address
|
||||||
|
|
||||||
REQUIRED_FIELDS = ("Fee", "Sequence", "TransactionType", "Payment")
|
REQUIRED_FIELDS = ("Fee", "Sequence", "TransactionType", "Payment")
|
||||||
REQUIRED_PAYMENT_FIELDS = ("Amount", "Destination")
|
REQUIRED_PAYMENT_FIELDS = ("Amount", "Destination")
|
||||||
|
@ -21,8 +21,8 @@ from . import exceptions, messages
|
|||||||
from .tools import expect
|
from .tools import expect
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .protobuf import MessageType
|
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
|
from .protobuf import MessageType
|
||||||
from .tools import Address
|
from .tools import Address
|
||||||
|
|
||||||
StellarMessageType = Union[
|
StellarMessageType = Union[
|
||||||
@ -52,22 +52,22 @@ try:
|
|||||||
CreatePassiveSellOffer,
|
CreatePassiveSellOffer,
|
||||||
HashMemo,
|
HashMemo,
|
||||||
IdMemo,
|
IdMemo,
|
||||||
|
ManageBuyOffer,
|
||||||
ManageData,
|
ManageData,
|
||||||
ManageSellOffer,
|
ManageSellOffer,
|
||||||
|
MuxedAccount,
|
||||||
|
Network,
|
||||||
NoneMemo,
|
NoneMemo,
|
||||||
Operation,
|
Operation,
|
||||||
PathPaymentStrictReceive,
|
PathPaymentStrictReceive,
|
||||||
PathPaymentStrictSend,
|
PathPaymentStrictSend,
|
||||||
Payment,
|
Payment,
|
||||||
|
Price,
|
||||||
ReturnHashMemo,
|
ReturnHashMemo,
|
||||||
SetOptions,
|
SetOptions,
|
||||||
TextMemo,
|
TextMemo,
|
||||||
TransactionEnvelope,
|
TransactionEnvelope,
|
||||||
TrustLineEntryFlag,
|
TrustLineEntryFlag,
|
||||||
Price,
|
|
||||||
Network,
|
|
||||||
ManageBuyOffer,
|
|
||||||
MuxedAccount,
|
|
||||||
)
|
)
|
||||||
from stellar_sdk.xdr.signer_key_type import SignerKeyType
|
from stellar_sdk.xdr.signer_key_type import SignerKeyType
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ from .tools import expect
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
from .tools import Address
|
|
||||||
from .protobuf import MessageType
|
from .protobuf import MessageType
|
||||||
|
from .tools import Address
|
||||||
|
|
||||||
|
|
||||||
@expect(messages.TezosAddress, field="address", ret_type=str)
|
@expect(messages.TezosAddress, field="address", ret_type=str)
|
||||||
|
@ -36,13 +36,14 @@ from typing import (
|
|||||||
import construct
|
import construct
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
|
||||||
from .protobuf import MessageType
|
|
||||||
|
|
||||||
# Needed to enforce a return value from decorators
|
# Needed to enforce a return value from decorators
|
||||||
# More details: https://www.python.org/dev/peps/pep-0612/
|
# More details: https://www.python.org/dev/peps/pep-0612/
|
||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
from typing_extensions import ParamSpec, Concatenate
|
|
||||||
|
from typing_extensions import Concatenate, ParamSpec
|
||||||
|
|
||||||
|
from .client import TrezorClient
|
||||||
|
from .protobuf import MessageType
|
||||||
|
|
||||||
MT = TypeVar("MT", bound=MessageType)
|
MT = TypeVar("MT", bound=MessageType)
|
||||||
P = ParamSpec("P")
|
P = ParamSpec("P")
|
||||||
|
Loading…
Reference in New Issue
Block a user