diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d00fdd111d..d6e7102101 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -17,7 +17,11 @@ "visualstudioexptteam.vscodeintellicode" ], "settings": { + "python.defaultInterpreterPath": "/usr/bin/python3", + "flake8.interpreter": ["/usr/bin/python3"], + "flake8.importStrategy": "fromEnvironment", "flake8.args": ["--config=setup.cfg"], + "pylint.interpreter": ["/usr/bin/python3"], "pylint.args": ["--rcfile=setup.cfg", "--init-hook", "import sys;sys.path.append('src')"], "terminal.integrated.shell.linux": "/usr/bin/zsh", "terminal.integrated.defaultProfile.linux": "zsh", diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh index 2350f686fe..f04a3b7d3d 100755 --- a/.devcontainer/postCreateCommand.sh +++ b/.devcontainer/postCreateCommand.sh @@ -1,4 +1,9 @@ #!/bin/sh pip3 install -r requirements.txt -pip3 install -r kivy-requirements.txt \ No newline at end of file +pip3 install -r kivy-requirements.txt + +# Linter tools needed by the VS Code extensions (ms-python.flake8, +# ms-python.pylint, nwgh.bandit). The apt-installed system packages +# are not visible to the VS Code Python interpreter. +pip3 install flake8 pylint bandit \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 6143f19255..64a5909dce 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,18 +15,35 @@ ignore = E722,F841,W503 # F841: pylint is preferred for unused-variable # 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 -# pylint honours the [MESSAGES CONTROL] section -# as well as [MASTER] section -[MESSAGES CONTROL] -disable= - invalid-name,bare-except,broad-except,superfluous-parens, - bad-option-value +# -- pylint (modern, >= 2.14) -- pylint.*-prefixed sections for setup.cfg + +[pylint.main] +init-hook = import sys;sys.path.append('src') +ignore = bitmessagekivy + +[pylint.messages_control] +disable = + invalid-name,bare-except,broad-except,relative-import, + superfluous-parens,bad-option-value # invalid-name: needs fixing during a large, project-wide refactor # bare-except,broad-except: Need fixing once thorough testing is easier # bad-option-value is for backward compatibility between python 2 and 3 + +[pylint.design] max-args = 8 max-attributes = 8 +# -- pylint (legacy, < 2.0 / python 2.7) -- old .pylintrc-style section names + [MASTER] init-hook = import sys;sys.path.append('src') ignore = bitmessagekivy + +[MESSAGES CONTROL] +disable = + invalid-name,bare-except,broad-except,relative-import, + superfluous-parens,bad-option-value + +[DESIGN] +max-args = 8 +max-attributes = 8 diff --git a/src/api.py b/src/api.py index c74960b29a..95debcab3d 100644 --- a/src/api.py +++ b/src/api.py @@ -57,7 +57,7 @@ For further examples please reference `.tests.test_api`. """ -# pylint: disable=too-many-lines,relative-import +# pylint: disable=too-many-lines import base64 import errno diff --git a/src/bitmessagecli.py b/src/bitmessagecli.py index d46c7debfd..536c5821b6 100644 --- a/src/bitmessagecli.py +++ b/src/bitmessagecli.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # pylint: disable=too-many-lines,global-statement,too-many-branches,too-many-statements,inconsistent-return-statements # pylint: disable=too-many-nested-blocks,too-many-locals,protected-access,too-many-arguments,too-many-function-args -# pylint: disable=no-member +# pylint: disable=no-member,superfluous-parens """ Created by Adam Melton (.dok) referenceing https://bitmessage.org/wiki/API_Reference for API documentation Distributed under the MIT/X11 software license. See http://www.opensource.org/licenses/mit-license.php. @@ -16,15 +16,14 @@ import datetime import imghdr import json -import ntpath import os import socket import sys import time - from six.moves import input as raw_input from six.moves import xmlrpc_client as xmlrpclib +import ntpath from bmconfigparser import config diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index d1502ce6ca..7b74bca26b 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -11,7 +11,7 @@ # yet contain logic to expand into further streams. # flake8: noqa:402 -# pylint: disable=superfluous-parens,relative-import +# pylint: disable=superfluous-parens import os import sys @@ -212,7 +212,7 @@ def start(self): # API is also objproc dependent if config.safeGetBoolean('bitmessagesettings', 'apienabled'): - import api # pylint: disable=relative-import + import api singleAPIThread = api.singleAPI() # close the main program even if there are threads left singleAPIThread.daemon = True @@ -256,14 +256,13 @@ def start(self): while state.shutdown == 0: time.sleep(1) if ( - state.testmode - and time.time() - state.last_api_response >= 30 + state.testmode + and time.time() - state.last_api_response >= 30 ): self.stop() elif not state.enableGUI: state.enableGUI = True try: - # pylint: disable=relative-import from tests import core as test_core except ImportError: try: diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index a6453c3c01..bb1ca8a9ec 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -1,7 +1,7 @@ """ PyQt based UI for bitmessage, the main module """ -# pylint: disable=import-error,relative-import,too-many-lines +# pylint: disable=import-error,too-many-lines import hashlib import locale import os diff --git a/src/bitmessageqt/address_dialogs.py b/src/bitmessageqt/address_dialogs.py index bf7503f87d..9181acd14a 100644 --- a/src/bitmessageqt/address_dialogs.py +++ b/src/bitmessageqt/address_dialogs.py @@ -2,7 +2,7 @@ Dialogs that work with BM address. """ # pylint: disable=attribute-defined-outside-init,too-few-public-methods -# pylint: disable=relative-import,import-error +# pylint: disable=import-error import hashlib diff --git a/src/bitmessageqt/addressvalidator.py b/src/bitmessageqt/addressvalidator.py index 03b0647eef..21bfff4f97 100644 --- a/src/bitmessageqt/addressvalidator.py +++ b/src/bitmessageqt/addressvalidator.py @@ -2,7 +2,7 @@ Address validator module. """ # pylint: disable=too-many-branches,too-many-arguments -# pylint: disable=import-error,relative-import +# pylint: disable=import-error from Queue import Empty diff --git a/src/bitmessageqt/newchandialog.py b/src/bitmessageqt/newchandialog.py index b2283bcc7a..8175771ce6 100644 --- a/src/bitmessageqt/newchandialog.py +++ b/src/bitmessageqt/newchandialog.py @@ -3,7 +3,7 @@ ================================= """ -# pylint: disable=import-error,relative-import,ungrouped-imports +# pylint: disable=import-error,ungrouped-imports,wrong-import-order from PyQt4 import QtCore, QtGui import widgets @@ -67,20 +67,28 @@ def accept(self): self.chanPassPhrase.text().toUtf8(), True)) addressGeneratorReturnValue = apiAddressGeneratorReturnQueue.get(True) - if addressGeneratorReturnValue and addressGeneratorReturnValue[0] != 'chan name does not match address': - UISignalQueue.put(('updateStatusBar', _translate( - "newchandialog", "Successfully created / joined chan %1").arg(unicode(self.chanPassPhrase.text())))) + if addressGeneratorReturnValue \ + and addressGeneratorReturnValue[0] \ + != 'chan name does not match address': + UISignalQueue.put(('updateStatusBar', + _translate("newchandialog", + "Successfully created / joined chan %1"). + arg(unicode(self.chanPassPhrase.text())))) # pylint: disable=undefined-variable self.parent.ui.tabWidget.setCurrentIndex( self.parent.ui.tabWidget.indexOf(self.parent.ui.chans) ) self.done(QtGui.QDialog.Accepted) else: - UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Chan creation / joining failed"))) + UISignalQueue.put(('updateStatusBar', + _translate("newchandialog", + "Chan creation / joining failed"))) self.done(QtGui.QDialog.Rejected) def reject(self): """Cancel joining the chan""" self.timer.stop() self.hide() - UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Chan creation / joining cancelled"))) + UISignalQueue.put(('updateStatusBar', + _translate("newchandialog", + "Chan creation / joining cancelled"))) self.done(QtGui.QDialog.Rejected) diff --git a/src/bitmessageqt/tests/addressbook.py b/src/bitmessageqt/tests/addressbook.py index 279343ac4d..8289ca825d 100644 --- a/src/bitmessageqt/tests/addressbook.py +++ b/src/bitmessageqt/tests/addressbook.py @@ -1,11 +1,10 @@ """ Test PyQt addressbook """ -# pylint: disable=relative-import import helper_addressbook from bitmessageqt.support import createAddressIfNeeded -from main import TestBase +from main import TestBase # pylint: disable=no-name-in-module class TestAddressbook(TestBase): diff --git a/src/bitmessageqt/tests/support.py b/src/bitmessageqt/tests/support.py index a5b16257b9..be5fb7a11b 100644 --- a/src/bitmessageqt/tests/support.py +++ b/src/bitmessageqt/tests/support.py @@ -1,12 +1,11 @@ """ PyQt4 test for support request dialog """ -# pylint: disable=relative-import # from PyQt4 import QtTest import sys -from main import TestBase +from main import TestBase # pylint: disable=no-name-in-module from shared import isAddressInMyAddressBook diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index 79070fd479..68fb1e72f2 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -11,7 +11,7 @@ from six.moves import configparser try: - import state # pylint: disable=relative-import + import state except ImportError: from pybitmessage import state diff --git a/src/class_addressGenerator.py b/src/class_addressGenerator.py index 2c70eb9563..db0fe9fd7a 100644 --- a/src/class_addressGenerator.py +++ b/src/class_addressGenerator.py @@ -6,7 +6,7 @@ from binascii import hexlify from six.moves import configparser, queue -# pylint: disable=import-error,relative-import +# pylint: disable=import-error import defaults import highlevelcrypto import queues @@ -221,8 +221,8 @@ def run(self): )) elif command in ( - 'createDeterministicAddresses', 'createChan', - 'getDeterministicAddress', 'joinChan' + 'createDeterministicAddresses', 'createChan', + 'getDeterministicAddress', 'joinChan' ): if not deterministicPassphrase: self.logger.warning( @@ -268,8 +268,8 @@ def run(self): ripe = highlevelcrypto.to_ripe( potentialPubSigningKey, potentialPubEncryptionKey) if ( - ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash] - == b'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash + ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash] + == b'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash ): break @@ -303,9 +303,9 @@ def run(self): saveAddressToDisk = False if saveAddressToDisk and live and self.save_address( - addressVersionNumber, streamNumber, ripe, label, - potentialPrivSigningKey, potentialPrivEncryptionKey, - nonceTrialsPerByte, payloadLengthExtraBytes + addressVersionNumber, streamNumber, ripe, label, + potentialPrivSigningKey, potentialPrivEncryptionKey, + nonceTrialsPerByte, payloadLengthExtraBytes ): if command in ('createChan', 'joinChan'): config.set(address, 'chan', 'true') @@ -326,7 +326,7 @@ def run(self): # Done generating addresses. if command in ( - 'createDeterministicAddresses', 'createChan', 'joinChan' + 'createDeterministicAddresses', 'createChan', 'joinChan' ): queues.apiAddressGeneratorReturnQueue.put( listOfNewAddressesToSendOutThroughTheAPI) diff --git a/src/class_objectProcessor.py b/src/class_objectProcessor.py index 30341a7e6b..a434eb4830 100644 --- a/src/class_objectProcessor.py +++ b/src/class_objectProcessor.py @@ -4,6 +4,7 @@ """ # pylint: disable=too-many-locals,too-many-return-statements # pylint: disable=too-many-branches,too-many-statements +# pylint: disable=too-many-lines import hashlib import logging import os @@ -718,10 +719,10 @@ def processmsg(self, data): # Don't send ACK if invalid, blacklisted senders, invisible # messages, disabled or chan if ( - self.ackDataHasAValidHeader(ackData) and not blockMessage - and messageEncodingType != 0 - and not config.safeGetBoolean(toAddress, 'dontsendack') - and not config.safeGetBoolean(toAddress, 'chan') + self.ackDataHasAValidHeader(ackData) and not blockMessage + and messageEncodingType != 0 + and not config.safeGetBoolean(toAddress, 'dontsendack') + and not config.safeGetBoolean(toAddress, 'chan') ): ackPayload = ackData[24:] objectType, toStreamNumber, expiresTime = \ diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index b7be9333fd..508eb4b00a 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -3,7 +3,7 @@ """ # pylint: disable=protected-access,too-many-branches,too-many-statements # pylint: disable=no-self-use,too-many-lines,too-many-locals -# pylint: disable=relative-import,import-error,redefined-builtin +# pylint: disable=import-error,redefined-builtin from __future__ import division @@ -492,7 +492,7 @@ def sendOutOrStoreMyV4Pubkey(self, myAddress): def sendOnionPeerObj(self, peer=None): """Send onionpeer object representing peer""" if not peer: # find own onionhostname - for peer in state.ownAddresses: + for peer in state.ownAddresses: # pylint: disable=redefined-argument-from-local if peer.host.endswith('.onion'): break else: @@ -772,9 +772,9 @@ def sendMsg(self): if queryreturn != []: # set the status of this msg to doingmsgpow if not sqlExecute( - '''UPDATE sent SET status='doingmsgpow' ''' - ''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''', - toaddress + '''UPDATE sent SET status='doingmsgpow' ''' + ''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''', + toaddress ): continue status = 'doingmsgpow' diff --git a/src/depends.py b/src/depends.py index fcf5820b3d..050966fd6c 100755 --- a/src/depends.py +++ b/src/depends.py @@ -194,7 +194,7 @@ def try_import(module, log_extra=False): def check_ripemd160(): """Check availability of the RIPEMD160 hash function""" try: - from fallback import RIPEMD160Hash # pylint: disable=relative-import + from fallback import RIPEMD160Hash except ImportError: return False return RIPEMD160Hash is not None diff --git a/src/helper_sent.py b/src/helper_sent.py index aa76e756a8..dda5d8f023 100644 --- a/src/helper_sent.py +++ b/src/helper_sent.py @@ -44,8 +44,7 @@ def insert(msgid=None, toAddress='[Broadcast subscribers]', fromAddress=None, su sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t) return ackdata - else: - return None + return None def delete(ack_data): diff --git a/src/main.py b/src/main.py index ce042b84d3..f39b6fd2e9 100644 --- a/src/main.py +++ b/src/main.py @@ -4,13 +4,13 @@ """Mock kivy app with mock threads.""" import os -from kivy.config import Config -from mockbm import multiqueue -import state +from kivy.config import Config # pylint: disable=import-error -from mockbm.class_addressGenerator import FakeAddressGenerator # noqa:E402 -from bitmessagekivy.mpybit import NavigateApp # noqa:E402 -from mockbm import network # noqa:E402 +import pybitmessage.state as state +from pybitmessage.bitmessagekivy.mpybit import NavigateApp # noqa:E402 +from pybitmessage.mockbm import multiqueue +from pybitmessage.mockbm.class_addressGenerator import FakeAddressGenerator # noqa:E402 +from pybitmessage.mockbm import network # noqa:E402 stats = network.stats objectracker = network.objectracker diff --git a/src/pathmagic.py b/src/pathmagic.py index 3f32c0c1ef..0fcf44d801 100644 --- a/src/pathmagic.py +++ b/src/pathmagic.py @@ -1,3 +1,6 @@ +""" +Hack to work around relative imports +""" import os import sys diff --git a/src/proofofwork.py b/src/proofofwork.py index 539db710b2..70733eb99b 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -25,8 +25,8 @@ from tr import _translate -bitmsglib = 'bitmsghash.so' -bmpow = None +BITMSGLIB = 'bitmsghash.so' +BMPOW = None class LogOutput(object): # pylint: disable=too-few-public-methods @@ -173,7 +173,7 @@ def _doCPoW(target, initialHash): out_h = ctypes.pointer(ctypes.create_string_buffer(h, 64)) out_m = ctypes.c_ulonglong(m) logger.debug('C PoW start') - nonce = bmpow(out_h, out_m) + nonce = BMPOW(out_h, out_m) trialValue = trial_value(nonce, initialHash) if state.shutdown != 0: @@ -200,7 +200,7 @@ def _doGPUPoW(target, initialHash): 'Your GPUs (%s) did not calculate correctly, disabling OpenCL.' ' Please report to the developers.', deviceNames) openclpow.enabledGpus = [] - raise Exception("GPU did not calculate correctly.") + raise RuntimeError("GPU did not calculate correctly.") if state.shutdown != 0: raise StopIteration("Interrupted") logger.debug('GPU PoW done') @@ -240,7 +240,7 @@ def getPowType(): if openclpow.openclEnabled(): return "OpenCL" - if bmpow: + if BMPOW: return "C" return "python" @@ -250,7 +250,7 @@ def notifyBuild(tried=False): Notify the user of the success or otherwise of building the PoW C module """ - if bmpow: + if BMPOW: queues.UISignalQueue.put(('updateStatusBar', (_translate( "proofofwork", "C PoW module built successfully."), 1))) elif tried: @@ -264,7 +264,7 @@ def notifyBuild(tried=False): def buildCPoW(): """Attempt to build the PoW C module""" - if bmpow is not None: + if BMPOW is not None: return if paths.frozen or sys.platform.startswith('win'): notifyBuild(False) @@ -279,7 +279,9 @@ def buildCPoW(): subprocess.check_call(make_cmd) # nosec B603 if os.path.exists( - os.path.join(paths.codePath(), 'bitmsghash', 'bitmsghash.so') + os.path.join(paths.codePath(), + 'bitmsghash', + 'bitmsghash.so') ): init() except (OSError, subprocess.CalledProcessError): @@ -299,7 +301,7 @@ def run(target, initialHash): target = int(target) if openclpow.openclEnabled(): return _doGPUPoW(target, initialHash) - if bmpow: + if BMPOW: return _doCPoW(target, initialHash) if paths.frozen == "macosx_app" or not paths.frozen: # on my (Peter Surda) Windows 10, Windows Defender @@ -323,14 +325,14 @@ def getTarget(payloadLength, ttl, nonceTrialsPerByte, payloadLengthExtraBytes): def calculate( - payload, ttl, - nonceTrialsPerByte=networkDefaultProofOfWorkNonceTrialsPerByte, - payloadLengthExtraBytes=networkDefaultPayloadLengthExtraBytes + payload, ttl, + nonceTrialsPerByte=networkDefaultProofOfWorkNonceTrialsPerByte, + payloadLengthExtraBytes=networkDefaultPayloadLengthExtraBytes ): """Do the PoW for the payload and TTL with optional difficulty params""" - return run(getTarget( - len(payload), ttl, nonceTrialsPerByte, payloadLengthExtraBytes), - hashlib.sha512(payload).digest()) + return run(getTarget(len(payload), ttl, nonceTrialsPerByte, + payloadLengthExtraBytes), + hashlib.sha512(payload).digest()) def resetPoW(): @@ -344,34 +346,34 @@ def resetPoW(): def init(): """Initialise PoW""" # pylint: disable=broad-exception-caught,global-statement - global bitmsglib, bmpow + global BITMSGLIB, BMPOW openclpow.initCL() if sys.platform.startswith('win'): - bitmsglib = ( + BITMSGLIB = ( 'bitmsghash32.dll' if ctypes.sizeof(ctypes.c_voidp) == 4 else 'bitmsghash64.dll') - libfile = os.path.join(paths.codePath(), 'bitmsghash', bitmsglib) + libfile = os.path.join(paths.codePath(), 'bitmsghash', BITMSGLIB) try: # MSVS bso = ctypes.WinDLL( - os.path.join(paths.codePath(), 'bitmsghash', bitmsglib)) - logger.info('Loaded C PoW DLL (stdcall) %s', bitmsglib) - bmpow = bso.BitmessagePOW - bmpow.restype = ctypes.c_ulonglong + os.path.join(paths.codePath(), 'bitmsghash', BITMSGLIB)) + logger.info('Loaded C PoW DLL (stdcall) %s', BITMSGLIB) + BMPOW = bso.BitmessagePOW + BMPOW.restype = ctypes.c_ulonglong _doCPoW(2**63, "") logger.info( - 'Successfully tested C PoW DLL (stdcall) %s', bitmsglib) + 'Successfully tested C PoW DLL (stdcall) %s', BITMSGLIB) except ValueError: try: # MinGW bso = ctypes.CDLL(libfile) - logger.info('Loaded C PoW DLL (cdecl) %s', bitmsglib) - bmpow = bso.BitmessagePOW - bmpow.restype = ctypes.c_ulonglong + logger.info('Loaded C PoW DLL (cdecl) %s', BITMSGLIB) + BMPOW = bso.BitmessagePOW + BMPOW.restype = ctypes.c_ulonglong _doCPoW(2**63, "") logger.info( - 'Successfully tested C PoW DLL (cdecl) %s', bitmsglib) + 'Successfully tested C PoW DLL (cdecl) %s', BITMSGLIB) except Exception as e: logger.error('Error: %s', e, exc_info=True) except Exception as e: @@ -379,7 +381,7 @@ def init(): else: try: bso = ctypes.CDLL( - os.path.join(paths.codePath(), 'bitmsghash', bitmsglib)) + os.path.join(paths.codePath(), 'bitmsghash', BITMSGLIB)) except OSError: import glob try: @@ -391,15 +393,15 @@ def init(): except Exception: bso = None else: - logger.info('Loaded C PoW DLL %s', bitmsglib) + logger.info('Loaded C PoW DLL %s', BITMSGLIB) if bso: try: - bmpow = bso.BitmessagePOW - bmpow.restype = ctypes.c_ulonglong + BMPOW = bso.BitmessagePOW + BMPOW.restype = ctypes.c_ulonglong except Exception: logger.warning( - 'Failed to setup bmpow lib %s', bso, exc_info=True) + 'Failed to setup BMPOW lib %s', bso, exc_info=True) return - if bmpow is None: + if BMPOW is None: buildCPoW() diff --git a/src/protocol.py b/src/protocol.py index 5f693a13b9..399ab5bad5 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -347,8 +347,8 @@ def assembleAddrMessage(peerList): def assembleVersionMessage( - remoteHost, remotePort, participatingStreams, - dandelion_enabled=True, server=False, nodeid=None + remoteHost, remotePort, participatingStreams, + dandelion_enabled=True, server=False, nodeid=None ): """ Construct the payload of a version message, @@ -395,9 +395,10 @@ def assembleVersionMessage( # or outgoing through clearnet extport = config.safeGetInt('bitmessagesettings', 'extport') if ( - extport and ((server and not checkSocksIP(remoteHost)) or ( - config.get('bitmessagesettings', 'socksproxytype') - == 'none' and not server)) + extport and ((server and not checkSocksIP(remoteHost)) + or (config.get('bitmessagesettings', + 'socksproxytype') + == 'none' and not server)) ): payload += pack('>H', extport) elif checkSocksIP(remoteHost) and server: # incoming connection over Tor diff --git a/src/shared.py b/src/shared.py index 9357a4ee4f..809e8b8381 100644 --- a/src/shared.py +++ b/src/shared.py @@ -15,7 +15,7 @@ import sys from binascii import hexlify -from six.moves.reprlib import repr +from six.moves.reprlib import repr # pylint: disable=redefined-builtin # Project imports. import highlevelcrypto @@ -102,9 +102,9 @@ def reloadMyAddressHashes(): # Returns a simple 32 bytes of information encoded in 64 Hex characters try: privEncryptionKey = hexlify( - highlevelcrypto.decodeWalletImportFormat(config.get( - addressInKeysFile, 'privencryptionkey').encode() - )) + highlevelcrypto.decodeWalletImportFormat( + config.get(addressInKeysFile, + 'privencryptionkey').encode())) except ValueError: logger.error( 'Error in reloadMyAddressHashes: failed to decode' diff --git a/src/shutdown.py b/src/shutdown.py index 441d655eef..72ff36f43d 100644 --- a/src/shutdown.py +++ b/src/shutdown.py @@ -55,9 +55,9 @@ def doCleanShutdown(): for thread in threading.enumerate(): if ( - thread is not threading.currentThread() - and isinstance(thread, StoppableThread) - and thread.name != 'SQL' + thread is not threading.currentThread() + and isinstance(thread, StoppableThread) + and thread.name != 'SQL' ): logger.debug("Waiting for thread %s", thread.name) thread.join() diff --git a/src/tests/core.py b/src/tests/core.py index 0ef7b2ef46..5858505143 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -209,8 +209,8 @@ def _check_connection(self, full=False, timeout=360): time.sleep(1) for peer, con in connectionpool.pool.outboundConnections.items(): if ( - peer.host.startswith('bootstrap') - or peer.host == 'quzwelsuziwqgpt2.onion' + peer.host.startswith('bootstrap') + or peer.host == 'quzwelsuziwqgpt2.onion' ): continue self.assertIsInstance(con, connection_base) @@ -278,8 +278,8 @@ def test_onionservicesonly(self): config.set('bitmessagesettings', 'onionservicesonly', 'true') self._load_knownnodes(knownnodes_file + '.bak') if len([ - node for node in knownnodes.knownNodes[1] - if node.host.endswith('.onion') + node for node in knownnodes.knownNodes[1] + if node.host.endswith('.onion') ]) < 3: # generate fake onion nodes if have not enough with knownnodes.knownNodesLock: for f in ('a', 'b', 'c', 'd'): diff --git a/src/tests/partial.py b/src/tests/partial.py index f008e847e5..71347c6d67 100644 --- a/src/tests/partial.py +++ b/src/tests/partial.py @@ -24,7 +24,7 @@ def setUpClass(cls): from debug import logger # noqa:F401 pylint: disable=unused-variable if sys.hexversion >= 0x3000000: - # pylint: disable=no-name-in-module,relative-import + # pylint: disable=no-name-in-module from mockbm import network as network_mock import network network.stats = network_mock.stats diff --git a/src/tests/test_network.py b/src/tests/test_network.py index 11de1329b4..ac757dee89 100644 --- a/src/tests/test_network.py +++ b/src/tests/test_network.py @@ -90,9 +90,10 @@ def test_stats(self): if pl == 0: pl = len(self.pool) if ( - self.stats.receivedBytes() > 0 and self.stats.sentBytes() > 0 - and pl > 0 - # and len(self.stats.connectedHostsList()) > 0 + self.stats.receivedBytes() > 0 + and self.stats.sentBytes() > 0 + and pl > 0 + # and len(self.stats.connectedHostsList()) > 0 ): break time.sleep(1) diff --git a/src/tests/test_shared.py b/src/tests/test_shared.py index ae90a9d441..6fdecb1705 100644 --- a/src/tests/test_shared.py +++ b/src/tests/test_shared.py @@ -174,7 +174,7 @@ def test_check_sensitive_file_permissions(self, mock_sys, mock_os_stat): @patch("pybitmessage.shared.os.chmod") @patch("pybitmessage.shared.os.stat") def test_fix_sensitive_file_permissions( # pylint: disable=no-self-use - self, mock_os_stat, mock_chmod + self, mock_os_stat, mock_chmod ): """Test to fix file permissions""" fake_filename = "path/to/file" diff --git a/tox.ini b/tox.ini index 2a2593c3c7..7cf892c42a 100644 --- a/tox.ini +++ b/tox.ini @@ -159,14 +159,35 @@ ignore = E722,F841,W503 # F841: pylint is preferred for unused-variable # 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 +# -- pylint (modern, >= 2.14) -- pylint.*-prefixed sections for setup.cfg/tox.ini + [pylint.main] +ignore = bitmessagecurses,bitmessagekivy,bitmessageqt,messagetypes,mockbm, + network,plugins,umsgpack,bitmessagecli.py + +[pylint.messages_control] disable = invalid-name,consider-using-f-string,fixme,raise-missing-from, - super-with-arguments,unnecessary-pass,unknown-option-value, - unspecified-encoding,useless-object-inheritance,useless-option-value + relative-import,super-with-arguments,unnecessary-pass,unknown-option-value, + unspecified-encoding,useless-object-inheritance,useless-option-value, + bad-option-value + +[pylint.design] +max-args = 8 +max-positional-arguments = 8 +max-attributes = 8 + +# -- pylint (legacy, < 2.0 / python 2.7) -- old .pylintrc-style section names + +[MASTER] ignore = bitmessagecurses,bitmessagekivy,bitmessageqt,messagetypes,mockbm, network,plugins,umsgpack,bitmessagecli.py +[MESSAGES CONTROL] +disable = + invalid-name,bare-except,broad-except,relative-import, + superfluous-parens,bad-option-value + +[DESIGN] max-args = 8 -max-positional-arguments = 8 max-attributes = 8