Browse Source

pylint integration

Lint the entire MMGen Wallet code base, including test suite:

    # Install pylint:
    $ python3 -m pip install pylint

    # Perform the check:
    $ test/test-release.sh lint

The check should complete without error when running Python v3.9 or greater,
provided all required Python dependencies described in Test-Suite.md, including
altcoin dependencies, are installed.
The MMGen Project 1 year ago
parent
commit
11b131fda8

+ 1 - 1
mmgen/data/version

@@ -1 +1 @@
-14.0.dev8
+14.0.dev9

+ 88 - 0
pyproject.toml

@@ -5,3 +5,91 @@ requires = [
 	"build>=0.5.1",
 ]
 build-backend = "setuptools.build_meta"
+
+[tool.pylint.format]
+indent-string = "\t"
+indent-after-paren = 2
+max-line-length = 110
+ 
+[tool.pylint.main]
+py-version = "3.7"
+recursive = true
+jobs = 0
+ignore = [
+	"data",
+	"wordlist",
+	"pyethereum",
+	"rlp",
+	"main_split.py",
+]
+ignored-modules = [ # ignored for no-member, otherwise checked
+	"mmgen.proto.secp256k1.secp256k1",
+	"mmgen.color",
+	"mmgen.term",
+	"msvcrt",
+	"gmpy2",
+]
+ 
+[tool.pylint."messages control"]
+disable = [
+	"raw-checker-failed",
+	"bad-inline-option",
+	"locally-disabled",
+	"file-ignored",
+	"suppressed-message",
+	"useless-suppression",
+	"deprecated-pragma",
+	"use-symbolic-message-instead",
+	"use-implicit-booleaness-not-comparison-to-string",
+	"use-implicit-booleaness-not-comparison-to-zero",
+# non-default:
+	"no-method-argument",
+	"function-redefined",
+	"method-hidden",
+]
+# Disable these too for mostly quiet output without --errors-only:
+#	"missing-function-docstring",
+#	"missing-class-docstring",
+#	"import-outside-toplevel",
+#	"multiple-imports",
+#	"wrong-import-position",
+#	"protected-access",
+#	"invalid-name",
+#	"too-few-public-methods",
+#	"super-init-not-called",
+#	"unnecessary-lambda-assignment",
+#	"attribute-defined-outside-init",
+#	"fixme",
+
+[tool.pylint.miscellaneous]
+notes = ["FIXME", "TODO", "DEBUG", "WIP"]
+ 
+[tool.pylint.typecheck]
+mixin-class-rgx = """.*[Mm]ixin|\
+	^(Hilite|InitErrors|DummyWIF|\
+	cfg_file|cfg_file_sample|\
+	MoneroMMGenFile|keygen_base|xmr_signable|\
+	CmdTestShared)$"""
+
+ignored-classes = [ # ignored for no-member, otherwise checked
+	"optparse.Values", 
+	"thread._local", 
+	"_thread._local", 
+	"argparse.Namespace",
+# mmgen:
+	"baseconv",
+	"mmgen.autosign.Signable.base",
+	"Sha2",
+	"mmgen.xmrwallet.MoneroMMGenTX.Base",
+	"mmgen.xmrwallet.MoneroWalletOutputsFile.Base",
+	"mmgen.proto.eth.tx.Completed",
+	"TxInfo",
+	"TwRPC",
+	"MnemonicEntry",
+	"MMGenObjectDevTools",
+	"MnEntryMode",
+	"deserialized_tx",
+# test suite:
+	"TestHashFunc",
+	"GenTool",
+]

+ 5 - 0
test/include/coin_daemon_control.py

