Skip to content

Commit e719e85

Browse files
committed
Code quality
1 parent f6f5273 commit e719e85

16 files changed

Lines changed: 132 additions & 79 deletions

.devcontainer/devcontainer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
"visualstudioexptteam.vscodeintellicode"
1818
],
1919
"settings": {
20+
"python.defaultInterpreterPath": "/usr/bin/python3",
21+
"flake8.interpreter": ["/usr/bin/python3"],
22+
"flake8.importStrategy": "fromEnvironment",
2023
"flake8.args": ["--config=setup.cfg"],
24+
"pylint.interpreter": ["/usr/bin/python3"],
2125
"pylint.args": ["--rcfile=setup.cfg", "--init-hook", "import sys;sys.path.append('src')"],
2226
"terminal.integrated.shell.linux": "/usr/bin/zsh",
2327
"terminal.integrated.defaultProfile.linux": "zsh",

.devcontainer/postCreateCommand.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#!/bin/sh
22

33
pip3 install -r requirements.txt
4-
pip3 install -r kivy-requirements.txt
4+
pip3 install -r kivy-requirements.txt
5+
6+
# Linter tools needed by the VS Code extensions (ms-python.flake8,
7+
# ms-python.pylint, nwgh.bandit). The apt-installed system packages
8+
# are not visible to the VS Code Python interpreter.
9+
pip3 install flake8 pylint bandit

setup.cfg

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,35 @@ ignore = E722,F841,W503
1515
# F841: pylint is preferred for unused-variable
1616
# W503: deprecated: https://bugs.python.org/issue26763 - https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
1717

18-
# pylint honours the [MESSAGES CONTROL] section
19-
# as well as [MASTER] section
20-
[MESSAGES CONTROL]
21-
disable=
18+
# -- pylint (modern, >= 2.14) -- pylint.*-prefixed sections for setup.cfg
19+
20+
[pylint.main]
21+
init-hook = import sys;sys.path.append('src')
22+
ignore = bitmessagekivy
23+
24+
[pylint.messages_control]
25+
disable =
2226
invalid-name,bare-except,broad-except,superfluous-parens,
2327
bad-option-value
2428
# invalid-name: needs fixing during a large, project-wide refactor
2529
# bare-except,broad-except: Need fixing once thorough testing is easier
2630
# bad-option-value is for backward compatibility between python 2 and 3
31+
32+
[pylint.design]
2733
max-args = 8
2834
max-attributes = 8
2935

36+
# -- pylint (legacy, < 2.0 / python 2.7) -- old .pylintrc-style section names
37+
3038
[MASTER]
3139
init-hook = import sys;sys.path.append('src')
3240
ignore = bitmessagekivy
41+
42+
[MESSAGES CONTROL]
43+
disable =
44+
invalid-name,bare-except,broad-except,superfluous-parens,
45+
bad-option-value
46+
47+
[DESIGN]
48+
max-args = 8
49+
max-attributes = 8

src/bitmessagecli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33
# pylint: disable=too-many-lines,global-statement,too-many-branches,too-many-statements,inconsistent-return-statements
44
# pylint: disable=too-many-nested-blocks,too-many-locals,protected-access,too-many-arguments,too-many-function-args
5-
# pylint: disable=no-member
5+
# pylint: disable=no-member,superfluous-parens
66
"""
77
Created by Adam Melton (.dok) referenceing https://bitmessage.org/wiki/API_Reference for API documentation
88
Distributed under the MIT/X11 software license. See http://www.opensource.org/licenses/mit-license.php.
@@ -16,15 +16,14 @@
1616
import datetime
1717
import imghdr
1818
import json
19-
import ntpath
2019
import os
2120
import socket
2221
import sys
2322
import time
24-
2523
from six.moves import input as raw_input
2624
from six.moves import xmlrpc_client as xmlrpclib
2725

26+
import ntpath
2827
from bmconfigparser import config
2928

3029

src/bitmessagemain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ def start(self):
256256
while state.shutdown == 0:
257257
time.sleep(1)
258258
if (
259-
state.testmode
260-
and time.time() - state.last_api_response >= 30
259+
state.testmode
260+
and time.time() - state.last_api_response >= 30
261261
):
262262
self.stop()
263263
elif not state.enableGUI:

src/class_addressGenerator.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ def run(self):
221221
))
222222

223223
elif command in (
224-
'createDeterministicAddresses', 'createChan',
225-
'getDeterministicAddress', 'joinChan'
224+
'createDeterministicAddresses', 'createChan',
225+
'getDeterministicAddress', 'joinChan'
226226
):
227227
if not deterministicPassphrase:
228228
self.logger.warning(
@@ -268,8 +268,8 @@ def run(self):
268268
ripe = highlevelcrypto.to_ripe(
269269
potentialPubSigningKey, potentialPubEncryptionKey)
270270
if (
271-
ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash]
272-
== b'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash
271+
ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash]
272+
== b'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash
273273
):
274274
break
275275

@@ -303,9 +303,9 @@ def run(self):
303303
saveAddressToDisk = False
304304

305305
if saveAddressToDisk and live and self.save_address(
306-
addressVersionNumber, streamNumber, ripe, label,
307-
potentialPrivSigningKey, potentialPrivEncryptionKey,
308-
nonceTrialsPerByte, payloadLengthExtraBytes
306+
addressVersionNumber, streamNumber, ripe, label,
307+
potentialPrivSigningKey, potentialPrivEncryptionKey,
308+
nonceTrialsPerByte, payloadLengthExtraBytes
309309
):
310310
if command in ('createChan', 'joinChan'):
311311
config.set(address, 'chan', 'true')
@@ -326,7 +326,7 @@ def run(self):
326326

327327
# Done generating addresses.
328328
if command in (
329-
'createDeterministicAddresses', 'createChan', 'joinChan'
329+
'createDeterministicAddresses', 'createChan', 'joinChan'
330330
):
331331
queues.apiAddressGeneratorReturnQueue.put(
332332
listOfNewAddressesToSendOutThroughTheAPI)

src/class_objectProcessor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
# pylint: disable=too-many-locals,too-many-return-statements
66
# pylint: disable=too-many-branches,too-many-statements
7+
# pylint: disable=too-many-lines
78
import hashlib
89
import logging
910
import os
@@ -718,10 +719,10 @@ def processmsg(self, data):
718719
# Don't send ACK if invalid, blacklisted senders, invisible
719720
# messages, disabled or chan
720721
if (
721-
self.ackDataHasAValidHeader(ackData) and not blockMessage
722-
and messageEncodingType != 0
723-
and not config.safeGetBoolean(toAddress, 'dontsendack')
724-
and not config.safeGetBoolean(toAddress, 'chan')
722+
self.ackDataHasAValidHeader(ackData) and not blockMessage
723+
and messageEncodingType != 0
724+
and not config.safeGetBoolean(toAddress, 'dontsendack')
725+
and not config.safeGetBoolean(toAddress, 'chan')
725726
):
726727
ackPayload = ackData[24:]
727728
objectType, toStreamNumber, expiresTime = \

src/class_singleWorker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,9 @@ def sendMsg(self):
772772
if queryreturn != []:
773773
# set the status of this msg to doingmsgpow
774774
if not sqlExecute(
775-
'''UPDATE sent SET status='doingmsgpow' '''
776-
''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''',
777-
toaddress
775+
'''UPDATE sent SET status='doingmsgpow' '''
776+
''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''',
777+
toaddress
778778
):
779779
continue
780780
status = 'doingmsgpow'

src/helper_sent.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ def insert(msgid=None, toAddress='[Broadcast subscribers]', fromAddress=None, su
4444

4545
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
4646
return ackdata
47-
else:
48-
return None
47+
return None
4948

5049

5150
def delete(ack_data):

src/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"""Mock kivy app with mock threads."""
55

66
import os
7-
from kivy.config import Config
8-
from mockbm import multiqueue
9-
import state
7+
from kivy.config import Config # pylint: disable=import-error
108

11-
from mockbm.class_addressGenerator import FakeAddressGenerator # noqa:E402
12-
from bitmessagekivy.mpybit import NavigateApp # noqa:E402
13-
from mockbm import network # noqa:E402
9+
import pybitmessage.state as state
10+
from pybitmessage.bitmessagekivy.mpybit import NavigateApp # noqa:E402
11+
from pybitmessage.mockbm import multiqueue
12+
from pybitmessage.mockbm.class_addressGenerator import FakeAddressGenerator # noqa:E402
13+
from pybitmessage.mockbm import network # noqa:E402
1414

1515
stats = network.stats
1616
objectracker = network.objectracker

0 commit comments

Comments
 (0)