1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-17 21:22:10 +00:00
trezor-firmware/setup.py
matejcik ce7a434f2d build: add the prebuild command as a dependency for develop
So, 'python setup.py develop' exists. And of course it doesn't have build_py as
a dependency, because of course it doesn't.
We could use 'data_files' instead of 'package_data and copying', and then use
pkg_resources to find the actual file location, and that could work in theory.
But pkg_resources API is weird and messy and this whole area of Python
packaging theory barely works as it is.

Instead we will force the prebuild command to be a dependency of develop as
well as build_py, and we do this by monkey-patching instead of the proper way,
because at this point it seems cleaner. I wonder if there are more commands
that would need this.
2018-05-03 18:55:32 +02:00

114 lines
3.0 KiB
Python
Executable File

#!/usr/bin/env python3
import os.path
import shutil
import subprocess
from setuptools import setup, Command
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
install_requires = [
'setuptools>=19.0',
'ecdsa>=0.9',
'mnemonic>=0.17',
'requests>=2.4.0',
'click>=6.2',
'pyblake2>=0.9.3',
'rlp>=0.6.0',
]
import sys
if '--disable-hidapi' in sys.argv:
sys.argv.remove('--disable-hidapi')
else:
install_requires.append('hidapi>=0.7.99.post20')
if '--disable-libusb' in sys.argv:
sys.argv.remove('--disable-libusb')
else:
install_requires.append('libusb1>=1.6.4')
from trezorlib import __version__ as VERSION
class PrebuildCommand(Command):
description = 'update vendored files (coins.json, protobuf messages)'
user_options = []
TREZOR_COMMON = os.path.join('vendor', 'trezor-common')
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# check for existence of the submodule directory
coins_json = os.path.join(self.TREZOR_COMMON, 'coins.json')
if not os.path.exists(coins_json):
raise Exception('trezor-common submodule seems to be missing.\n' +
'Use "git submodule update --init" to retrieve it.')
# copy coins.json to the tree
shutil.copy(coins_json, 'trezorlib')
# regenerate messages
try:
subprocess.check_call(os.path.join(os.getcwd(), 'tools', 'build_protobuf'))
except Exception as e:
print(e)
print("Generating protobuf failed. Maybe you don't have 'protoc', or maybe you are on Windows?")
print("Using pre-generated files.")
def _patch_prebuild(cls):
"""Patch a setuptools command to depend on `prebuild`"""
orig_run = cls.run
def new_run(self):
self.run_command('prebuild')
orig_run(self)
cls.run = new_run
_patch_prebuild(build_py)
_patch_prebuild(develop)
setup(
name='trezor',
version=VERSION,
author='TREZOR',
author_email='info@trezor.io',
description='Python library for communicating with TREZOR Hardware Wallet',
url='https://github.com/trezor/python-trezor',
packages=[
'trezorlib',
'trezorlib.transport',
'trezorlib.messages',
'trezorlib.qt',
'trezorlib.tests.device_tests',
'trezorlib.tests.unit_tests',
],
package_data={
'trezorlib': ['coins.json'],
},
scripts=['trezorctl'],
install_requires=install_requires,
python_requires='>=3.3',
include_package_data=True,
zip_safe=False,
classifiers=[
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
'Operating System :: POSIX :: Linux',
'Operating System :: Microsoft :: Windows',
'Operating System :: MacOS :: MacOS X',
'Programming Language :: Python :: 3 :: Only',
],
cmdclass={
'prebuild': PrebuildCommand,
},
)