From 88b50ac2ffb4c3106886861c3871b10831f5915f Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 21 Aug 2018 16:21:49 +0200 Subject: [PATCH] style: add makefile with style targets, final touchups --- .travis.yml | 5 ++--- Makefile | 27 ++++++++++++++++++++++++ requirements-dev.txt | 3 +++ trezorctl | 17 ++++++++------- trezorlib/lisk.py | 3 +-- trezorlib/ripple.py | 2 +- trezorlib/tests/device_tests/conftest.py | 5 +++-- 7 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 Makefile diff --git a/.travis.yml b/.travis.yml index 7e79071fbe..16f466403c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,19 +30,18 @@ install: - pip install "setuptools>=38" # setuptools >= 38 are capable of using prebuilt wheels - pip install "virtualenv<16.0.0" # virtualenv 16.0.0 drops support for py33 without properly declaring it - pip install tox-travis - - pip install flake8 + - pip install -r requirements-dev.txt # protobuf-related dependencies - curl -LO "https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip" - unzip "protoc-${PROTOBUF_VERSION}-linux-x86_64.zip" -d protoc - export PATH="$(pwd)/protoc/bin:$PATH" - - pip install "protobuf == ${PROTOBUF_VERSION}" before_script: - ./trigger-travis.sh script: - python setup.py install - - flake8 + - make stylecheck - tox notifications: diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..437f683761 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +PYTHON=python3 +SETUP=$(PYTHON) setup.py + +EXCLUDES=.vscode +STYLE_TARGETS=trezorlib trezorctl +EXCLUDE_TARGETS=trezorlib/messages + +all: build + +build: + $(SETUP) build + +install: + $(SETUP) install + +clean: + git clean -dfx -e $(EXCLUDES) + +style: + black $(STYLE_TARGETS) + isort --apply --recursive $(STYLE_TARGETS) --skip-glob "*/$(EXCLUDE_TARGETS)/*" + autoflake -i --remove-all-unused-imports -r $(STYLE_TARGETS) + +stylecheck: + black --check $(STYLE_TARGETS) + isort --check-only --recursive $(STYLE_TARGETS) --skip-glob "*/$(EXCLUDE_TARGETS)/*" + flake8 diff --git a/requirements-dev.txt b/requirements-dev.txt index ebd11f7ecc..494ad11d4e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,3 +4,6 @@ pytest>=3.2.5 mock>=2.0.0 flake8 protobuf +isort +black +autoflake diff --git a/trezorctl b/trezorctl index 07888023b4..75208a4c3d 100755 --- a/trezorctl +++ b/trezorctl @@ -22,33 +22,34 @@ import base64 import binascii -import click import hashlib import io import json import os import sys -from trezorlib.client import TrezorClient -from trezorlib.transport import get_transport, enumerate_devices -from trezorlib import coins -from trezorlib import log -from trezorlib import messages as proto +import click + from trezorlib import ( btc, + coins, cosi, debuglink, device, ethereum, firmware, lisk, + log, + messages as proto, misc, nem, + protobuf, ripple, stellar, + tools, ) -from trezorlib import protobuf -from trezorlib import tools +from trezorlib.client import TrezorClient +from trezorlib.transport import enumerate_devices, get_transport class ChoiceType(click.Choice): diff --git a/trezorlib/lisk.py b/trezorlib/lisk.py index 5be22c1a8c..fe571c6062 100644 --- a/trezorlib/lisk.py +++ b/trezorlib/lisk.py @@ -1,8 +1,7 @@ -import binascii from . import messages as proto -from .tools import CallException, expect, normalize_nfc, dict_from_camelcase from .protobuf import dict_to_proto +from .tools import CallException, dict_from_camelcase, expect, normalize_nfc @expect(proto.LiskAddress, field="address") diff --git a/trezorlib/ripple.py b/trezorlib/ripple.py index 3b8cfad887..113ca9acd8 100644 --- a/trezorlib/ripple.py +++ b/trezorlib/ripple.py @@ -16,8 +16,8 @@ from . import messages -from .tools import expect, dict_from_camelcase from .protobuf import dict_to_proto +from .tools import dict_from_camelcase, expect REQUIRED_FIELDS = ("Fee", "Sequence", "TransactionType", "Amount", "Destination") diff --git a/trezorlib/tests/device_tests/conftest.py b/trezorlib/tests/device_tests/conftest.py index a345805348..25d84c59d8 100644 --- a/trezorlib/tests/device_tests/conftest.py +++ b/trezorlib/tests/device_tests/conftest.py @@ -16,11 +16,12 @@ import functools import os + import pytest -from trezorlib.transport import get_transport, enumerate_devices +from trezorlib import coins, log from trezorlib.client import TrezorClient, TrezorClientDebugLink -from trezorlib import log, coins +from trezorlib.transport import enumerate_devices, get_transport TREZOR_VERSION = None