@@ -12,6 +12,11 @@
 test.include.coin_daemon_control: Start and stop daemons for the MMGen test suite
 """
 
+import sys
+from pathlib import PurePath
+
+sys.path[0] = str(PurePath(*PurePath(sys.modules[__name__].__file__).parts[:-3]))
+
 from mmgen.cfg import Config,gc
 from mmgen.util import msg,die,oneshot_warning,async_run
 from mmgen.protocol import init_proto

+ 10 - 3
test/test-release.d/cfg.sh

@@ -8,7 +8,7 @@
 #   https://github.com/mmgen/mmgen
 #   https://gitlab.com/mmgen/mmgen
 
-all_tests="dep obj color unit hash ref altref altgen xmr eth autosign btc btc_tn btc_rt bch bch_tn bch_rt ltc ltc_tn ltc_rt tool tool2 gen alt"
+all_tests="dep lint obj color unit hash ref altref altgen xmr eth autosign btc btc_tn btc_rt bch bch_tn bch_rt ltc ltc_tn ltc_rt tool tool2 gen alt"
 
 groups_desc="
 	default  - All tests minus the extra tests
@@ -20,10 +20,10 @@ groups_desc="
 
 init_groups() {
 	dfl_tests='dep alt obj color unit hash ref tool tool2 gen autosign btc btc_tn btc_rt altref altgen bch bch_rt ltc ltc_rt eth xmr'
-	extra_tests='dep autosign_btc autosign_live ltc_tn bch_tn'
+	extra_tests='dep lint autosign_btc autosign_live ltc_tn bch_tn'
 	noalt_tests='dep alt obj color unit hash ref tool tool2 gen autosign_btc btc btc_tn btc_rt'
 	quick_tests='dep alt obj color unit hash ref tool tool2 gen autosign btc btc_rt altref altgen eth xmr'
-	qskip_tests='btc_tn bch bch_rt ltc ltc_rt'
+	qskip_tests='lint btc_tn bch bch_rt ltc ltc_rt'
 
 	[ "$MSYS2" ] && SKIP_LIST='autosign autosign_btc autosign_live'
 }
@@ -58,6 +58,13 @@ init_tests() {
 	d_dep="system and testing dependencies"
 	t_dep="- $unit_tests_py testdep dep daemon.exec"
 
+	d_lint="code errors with static code analyzer"
+	t_lint="
+		- $pylint --errors-only mmgen
+		- $pylint --errors-only test
+		- $pylint --errors-only --disable=relative-beyond-top-level test/cmdtest_py_d
+	"
+
 	d_unit="low-level subsystems"
 	t_unit="- $unit_tests_py --exclude testdep,dep,daemon"
 

+ 3 - 1
test/test-release.sh

@@ -141,6 +141,7 @@ gentest_py='test/gentest.py --quiet'
 scrambletest_py='test/scrambletest.py'
 altcoin_mod_opts='--quiet'
 mmgen_tool='cmds/mmgen-tool'
+pylint='PYTHONPATH=. pylint' # PYTHONPATH required by older Pythons (e.g. v3.9)
 python='python3'
 rounds=10
 
@@ -218,7 +219,8 @@ do
 		tooltest_py+=" --verbose"
 		mmgen_tool+=" --verbose"
 		objattrtest_py+=" --verbose"
-		scrambletest_py+=" --verbose" ;;
+		scrambletest_py+=" --verbose"
+		pylint+=" --verbose" ;;
 	*)  exit ;;
 	esac
 done

+ 10 - 1
test/unit_tests_d/ut_testdep.py

@@ -7,7 +7,8 @@ test.unit_tests_d.ut_testdep: test dependency unit tests for the MMGen suite
 import sys,os
 from subprocess import run,DEVNULL
 
-from mmgen.util import ymsg
+from mmgen.util import ymsg,bmsg
+from ..include.common import cfg
 
 sec = 'deadbeef' * 8
 
@@ -16,6 +17,14 @@ class unit_tests:
 	altcoin_deps = ('pycoin','monero_python','keyconv','zcash_mini','ethkey','ssh_socks_proxy')
 	win_skip = ('losetup','zcash_mini')
 
+	def pylint(self,name,ut):
+		try:
+			return run(['pylint','--version'],stdout=None if cfg.verbose else DEVNULL).returncode == 0
+		except OSError as e:
+			ymsg('  ' + str(e))
+			bmsg("  Install pylint with 'python3 -m pip install pylint'")
+			return False
+
 	def core_repo(self,name,ut):
 		crr = os.getenv('CORE_REPO_ROOT')
 		if not crr or not os.path.exists(os.path.join(crr,'src/test/data/tx_valid.json')):