style(python): implement isort 5 for trezorlib

[no changelog]
grdddj/ruff_linter
matejcik 10 months ago committed by matejcik
parent a12bc416ed
commit 821d70dd8d

@ -3,7 +3,6 @@ SETUP=$(PYTHON) setup.py
EXCLUDES=.vscode
STYLE_TARGETS=src/trezorlib setup.py
EXCLUDE_TARGETS=messages
all: build
@ -46,20 +45,20 @@ git-clean:
style:
black $(STYLE_TARGETS)
isort --apply --recursive $(STYLE_TARGETS) --skip-glob "$(EXCLUDE_TARGETS)/*"
autoflake -i --remove-all-unused-imports -r $(STYLE_TARGETS) --exclude "$(EXCLUDE_TARGETS)"
isort --apply --recursive $(STYLE_TARGETS)
autoflake -i --remove-all-unused-imports -r $(STYLE_TARGETS)
flake8
make pyright
style_check:
black --check $(STYLE_TARGETS)
isort --check-only --recursive $(STYLE_TARGETS) --skip-glob "$(EXCLUDE_TARGETS)/*"
isort --check-only $(STYLE_TARGETS)
flake8
make pyright
style_quick_check:
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

@ -28,15 +28,7 @@ per-file-ignores =
known-modules = libusb1:[usb1],hidapi:[hid],PyQt5:[PyQt5.QtWidgets,PyQt5.QtGui,PyQt5.QtCore],simple-rlp:[rlp]
[isort]
multi_line_output = 3
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
profile = black
[mypy]
check_untyped_defs = True

@ -22,8 +22,8 @@ from .tools import expect, session
if TYPE_CHECKING:
from .client import TrezorClient
from .tools import Address
from .protobuf import MessageType
from .tools import Address
@expect(messages.BinanceAddress, field="address", ret_type=str)

@ -27,8 +27,8 @@ from .tools import expect, prepare_message_bytes, session
if TYPE_CHECKING:
from .client import TrezorClient
from .tools import Address
from .protobuf import MessageType
from .tools import Address
class ScriptSig(TypedDict):
asm: str

@ -26,13 +26,14 @@ from ..client import TrezorClient
from ..ui import ClickUI, ScriptUI
if TYPE_CHECKING:
from ..transport import Transport
from ..ui import TrezorClientUI
# Needed to enforce a return value from decorators
# More details: https://www.python.org/dev/peps/pep-0612/
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")
R = TypeVar("R")

@ -22,8 +22,8 @@ from .. import cosi, tools
from . import with_client
if TYPE_CHECKING:
from ..client import TrezorClient
from .. import messages
from ..client import TrezorClient
PATH_HELP = "BIP-32 path, e.g. m/10018'/0'"

