Skip to content

Commit

Permalink
Switch to flake8
Browse files Browse the repository at this point in the history
pylint no longer works on MacOSX
  • Loading branch information
Neil Booth committed Nov 1, 2021
1 parent b3c330b commit a4be445
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/prepare-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ steps:
python -m pip install pytest
python -m pip install pytest-asyncio
python -m pip install Sphinx
python -m pip install pylint
python -m pip install flake8
displayName: Prepare general environment
condition: |
and(
Expand Down
4 changes: 2 additions & 2 deletions .azure-pipelines/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
coverage run -m pytest --junitxml=junit/test-results.xml tests
coverage xml
displayName: 'Test with pytest'
- bash: ./pylint
displayName: pylint
- bash: ./flake8
displayName: flake8
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
Expand Down
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]

max-line-length=100
select=E,F,W
ignore=W503
3 changes: 1 addition & 2 deletions electrumx/lib/coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def lookup_coin_class(cls, name, net):
Raise an exception if unrecognised.'''
req_attrs = ['CHAIN_SIZE', 'CHAIN_SIZE_HEIGHT', 'AVG_BLOCK_SIZE']
for coin in util.subclasses(Coin):
if (coin.NAME.lower() == name.lower() and
coin.NET.lower() == net.lower()):
if coin.NAME.lower() == name.lower() and coin.NET.lower() == net.lower():
coin_req_attrs = req_attrs.copy()
missing = [attr for attr in coin_req_attrs
if not hasattr(coin, attr)]
Expand Down
2 changes: 1 addition & 1 deletion electrumx/lib/merkle.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def branch_and_root(self, hashes, index, length=None, tsc_format=False):
hashes.append(hashes[-1])

# Asterix used in place of "duplicated" hashes in TSC format (derivable by client)
is_last_node_in_level = (index ^ 1 == len(hashes)-1)
is_last_node_in_level = (index ^ 1 == len(hashes) - 1)
if tsc_format and is_last_node_in_level:
branch.append(b"*")
else:
Expand Down
6 changes: 3 additions & 3 deletions electrumx/lib/peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def bucket_for_internal_purposes(self):
if ip_addr.version == 4:
return str(ip_addr)
elif ip_addr.version == 6:
slash64 = IPv6Network(self.ip_addr).supernet(prefixlen_diff=128-64)
slash64 = IPv6Network(self.ip_addr).supernet(prefixlen_diff=128 - 64)
return str(slash64)
return ''

Expand All @@ -181,10 +181,10 @@ def bucket_for_external_interface(self):
return ''
ip_addr = ip_address(self.ip_addr)
if ip_addr.version == 4:
slash16 = IPv4Network(self.ip_addr).supernet(prefixlen_diff=32-16)
slash16 = IPv4Network(self.ip_addr).supernet(prefixlen_diff=32 - 16)
return str(slash16)
elif ip_addr.version == 6:
slash56 = IPv6Network(self.ip_addr).supernet(prefixlen_diff=128-56)
slash56 = IPv6Network(self.ip_addr).supernet(prefixlen_diff=128 - 56)
return str(slash56)
return ''

Expand Down
4 changes: 2 additions & 2 deletions electrumx/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def size(o):
def subclasses(base_class, strict=True):
'''Return a list of subclasses of base_class in its module.'''
def select(obj):
return (inspect.isclass(obj) and issubclass(obj, base_class) and
(not strict or obj != base_class))
return (inspect.isclass(obj) and issubclass(obj, base_class)
and (not strict or obj != base_class))

pairs = inspect.getmembers(sys.modules[base_class.__module__], select)
return [pair[1] for pair in pairs]
Expand Down
10 changes: 5 additions & 5 deletions electrumx/server/block_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,13 @@ async def flush(self, flush_utxos):
# Estimate size remaining
daemon_height = self.daemon.cached_height()
tail_blocks = max(0, (daemon_height - max(self.state.height, self.coin.CHAIN_SIZE_HEIGHT)))
size_remaining = (max(self.coin.CHAIN_SIZE - self.state.chain_size, 0) +
tail_blocks * self.coin.AVG_BLOCK_SIZE)
size_remaining = (max(self.coin.CHAIN_SIZE - self.state.chain_size, 0)
+ tail_blocks * self.coin.AVG_BLOCK_SIZE)
await run_in_thread(self.db.flush_dbs, self.flush_data(), flush_utxos, size_remaining)

async def check_cache_size_loop(self):
'''Signal to flush caches if they get too big.'''
one_MB = 1000*1000
one_MB = 1_000_000
cache_MB = self.env.cache_MB
OnDiskBlock.daemon = self.daemon
while True:
Expand Down Expand Up @@ -481,8 +481,8 @@ async def advance_and_maybe_flush(block):
def advance_block(self, block):
'''Advance once block. It is already verified they correctly connect onto our tip.'''

is_unspendable = (is_unspendable_genesis if block.height >=
self.coin.GENESIS_ACTIVATION else is_unspendable_legacy)
is_unspendable = (is_unspendable_genesis if block.height >= self.coin.GENESIS_ACTIVATION
else is_unspendable_legacy)

# Use local vars for speed in the loops
state = self.state
Expand Down
4 changes: 0 additions & 4 deletions electrumx/server/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class Notifications(object):
# block is done. This object handles that logic by deferring
# notifications appropriately.

# pylint:disable=E0202

def __init__(self):
self._touched_mp = {}
self._touched_bp = {}
Expand Down Expand Up @@ -74,8 +72,6 @@ async def on_block(self, touched, height):
self._highest_block = height
await self._maybe_notify()

# pylint:disable=W0201


class Controller(ServerBase):
'''Manages server initialisation and stutdown.
Expand Down
2 changes: 1 addition & 1 deletion electrumx/server/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def fs_tx_hashes_at_blockheight(self, block_height):
num_txs_in_block = self.tx_counts[block_height] - first_tx_num
tx_hashes = self.hashes_file.read(first_tx_num * 32, num_txs_in_block * 32)
assert num_txs_in_block == len(tx_hashes) // 32
return [tx_hashes[idx * 32: (idx+1) * 32] for idx in range(num_txs_in_block)]
return [tx_hashes[idx * 32: (idx + 1) * 32] for idx in range(num_txs_in_block)]

