From 3524ee0932fce6ad084e8b380d3240176c7994a8 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 18 Oct 2023 12:11:49 +0000 Subject: [PATCH] minor cleanups --- examples/coin-daemon-info.py | 2 +- mmgen/addr.py | 10 +++++----- mmgen/contrib/license.py | 4 +--- mmgen/mn_entry.py | 8 +++----- mmgen/msg.py | 2 +- mmgen/obj.py | 12 ++++++------ mmgen/ui.py | 3 ++- mmgen/util2.py | 2 +- pyproject.toml | 13 ------------- 9 files changed, 20 insertions(+), 36 deletions(-) diff --git a/examples/coin-daemon-info.py b/examples/coin-daemon-info.py index cfb640d8..297c0443 100755 --- a/examples/coin-daemon-info.py +++ b/examples/coin-daemon-info.py @@ -19,7 +19,7 @@ examples/coin-daemon-info.py: # Testing mode: # # 1) From the MMGen repository root, start the mainnet test suite daemons as follows -# (note that openethereum is the default testing daemon for ETH): +# (note that Geth is the default testing daemon for ETH): # # test/start-coin-daemons.py btc ltc eth # diff --git a/mmgen/addr.py b/mmgen/addr.py index 0d0eb4e7..dd2fd9f0 100755 --- a/mmgen/addr.py +++ b/mmgen/addr.py @@ -172,13 +172,13 @@ class CoinAddr(HiliteStr,InitErrors,MMGenObject): return self._parsed @classmethod - def fmtc(cls,s,width,**kwargs): - return super().fmtc( s=s[:width-2]+'..' if len(s) > width else s, width=width, **kwargs ) + def fmtc(cls,s,width,color=False): + return super().fmtc( s=s[:width-2]+'..' if len(s) > width else s, width=width, color=color ) - def fmt(self,width,**kwargs): + def fmt(self,width,color=False): return ( - super().fmtc( s=self[:width-2]+'..', width=width, **kwargs ) if len(self) > width else - super().fmt( width=width, **kwargs ) + super().fmtc( s=self[:width-2]+'..', width=width, color=color ) if len(self) > width else + super().fmt( width=width, color=color ) ) def is_coin_addr(proto,s): diff --git a/mmgen/contrib/license.py b/mmgen/contrib/license.py index 90049838..0835d445 100755 --- a/mmgen/contrib/license.py +++ b/mmgen/contrib/license.py @@ -20,9 +20,7 @@ contrib.license: Copyright notice and text of GPLv3 """ -from ..cfg import gc - -warning = f""" +warning = """ {gc.proj_name} Copyright (C) {gc.Cdates} by {gc.author} {gc.email}. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. diff --git a/mmgen/mn_entry.py b/mmgen/mn_entry.py index 72503f07..5a79e648 100755 --- a/mmgen/mn_entry.py +++ b/mmgen/mn_entry.py @@ -20,7 +20,7 @@ mn_entry.py - Mnemonic user entry methods for the MMGen suite """ -import time +import sys,time from .util import msg,msg_r,fmt,fmt_list,capfirst,die,ascii_lowercase from .term import get_char,get_char_raw @@ -297,8 +297,7 @@ class MnemonicEntry: lo = idx + 1 def get_cls_by_entry_mode(self,entry_mode): - import mmgen.mn_entry - return getattr( mmgen.mn_entry, 'MnEntryMode'+capfirst(entry_mode) ) + return getattr(sys.modules[__name__], 'MnEntryMode' + capfirst(entry_mode)) def choose_entry_mode(self): msg('Choose an entry mode:\n') @@ -430,6 +429,5 @@ def mn_entry(cfg,wl_id,entry_mode=None): me.bconv = getattr(importlib.import_module(f'mmgen.{me.modname}'),me.modname)(wl_id) me.wl = me.bconv.digits if entry_mode: - import mmgen.mn_entry - me.em = getattr( mmgen.mn_entry, 'MnEntryMode'+capfirst(entry_mode) )(me) + me.em = getattr(sys.modules[__name__], 'MnEntryMode' + capfirst(entry_mode))(me) return me diff --git a/mmgen/msg.py b/mmgen/msg.py index 08f12529..ce25316e 100755 --- a/mmgen/msg.py +++ b/mmgen/msg.py @@ -186,7 +186,7 @@ class coin_msg: yield res hdr_data = { - 'message': ('Message:', lambda v: grnbg(v) ), + 'message': ('Message:', grnbg ), 'network': ('Network:', lambda v: v.replace('_',' ').upper() ), 'msghash_type': ('Message Hash Type:', lambda v: v ), 'addrlists': ('Address Ranges:', lambda v: fmt_list(v,fmt='bare') ), diff --git a/mmgen/obj.py b/mmgen/obj.py index 5f6d0771..fe1a81a0 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -284,15 +284,15 @@ class Int(int,Hilite,InitErrors): except Exception as e: return cls.init_fail(e,n) - def fmt(self,**kwargs): - return super().fmtc(self.__str__(),**kwargs) - @classmethod - def fmtc(cls,s,**kwargs): - return super().fmtc(s.__str__(),**kwargs) + def fmtc(cls,s,width,color=False): + return super().fmtc(str(s), width=width, color=color) + + def fmt(self,width,color=False): + return super().fmtc(str(self), width=width, color=color) def hl(self,**kwargs): - return super().colorize(self.__str__(),**kwargs) + return super().colorize(str(self), **kwargs) class NonNegativeInt(Int): min_val = 0 diff --git a/mmgen/ui.py b/mmgen/ui.py index 03ca61b3..026adf95 100755 --- a/mmgen/ui.py +++ b/mmgen/ui.py @@ -139,7 +139,8 @@ def do_license_msg(cfg,immed=False): return import mmgen.contrib.license as gpl - msg(gpl.warning) + from mmgen.cfg import gc + msg(gpl.warning.format(gc=gc)) from .term import get_char prompt = "Press 'w' for conditions and warranty info, or 'c' to continue: " diff --git a/mmgen/util2.py b/mmgen/util2.py index 9c34bb19..c491d3bf 100755 --- a/mmgen/util2.py +++ b/mmgen/util2.py @@ -130,7 +130,7 @@ def format_elapsed_hr(t,now=None,cached={}): if not e in cached: abs_e = abs(e) cached[e] = ' '.join( - '{} {}{}'.format(n,desc,suf(n)) for desc,n in ( + f'{n} {desc}{suf(n)}' for desc,n in ( ('day', abs_e // 86400), ('hour', abs_e // 3600 % 24), ('minute', abs_e // 60 % 60), diff --git a/pyproject.toml b/pyproject.toml index 57273cb4..bb9e3ee8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,19 +46,6 @@ disable = [ "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"]