@ -24,8 +24,8 @@ from . import ChoiceType, with_client
if TYPE_CHECKING:
from ..client import TrezorClient
from . import TrezorConnection
from ..protobuf import MessageType
from . import TrezorConnection
RECOVERY_TYPE = {
"scrambled": messages.RecoveryDeviceType.ScrambledWords,

@ -23,8 +23,8 @@ from .. import eos, tools
from . import with_client
if TYPE_CHECKING:
from ..client import TrezorClient
from .. import messages
from ..client import TrezorClient
PATH_HELP = "BIP-32 path, e.g. m/44'/194'/0'/0/0"

@ -40,6 +40,7 @@ from . import with_client
if TYPE_CHECKING:
import web3
from ..client import TrezorClient
PATH_HELP = "BIP-32 path, e.g. m/44'/60'/0'/0/0"

@ -28,8 +28,8 @@ if TYPE_CHECKING:
try:
from stellar_sdk import (
parse_transaction_envelope_from_xdr,
FeeBumpTransactionEnvelope,
parse_transaction_envelope_from_xdr,
)
except ImportError:
pass

@ -28,8 +28,8 @@ from .tools import expect, parse_path, session
if TYPE_CHECKING:
from .protobuf import MessageType
from .ui import TrezorClientUI
from .transport import Transport
from .ui import TrezorClientUI
UI = TypeVar("UI", bound="TrezorClientUI")

@ -23,8 +23,8 @@ from .tools import expect
if TYPE_CHECKING:
from .client import TrezorClient
from .tools import Address
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.
# Unsure if we want that.

@ -51,8 +51,8 @@ from .log import DUMP_BYTES
from .tools import expect
if TYPE_CHECKING:
from .transport import Transport
from .messages import PinMatrixRequestType
from .transport import Transport
ExpectedMessage = Union[
protobuf.MessageType, Type[protobuf.MessageType], "MessageFilter"

@ -22,8 +22,8 @@ from .tools import b58decode, expect, session
if TYPE_CHECKING:
from .client import TrezorClient
from .tools import Address
from .protobuf import MessageType
from .tools import Address
def name_to_number(name: str) -> int:

@ -22,8 +22,8 @@ from .tools import expect, prepare_message_bytes, session, unharden
if TYPE_CHECKING:
from .client import TrezorClient
from .tools import Address
from .protobuf import MessageType
from .tools import Address
def int_to_big_endian(value: int) -> bytes:

@ -20,9 +20,9 @@ from . import messages
from .tools import expect
if TYPE_CHECKING:
from .tools import Address
from .client import TrezorClient
from .protobuf import MessageType
from .tools import Address
@expect(messages.Entropy, field="entropy", ret_type=bytes)

@ -21,8 +21,8 @@ from .tools import expect
if TYPE_CHECKING:
from .client import TrezorClient
from .tools import Address
from .protobuf import MessageType
from .tools import Address
# MAINNET = 0

@ -22,8 +22,8 @@ from .tools import expect
if TYPE_CHECKING:
from .client import TrezorClient
from .tools import Address
from .protobuf import MessageType
from .tools import Address
TYPE_TRANSACTION_TRANSFER = 0x0101
TYPE_IMPORTANCE_TRANSFER = 0x0801

@ -19,33 +19,33 @@ import sys
from typing import Any
try:
from PyQt5.QtCore import QT_VERSION_STR, QRegExp, Qt
from PyQt5.QtGui import QRegExpValidator
from PyQt5.QtWidgets import (
QPushButton,
QLineEdit,
QSizePolicy,
QLabel,
QApplication,
QWidget,
QGridLayout,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QPushButton,
QSizePolicy,
QVBoxLayout,
QWidget,
)
from PyQt5.QtGui import QRegExpValidator
from PyQt5.QtCore import QRegExp, Qt, QT_VERSION_STR
except Exception:
from PyQt4.QtCore import QT_VERSION_STR, SIGNAL, QObject, QRegExp, Qt # noqa: I
from PyQt4.QtGui import ( # noqa: I
QPushButton,
QLineEdit,
QSizePolicy,
QRegExpValidator,
QLabel,
QApplication,
QWidget,
QGridLayout,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QPushButton,
QRegExpValidator,
QSizePolicy,
QVBoxLayout,
QWidget,
)
from PyQt4.QtCore import QObject, SIGNAL, QRegExp, Qt, QT_VERSION_STR # noqa: I
class PinButton(QPushButton):

@ -22,8 +22,8 @@ from .tools import dict_from_camelcase, expect
if TYPE_CHECKING:
from .client import TrezorClient
from .tools import Address
from .protobuf import MessageType
from .tools import Address
REQUIRED_FIELDS = ("Fee", "Sequence", "TransactionType", "Payment")
REQUIRED_PAYMENT_FIELDS = ("Amount", "Destination")

@ -21,8 +21,8 @@ from . import exceptions, messages
from .tools import expect
if TYPE_CHECKING:
from .protobuf import MessageType
from .client import TrezorClient
from .protobuf import MessageType
from .tools import Address
StellarMessageType = Union[
@ -52,22 +52,22 @@ try:
CreatePassiveSellOffer,
HashMemo,
IdMemo,
ManageBuyOffer,
ManageData,
ManageSellOffer,
MuxedAccount,
Network,
NoneMemo,
Operation,
PathPaymentStrictReceive,
PathPaymentStrictSend,
Payment,
Price,
ReturnHashMemo,
SetOptions,
TextMemo,
TransactionEnvelope,
TrustLineEntryFlag,
Price,
Network,
ManageBuyOffer,
MuxedAccount,
)
from stellar_sdk.xdr.signer_key_type import SignerKeyType

@ -21,8 +21,8 @@ from .tools import expect
if TYPE_CHECKING:
from .client import TrezorClient
from .tools import Address
from .protobuf import MessageType
from .tools import Address
@expect(messages.TezosAddress, field="address", ret_type=str)

@ -36,13 +36,14 @@ from typing import (
import construct
if TYPE_CHECKING:
from .client import TrezorClient
from .protobuf import MessageType
# Needed to enforce a return value from decorators
# More details: https://www.python.org/dev/peps/pep-0612/
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)
P = ParamSpec("P")

Loading…
Cancel
Save