async def tx_hashes_at_blockheight(self, block_height):
return await run_in_thread(self.fs_tx_hashes_at_blockheight, block_height)
Expand Down
4 changes: 2 additions & 2 deletions electrumx/server/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def services_to_report(self):
raise ServiceError(f'bad protocol for REPORT_SERVICES: {service.protocol}')
if isinstance(service.host, (IPv4Address, IPv6Address)):
ip_addr = service.host
if (ip_addr.is_multicast or ip_addr.is_unspecified or
(ip_addr.is_private and self.peer_announce)):
if (ip_addr.is_multicast or ip_addr.is_unspecified
or (ip_addr.is_private and self.peer_announce)):
raise ServiceError(f'bad IP address for REPORT_SERVICES: {ip_addr}')
elif service.host.lower() == 'localhost':
raise ServiceError(f'bad host for REPORT_SERVICES: {service.host}')
Expand Down
4 changes: 2 additions & 2 deletions electrumx/server/mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def _accept_transactions(self, tx_map, utxo_map, touched):
tx.in_pairs = tuple(in_pairs)
# Avoid negative fees if dealing with generation-like transactions
# because some in_parts would be missing
tx.fee = max(0, (sum(v for _, v in tx.in_pairs) -
sum(v for _, v in tx.out_pairs)))
tx.fee = max(0, (sum(v for _, v in tx.in_pairs)
- sum(v for _, v in tx.out_pairs)))
txs[tx_hash] = tx

for hashX, _value in itertools.chain(tx.in_pairs, tx.out_pairs):
Expand Down
8 changes: 4 additions & 4 deletions electrumx/server/peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class PeerSession(RPCSession):

async def handle_request(self, request):
# We subscribe so might be unlucky enough to get a notification...
if (isinstance(request, Notification) and
request.method == 'blockchain.headers.subscribe'):
if (isinstance(request, Notification)
and request.method == 'blockchain.headers.subscribe'):
pass
else:
await handler_invocation(None, request) # Raises
Expand Down Expand Up @@ -132,8 +132,8 @@ async def _import_peers(self):
def _get_recent_good_peers(self):
cutoff = time.time() - STALE_SECS
recent = [peer for peer in self.peers
if peer.last_good > cutoff and
not peer.bad and peer.is_public]
if peer.last_good > cutoff
and not peer.bad and peer.is_public]
return recent

async def _detect_proxy(self):
Expand Down
4 changes: 2 additions & 2 deletions electrumx/server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ async def notify(self, touched, height_changed):
try:
async with timeout_after(30):
await self._notify_inner(touched, height_changed)
except Exception: # pylint:disable=W0703
except Exception:
self.logger.exception('unexpected exception notifying client')

async def _notify_inner(self, touched, height_changed):
Expand Down Expand Up @@ -1401,7 +1401,7 @@ async def transaction_broadcast(self, raw_tx):
hex_hash = await self.session_mgr.broadcast_transaction(raw_tx)
except DaemonError as e:
error, = e.args
message = error['message'] # pylint:disable=E1126
message = error['message']
self.logger.info(f'error sending transaction: {message}')
raise RPCError(BAD_REQUEST, 'the transaction was rejected by '
f'network rules.\n\n{message}\n[{raw_tx}]') from None
Expand Down
9 changes: 2 additions & 7 deletions electrumx/server/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,13 @@ def iterator(self, prefix=b'', reverse=False):
'''
raise NotImplementedError

# pylint:disable=W0223


class LevelDB(Storage):
'''LevelDB database engine.'''

@classmethod
def import_module(cls):
import plyvel # pylint:disable=E0401
import plyvel
cls.module = plyvel

def open(self, name, create):
Expand All @@ -91,9 +89,6 @@ def open(self, name, create):
sync=True)


# pylint:disable=E1101


class RocksDB(Storage):
'''RocksDB database engine.'''

Expand All @@ -103,7 +98,7 @@ def __init__(self, *args):

@classmethod
def import_module(cls):
import rocksdb # pylint:disable=E0401
import rocksdb
cls.module = rocksdb

def open(self, name, create):
Expand Down
1 change: 1 addition & 0 deletions flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flake8 electrumx/server/*.py electrumx/lib/*.py *.py
1 change: 0 additions & 1 deletion pylint

This file was deleted.

0 comments on commit a4be445

Please sign in to comment.