1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

python: restructure package

This deserves some explanation.

* tests were moved to separate python/tests subdir
* trezorlib was moved to python/src, so that it does not exist on
PYTHONPATH by default
(see https://blog.ionelmc.ro/2014/05/25/python-packaging/ for details)
* everything was updated to understand the new structure
* trezorctl was changed from a top-level executable script to a module
`trezorlib.cli.trezorctl` and is installed via the entry_points
mechanism.
This should make it work normally on Windows!

The package should be installable as normal through pip and pipenv, no
changes are needed on that side.

The source package from pypi will include unit tests. (Device tests were
completely moved out). Wheel will exclude them, because users don't need
them.
That shrinks the .whl from 520 kB to 270 - nice!

python: reorganize remaining unit tests
This commit is contained in:
matejcik 2019-08-06 16:26:23 +02:00 committed by matejcik
parent 0470cf9865
commit 67b879ac07
328 changed files with 35 additions and 58 deletions

2
python/.gitignore vendored
View File

@ -3,7 +3,7 @@
MANIFEST MANIFEST
/build /build
/dist /dist
/trezor.egg-info *.egg-info
*.bin *.bin
*.py.cache *.py.cache
/.tox /.tox

View File

@ -1,6 +1,7 @@
recursive-include bash_completion.d *.sh recursive-include bash_completion.d *.sh
include tools/* include tools/*
recursive-include trezorlib * graft src
graft tests
include AUTHORS README.md COPYING CHANGELOG.md include AUTHORS README.md COPYING CHANGELOG.md
include requirements*.txt include requirements*.txt

View File

@ -2,14 +2,14 @@ PYTHON=python3
SETUP=$(PYTHON) setup.py SETUP=$(PYTHON) setup.py
EXCLUDES=.vscode EXCLUDES=.vscode
STYLE_TARGETS=trezorlib trezorctl setup.py STYLE_TARGETS=src/trezorlib setup.py
EXCLUDE_TARGETS=messages EXCLUDE_TARGETS=messages
all: build all: build
clean-gen: ## remove generated files clean-gen: ## remove generated files
rm -f trezorlib/messages/*.py rm -f src/trezorlib/messages/*.py
rm -f trezorlib/coins.json rm -f src/trezorlib/coins.json
coins_json: coins_json:
./helper-scripts/build-coins-json.sh ./helper-scripts/build-coins-json.sh

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
cd $(dirname $0)/.. cd $(dirname $0)/..
DEST=trezorlib/coins.json DEST=src/trezorlib/coins.json
BUILD_COINS_AT="../common/tools/cointool.py dump \ BUILD_COINS_AT="../common/tools/cointool.py dump \
--list --support \ --list --support \

View File

@ -1,13 +1,11 @@
[flake8] [flake8]
filename = filename = *.py
*.py,
./trezorctl
exclude = exclude =
.tox/, .tox/,
build/, build/,
dist/, dist/,
vendor/, vendor/,
trezorlib/messages/__init__.py src/trezorlib/messages/__init__.py
ignore = ignore =
# E203 whitespace before ':' # E203 whitespace before ':'
E203, E203,

View File

@ -28,7 +28,7 @@ def read(*path):
def find_version(): def find_version():
version_file = read("trezorlib", "__init__.py") version_file = read("src", "trezorlib", "__init__.py")
version_match = re.search(r"^__version__ = \"(.*)\"$", version_file, re.M) version_match = re.search(r"^__version__ = \"(.*)\"$", version_file, re.M)
if version_match: if version_match:
return version_match.group(1) return version_match.group(1)
@ -60,9 +60,10 @@ setup(
long_description="{}\n\n{}".format(read("README.md"), read("CHANGELOG.md")), long_description="{}\n\n{}".format(read("README.md"), read("CHANGELOG.md")),
long_description_content_type="text/markdown", long_description_content_type="text/markdown",
url="https://github.com/trezor/python-trezor", url="https://github.com/trezor/python-trezor",
packages=find_packages(), packages=find_packages("src"),
package_dir={"": "src"},
package_data={"trezorlib": ["coins.json"]}, package_data={"trezorlib": ["coins.json"]},
scripts=["trezorctl"], entry_points={"console_scripts": ["trezorctl=trezorlib.cli.trezorctl:cli"]},
install_requires=install_requires, install_requires=install_requires,
extras_require={ extras_require={
"hidapi": ["hidapi>=0.7.99.post20"], "hidapi": ["hidapi>=0.7.99.post20"],

View File

@ -17,6 +17,7 @@
import hashlib import hashlib
import hmac import hmac
import struct import struct
import warnings
import ecdsa import ecdsa
from ecdsa.curves import SECP256k1 from ecdsa.curves import SECP256k1
@ -25,6 +26,8 @@ from ecdsa.util import number_to_string, string_to_number
from trezorlib import messages, tools from trezorlib import messages, tools
warnings.warn("ckd_public module is deprecated and will be removed", DeprecationWarning)
def point_to_pubkey(point): def point_to_pubkey(point):
order = SECP256k1.order order = SECP256k1.order

Some files were not shown because too many files have changed in this diff Show More