pylint and mypy fixes
This commit is contained in:
parent
f60435c878
commit
48d7bfd225
5 changed files with 60 additions and 55 deletions
|
@ -6,17 +6,18 @@ source =
|
||||||
torba
|
torba
|
||||||
.tox/*/lib/python*/site-packages/torba
|
.tox/*/lib/python*/site-packages/torba
|
||||||
|
|
||||||
[mypy-twisted.*,cryptography.*,coincurve.*,pbkdf2]
|
[cryptography.*,coincurve.*,pbkdf2]
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
|
|
||||||
[pylint]
|
[pylint]
|
||||||
ignore=words,server
|
ignore=words,server,workbench
|
||||||
max-args=10
|
max-args=10
|
||||||
max-line-length=110
|
max-line-length=110
|
||||||
good-names=T,t,n,i,j,k,x,y,s,f,d,h,c,e,op,db,tx,io,cachedproperty,log,id
|
good-names=T,t,n,i,j,k,x,y,s,f,d,h,c,e,op,db,tx,io,cachedproperty,log,id
|
||||||
valid-metaclass-classmethod-first-arg=mcs
|
valid-metaclass-classmethod-first-arg=mcs
|
||||||
disable=
|
disable=
|
||||||
fixme,
|
fixme,
|
||||||
|
broad-except,
|
||||||
no-else-return,
|
no-else-return,
|
||||||
cyclic-import,
|
cyclic-import,
|
||||||
missing-docstring,
|
missing-docstring,
|
||||||
|
|
|
@ -13,9 +13,9 @@ def get_argument_parser():
|
||||||
)
|
)
|
||||||
subparsers = parser.add_subparsers(dest='command', help='sub-command help')
|
subparsers = parser.add_subparsers(dest='command', help='sub-command help')
|
||||||
|
|
||||||
gui = subparsers.add_parser("gui", help="Start Qt GUI.")
|
subparsers.add_parser("gui", help="Start Qt GUI.")
|
||||||
|
|
||||||
download = subparsers.add_parser("download", help="Download blockchain node binary.")
|
subparsers.add_parser("download", help="Download blockchain node binary.")
|
||||||
|
|
||||||
start = subparsers.add_parser("start", help="Start orchstr8 service.")
|
start = subparsers.add_parser("start", help="Start orchstr8 service.")
|
||||||
start.add_argument("--blockchain", help="Start blockchain node.", action="store_true")
|
start.add_argument("--blockchain", help="Start blockchain node.", action="store_true")
|
||||||
|
@ -25,7 +25,7 @@ def get_argument_parser():
|
||||||
generate = subparsers.add_parser("generate", help="Call generate method on running orchstr8 instance.")
|
generate = subparsers.add_parser("generate", help="Call generate method on running orchstr8 instance.")
|
||||||
generate.add_argument("blocks", type=int, help="Number of blocks to generate")
|
generate.add_argument("blocks", type=int, help="Number of blocks to generate")
|
||||||
|
|
||||||
transfer = subparsers.add_parser("transfer", help="Call transfer method on running orchstr8 instance.")
|
subparsers.add_parser("transfer", help="Call transfer method on running orchstr8 instance.")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import shutil
|
import shutil
|
||||||
import asyncio
|
import asyncio
|
||||||
import zipfile
|
import zipfile
|
||||||
|
@ -8,9 +7,10 @@ import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
import importlib
|
import importlib
|
||||||
import requests
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from typing import Type
|
from typing import Type, Optional
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
from torba.server.server import Server
|
from torba.server.server import Server
|
||||||
from torba.server.env import Env
|
from torba.server.env import Env
|
||||||
|
@ -19,12 +19,6 @@ from torba.baseledger import BaseLedger, BlockHeightEvent
|
||||||
from torba.basemanager import BaseWalletManager
|
from torba.basemanager import BaseWalletManager
|
||||||
from torba.baseaccount import BaseAccount
|
from torba.baseaccount import BaseAccount
|
||||||
|
|
||||||
root = logging.getLogger()
|
|
||||||
ch = logging.StreamHandler(sys.stdout)
|
|
||||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
||||||
ch.setFormatter(formatter)
|
|
||||||
root.addHandler(ch)
|
|
||||||
|
|
||||||
|
|
||||||
def get_manager_from_environment(default_manager=BaseWalletManager):
|
def get_manager_from_environment(default_manager=BaseWalletManager):
|
||||||
if 'TORBA_MANAGER' not in os.environ:
|
if 'TORBA_MANAGER' not in os.environ:
|
||||||
|
@ -122,17 +116,17 @@ class WalletNode:
|
||||||
self.manager_class = manager_class
|
self.manager_class = manager_class
|
||||||
self.ledger_class = ledger_class
|
self.ledger_class = ledger_class
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
self.manager: BaseWalletManager = None
|
self.manager: Optional[BaseWalletManager] = None
|
||||||
self.ledger: BaseLedger = None
|
self.ledger: Optional[BaseLedger] = None
|
||||||
self.wallet: Wallet = None
|
self.wallet: Optional[Wallet] = None
|
||||||
self.account: BaseAccount = None
|
self.account: Optional[BaseAccount] = None
|
||||||
self.data_path: str = None
|
self.data_path: Optional[str] = None
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
self.data_path = tempfile.mkdtemp()
|
self.data_path = tempfile.mkdtemp()
|
||||||
wallet_file_name = os.path.join(self.data_path, 'my_wallet.json')
|
wallet_file_name = os.path.join(self.data_path, 'my_wallet.json')
|
||||||
with open(wallet_file_name, 'w') as wf:
|
with open(wallet_file_name, 'w') as wallet_file:
|
||||||
wf.write('{"version": 1, "accounts": []}\n')
|
wallet_file.write('{"version": 1, "accounts": []}\n')
|
||||||
self.manager = self.manager_class.from_config({
|
self.manager = self.manager_class.from_config({
|
||||||
'ledgers': {
|
'ledgers': {
|
||||||
self.ledger_class.get_id(): {
|
self.ledger_class.get_id(): {
|
||||||
|
@ -164,6 +158,7 @@ class SPVNode:
|
||||||
self.coin_class = coin_class
|
self.coin_class = coin_class
|
||||||
self.controller = None
|
self.controller = None
|
||||||
self.data_path = None
|
self.data_path = None
|
||||||
|
self.server = None
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
self.data_path = tempfile.mkdtemp()
|
self.data_path = tempfile.mkdtemp()
|
||||||
|
@ -253,15 +248,15 @@ class BlockchainNode:
|
||||||
|
|
||||||
if not os.path.exists(downloaded_file):
|
if not os.path.exists(downloaded_file):
|
||||||
self.log.info('Downloading: %s', self.latest_release_url)
|
self.log.info('Downloading: %s', self.latest_release_url)
|
||||||
r = requests.get(self.latest_release_url, stream=True)
|
response = requests.get(self.latest_release_url, stream=True)
|
||||||
with open(downloaded_file, 'wb') as f:
|
with open(downloaded_file, 'wb') as f:
|
||||||
shutil.copyfileobj(r.raw, f)
|
shutil.copyfileobj(response.raw, f)
|
||||||
|
|
||||||
self.log.info('Extracting: %s', downloaded_file)
|
self.log.info('Extracting: %s', downloaded_file)
|
||||||
|
|
||||||
if downloaded_file.endswith('.zip'):
|
if downloaded_file.endswith('.zip'):
|
||||||
with zipfile.ZipFile(downloaded_file) as zf:
|
with zipfile.ZipFile(downloaded_file) as dotzip:
|
||||||
zf.extractall(self.bin_dir)
|
dotzip.extractall(self.bin_dir)
|
||||||
# zipfile bug https://bugs.python.org/issue15795
|
# zipfile bug https://bugs.python.org/issue15795
|
||||||
os.chmod(self.cli_bin, 0o755)
|
os.chmod(self.cli_bin, 0o755)
|
||||||
os.chmod(self.daemon_bin, 0o755)
|
os.chmod(self.daemon_bin, 0o755)
|
||||||
|
@ -314,7 +309,7 @@ class BlockchainNode:
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
*cmnd_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
*cmnd_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||||
)
|
)
|
||||||
out, err = await process.communicate()
|
out, _ = await process.communicate()
|
||||||
self.log.info(out.decode().strip())
|
self.log.info(out.decode().strip())
|
||||||
return out.decode().strip()
|
return out.decode().strip()
|
||||||
|
|
||||||
|
@ -322,8 +317,8 @@ class BlockchainNode:
|
||||||
self._block_expected += blocks
|
self._block_expected += blocks
|
||||||
return self._cli_cmnd('generate', str(blocks))
|
return self._cli_cmnd('generate', str(blocks))
|
||||||
|
|
||||||
def invalidateblock(self, hash):
|
def invalidateblock(self, blockhash):
|
||||||
return self._cli_cmnd('invalidateblock', hash)
|
return self._cli_cmnd('invalidateblock', blockhash)
|
||||||
|
|
||||||
def get_raw_change_address(self):
|
def get_raw_change_address(self):
|
||||||
return self._cli_cmnd('getrawchangeaddress')
|
return self._cli_cmnd('getrawchangeaddress')
|
||||||
|
@ -331,8 +326,8 @@ class BlockchainNode:
|
||||||
async def get_balance(self):
|
async def get_balance(self):
|
||||||
return float(await self._cli_cmnd('getbalance'))
|
return float(await self._cli_cmnd('getbalance'))
|
||||||
|
|
||||||
def send_to_address(self, address, credits):
|
def send_to_address(self, address, amount):
|
||||||
return self._cli_cmnd('sendtoaddress', address, str(credits))
|
return self._cli_cmnd('sendtoaddress', address, str(amount))
|
||||||
|
|
||||||
def send_raw_transaction(self, tx):
|
def send_raw_transaction(self, tx):
|
||||||
return self._cli_cmnd('sendrawtransaction', tx.decode())
|
return self._cli_cmnd('sendrawtransaction', tx.decode())
|
||||||
|
|
|
@ -27,7 +27,7 @@ class WebSocketLogHandler(logging.Handler):
|
||||||
|
|
||||||
class TestingServiceAPI:
|
class TestingServiceAPI:
|
||||||
|
|
||||||
def __init__(self, stack: Conductor, loop: asyncio.AbstractEventLoop):
|
def __init__(self, stack: Conductor, loop: asyncio.AbstractEventLoop) -> None:
|
||||||
self.stack = stack
|
self.stack = stack
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
self.app = Application()
|
self.app = Application()
|
||||||
|
@ -112,25 +112,25 @@ class TestingServiceAPI:
|
||||||
})
|
})
|
||||||
|
|
||||||
async def log(self, request):
|
async def log(self, request):
|
||||||
ws = WebSocketResponse()
|
web_socket = WebSocketResponse()
|
||||||
await ws.prepare(request)
|
await web_socket.prepare(request)
|
||||||
self.app['websockets'].add(ws)
|
self.app['websockets'].add(web_socket)
|
||||||
try:
|
try:
|
||||||
async for msg in ws:
|
async for msg in web_socket:
|
||||||
if msg.type == WSMsgType.TEXT:
|
if msg.type == WSMsgType.TEXT:
|
||||||
if msg.data == 'close':
|
if msg.data == 'close':
|
||||||
await ws.close()
|
await web_socket.close()
|
||||||
elif msg.type == WSMsgType.ERROR:
|
elif msg.type == WSMsgType.ERROR:
|
||||||
print('ws connection closed with exception %s' %
|
print('web socket connection closed with exception %s' %
|
||||||
ws.exception())
|
web_socket.exception())
|
||||||
finally:
|
finally:
|
||||||
self.app['websockets'].remove(ws)
|
self.app['websockets'].remove(web_socket)
|
||||||
return ws
|
return web_socket
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def on_shutdown(app):
|
async def on_shutdown(app):
|
||||||
for ws in app['websockets']:
|
for web_socket in app['websockets']:
|
||||||
await ws.close(code=WSCloseCode.GOING_AWAY, message='Server shutdown')
|
await web_socket.close(code=WSCloseCode.GOING_AWAY, message='Server shutdown')
|
||||||
|
|
||||||
async def on_status(self, _):
|
async def on_status(self, _):
|
||||||
if not self.app['websockets']:
|
if not self.app['websockets']:
|
||||||
|
@ -143,5 +143,5 @@ class TestingServiceAPI:
|
||||||
})
|
})
|
||||||
|
|
||||||
def send_message(self, msg):
|
def send_message(self, msg):
|
||||||
for ws in self.app['websockets']:
|
for web_socket in self.app['websockets']:
|
||||||
asyncio.ensure_future(ws.send_json(msg))
|
asyncio.ensure_future(web_socket.send_json(msg))
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import unittest
|
|
||||||
import logging
|
import logging
|
||||||
|
import unittest
|
||||||
from unittest.case import _Outcome
|
from unittest.case import _Outcome
|
||||||
from .node import Conductor
|
from .node import Conductor
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from asyncio.runners import _cancel_all_tasks
|
from asyncio.runners import _cancel_all_tasks # pylint: disable=C0412
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# this is only available in py3.7
|
# this is only available in py3.7
|
||||||
def _cancel_all_tasks(loop):
|
def _cancel_all_tasks(loop):
|
||||||
|
@ -17,26 +17,26 @@ class AsyncioTestCase(unittest.TestCase):
|
||||||
# Implementation inspired by discussion:
|
# Implementation inspired by discussion:
|
||||||
# https://bugs.python.org/issue32972
|
# https://bugs.python.org/issue32972
|
||||||
|
|
||||||
async def asyncSetUp(self):
|
async def asyncSetUp(self): # pylint: disable=C0103
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def asyncTearDown(self):
|
async def asyncTearDown(self): # pylint: disable=C0103
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def doAsyncCleanups(self):
|
async def doAsyncCleanups(self): # pylint: disable=C0103
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self, result=None):
|
def run(self, result=None): # pylint: disable=R0915
|
||||||
orig_result = result
|
orig_result = result
|
||||||
if result is None:
|
if result is None:
|
||||||
result = self.defaultTestResult()
|
result = self.defaultTestResult()
|
||||||
startTestRun = getattr(result, 'startTestRun', None)
|
startTestRun = getattr(result, 'startTestRun', None) # pylint: disable=C0103
|
||||||
if startTestRun is not None:
|
if startTestRun is not None:
|
||||||
startTestRun()
|
startTestRun()
|
||||||
|
|
||||||
result.startTest(self)
|
result.startTest(self)
|
||||||
|
|
||||||
testMethod = getattr(self, self._testMethodName)
|
testMethod = getattr(self, self._testMethodName) # pylint: disable=C0103
|
||||||
if (getattr(self.__class__, "__unittest_skip__", False) or
|
if (getattr(self.__class__, "__unittest_skip__", False) or
|
||||||
getattr(testMethod, "__unittest_skip__", False)):
|
getattr(testMethod, "__unittest_skip__", False)):
|
||||||
# If the class or method was skipped.
|
# If the class or method was skipped.
|
||||||
|
@ -99,9 +99,9 @@ class AsyncioTestCase(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
result.stopTest(self)
|
result.stopTest(self)
|
||||||
if orig_result is None:
|
if orig_result is None:
|
||||||
stopTestRun = getattr(result, 'stopTestRun', None)
|
stopTestRun = getattr(result, 'stopTestRun', None) # pylint: disable=C0103
|
||||||
if stopTestRun is not None:
|
if stopTestRun is not None:
|
||||||
stopTestRun()
|
stopTestRun() # pylint: disable=E1102
|
||||||
|
|
||||||
# explicitly break reference cycles:
|
# explicitly break reference cycles:
|
||||||
# outcome.errors -> frame -> outcome -> outcome.errors
|
# outcome.errors -> frame -> outcome -> outcome.errors
|
||||||
|
@ -119,6 +119,15 @@ class IntegrationTestCase(AsyncioTestCase):
|
||||||
MANAGER = None
|
MANAGER = None
|
||||||
VERBOSITY = logging.WARNING
|
VERBOSITY = logging.WARNING
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.conductor = None
|
||||||
|
self.blockchain = None
|
||||||
|
self.manager = None
|
||||||
|
self.ledger = None
|
||||||
|
self.wallet = None
|
||||||
|
self.account = None
|
||||||
|
|
||||||
async def asyncSetUp(self):
|
async def asyncSetUp(self):
|
||||||
self.conductor = Conductor(
|
self.conductor = Conductor(
|
||||||
ledger_module=self.LEDGER, manager_module=self.MANAGER, verbosity=self.VERBOSITY
|
ledger_module=self.LEDGER, manager_module=self.MANAGER, verbosity=self.VERBOSITY
|
||||||
|
@ -162,7 +171,7 @@ class IntegrationTestCase(AsyncioTestCase):
|
||||||
async def on_transaction(self, tx):
|
async def on_transaction(self, tx):
|
||||||
addresses = await self.get_tx_addresses(tx, self.ledger)
|
addresses = await self.get_tx_addresses(tx, self.ledger)
|
||||||
await asyncio.wait([
|
await asyncio.wait([
|
||||||
self.ledger.on_transaction.where(lambda e: e.address == address)
|
self.ledger.on_transaction.where(lambda e: e.address == address) # pylint: disable=W0640
|
||||||
for address in addresses
|
for address in addresses
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue