Browse Source

use relative imports wherever possible

The MMGen Project 1 year ago
parent
commit
66f318b4ef

+ 2 - 2
mmgen/addrlist.py

@@ -405,8 +405,8 @@ class AddrList(MMGenObject): # Address info for a single seed ID
 	@property
 	@property
 	def file(self):
 	def file(self):
 		if not hasattr(self,'_file'):
 		if not hasattr(self,'_file'):
-			import mmgen.addrfile as mod
-			self._file = getattr( mod, type(self).__name__.replace('List','File') )(self)
+			from . import addrfile
+			self._file = getattr( addrfile, type(self).__name__.replace('List','File') )(self)
 		return self._file
 		return self._file
 
 
 class KeyAddrList(AddrList):
 class KeyAddrList(AddrList):

+ 1 - 1
mmgen/cfg.py

@@ -406,7 +406,7 @@ class Config(Lockable):
 			assert cfg is None, (
 			assert cfg is None, (
 				'Config(): ‘cfg’ cannot be used simultaneously with ' +
 				'Config(): ‘cfg’ cannot be used simultaneously with ' +
 				'‘opts_data’, ‘parsed_opts’ or ‘process_opts’' )
 				'‘opts_data’, ‘parsed_opts’ or ‘process_opts’' )
-			from mmgen.opts import UserOpts
+			from .opts import UserOpts
 			UserOpts(
 			UserOpts(
 				cfg          = self,
 				cfg          = self,
 				opts_data    = opts_data,
 				opts_data    = opts_data,

+ 2 - 2
mmgen/devinit.py

@@ -29,8 +29,8 @@ devtools_funcs = {
 }
 }
 
 
 def devtools_call(funcname,*args,**kwargs):
 def devtools_call(funcname,*args,**kwargs):
-	import mmgen.devtools
-	return getattr(mmgen.devtools,funcname)(*args,**kwargs)
+	from . import devtools
+	return getattr(devtools,funcname)(*args,**kwargs)
 
 
 def MMGenObject_call(methodname,*args,**kwargs):
 def MMGenObject_call(methodname,*args,**kwargs):
 	from .devtools import MMGenObjectMethods
 	from .devtools import MMGenObjectMethods

+ 2 - 2
mmgen/main.py

@@ -54,7 +54,7 @@ def launch(mod,package='mmgen'):
 			errmsg = repr(e.args[0])
 			errmsg = repr(e.args[0])
 
 
 		from collections import namedtuple
 		from collections import namedtuple
-		from mmgen.color import nocolor,yellow,red
+		from .color import nocolor,yellow,red
 
 
 		_o = namedtuple('exit_data',['color','exit_val','fs'])
 		_o = namedtuple('exit_data',['color','exit_val','fs'])
 		d = {
 		d = {
@@ -76,6 +76,6 @@ def launch(mod,package='mmgen'):
 
 
 	except SystemExit as e:
 	except SystemExit as e:
 		if os.getenv('MMGEN_EXEC_WRAPPER') and e.code != 0:
 		if os.getenv('MMGEN_EXEC_WRAPPER') and e.code != 0:
-			from mmgen.color import red
+			from .color import red
 			sys.stdout.write(red(f'{type(e).__name__}: {e}\n'))
 			sys.stdout.write(red(f'{type(e).__name__}: {e}\n'))
 		raise
 		raise

+ 3 - 4
mmgen/main_addrgen.py

@@ -21,8 +21,7 @@ mmgen-addrgen: Generate a series or range of addresses from an MMGen
                deterministic wallet
                deterministic wallet
 """
 """
 
 
-import mmgen.addrlist
-
+from . import addrlist
 from .cfg import gc,Config
 from .cfg import gc,Config
 from .addr import MMGenAddrType
 from .addr import MMGenAddrType
 from .wallet import Wallet
 from .wallet import Wallet
@@ -141,7 +140,7 @@ if cfg.keygen_backend:
 	from .keygen import check_backend
 	from .keygen import check_backend
 	check_backend( cfg, proto, cfg.keygen_backend, cfg.type )
 	check_backend( cfg, proto, cfg.keygen_backend, cfg.type )
 
 
-idxs = mmgen.addrlist.AddrIdxList( fmt_str=cfg._args.pop() )
+idxs = addrlist.AddrIdxList( fmt_str=cfg._args.pop() )
 
 
 from .fileutil import get_seed_file
 from .fileutil import get_seed_file
 sf = get_seed_file(cfg,1)
 sf = get_seed_file(cfg,1)
@@ -158,7 +157,7 @@ if cfg.no_addresses:
 elif cfg.viewkeys:
 elif cfg.viewkeys:
 	gen_clsname = 'ViewKeyAddrList'
 	gen_clsname = 'ViewKeyAddrList'
 
 
-al = getattr( mmgen.addrlist, gen_clsname )(
+al = getattr( addrlist, gen_clsname )(
 	cfg       = cfg,
 	cfg       = cfg,
 	proto     = proto,
 	proto     = proto,
 	seed      = ss_seed,
 	seed      = ss_seed,

+ 1 - 1
mmgen/objmethods.py

@@ -21,7 +21,7 @@ objmethods: Mixin classes for MMGen data objects
 """
 """
 
 
 import unicodedata
 import unicodedata
-import mmgen.color as color_mod
+from . import color as color_mod
 
 
 if 'MMGenObjectDevTools' in __builtins__: # added to builtins by devinit.init_dev()
 if 'MMGenObjectDevTools' in __builtins__: # added to builtins by devinit.init_dev()
 	MMGenObject = __builtins__['MMGenObjectDevTools']
 	MMGenObject = __builtins__['MMGenObjectDevTools']

+ 1 - 1
mmgen/proto/btc/tx/base.py

@@ -14,7 +14,7 @@ proto.btc.tx.base: Bitcoin base transaction class
 
 
 from collections import namedtuple
 from collections import namedtuple
 
 
-import mmgen.tx.base as TxBase
+from ....tx import base as TxBase
 from ....obj import MMGenList,HexStr
 from ....obj import MMGenList,HexStr
 from ....util import msg,make_chksum_6,die,pp_fmt
 from ....util import msg,make_chksum_6,die,pp_fmt
 
 

+ 2 - 2
mmgen/proto/btc/tx/bump.py

@@ -12,10 +12,10 @@
 proto.btc.tx.bump: Bitcoin transaction bump class
 proto.btc.tx.bump: Bitcoin transaction bump class
 """
 """
 
 
-import mmgen.tx.bump as TxBase
+from ....tx import bump as TxBase
+from ....util import msg
 from .new import New
 from .new import New
 from .completed import Completed
 from .completed import Completed
-from ....util import msg
 
 
 class Bump(Completed,New,TxBase.Bump):
 class Bump(Completed,New,TxBase.Bump):
 	desc = 'fee-bumped transaction'
 	desc = 'fee-bumped transaction'

+ 2 - 2
mmgen/proto/btc/tx/completed.py

@@ -12,10 +12,10 @@
 proto.btc.tx.completed: Bitcoin completed transaction class
 proto.btc.tx.completed: Bitcoin completed transaction class
 """
 """
 
 
-import mmgen.tx.completed as TxBase
-from .base import Base,scriptPubKey2addr
+from ....tx import completed as TxBase
 from ....obj import HexStr
 from ....obj import HexStr
 from ....util import msg,die
 from ....util import msg,die
+from .base import Base,scriptPubKey2addr
 
 
 class Completed(Base,TxBase.Completed):
 class Completed(Base,TxBase.Completed):
 	fn_fee_unit = 'satoshi'
 	fn_fee_unit = 'satoshi'

+ 2 - 2
mmgen/proto/btc/tx/new.py

@@ -12,10 +12,10 @@
 proto.btc.tx.new: Bitcoin new transaction class
 proto.btc.tx.new: Bitcoin new transaction class
 """
 """
 
 
-import mmgen.tx.new as TxBase
-from .base import Base
+from ....tx import new as TxBase
 from ....obj import MMGenTxID
 from ....obj import MMGenTxID
 from ....util import msg,fmt,make_chksum_6,die
 from ....util import msg,fmt,make_chksum_6,die
+from .base import Base
 
 
 class New(Base,TxBase.New):
 class New(Base,TxBase.New):
 	usr_fee_prompt = 'Enter transaction fee: '
 	usr_fee_prompt = 'Enter transaction fee: '

+ 2 - 2
mmgen/proto/btc/tx/online.py

@@ -14,9 +14,9 @@ proto.btc.tx.online: Bitcoin online signed transaction class
 
 
 import sys
 import sys
 
 
-import mmgen.tx.online as TxBase
-from .signed import Signed
+from ....tx import online as TxBase
 from ....util import msg,ymsg,rmsg,die
 from ....util import msg,ymsg,rmsg,die
+from .signed import Signed
 
 
 class OnlineSigned(Signed,TxBase.OnlineSigned):
 class OnlineSigned(Signed,TxBase.OnlineSigned):
 
 

+ 2 - 2
mmgen/proto/btc/tx/signed.py

@@ -12,9 +12,9 @@
 proto.btc.tx.signed: Bitcoin signed transaction class
 proto.btc.tx.signed: Bitcoin signed transaction class
 """
 """
 
 
-import mmgen.tx.signed as TxBase
-from .completed import Completed
+from ....tx import signed as TxBase
 from ....util import fmt,die
 from ....util import fmt,die
+from .completed import Completed
 
 
 class Signed(Completed,TxBase.Signed):
 class Signed(Completed,TxBase.Signed):
 
 

+ 1 - 1
mmgen/proto/btc/tx/status.py

@@ -14,7 +14,7 @@ proto.btc.tx.status: Bitcoin transaction status class
 
 
 import time
 import time
 
 
-import mmgen.tx.status as TxBase
+from ....tx import status as TxBase
 from ....util import msg,suf,die,secs_to_dhms
 from ....util import msg,suf,die,secs_to_dhms
 
 
 class Status(TxBase.Status):
 class Status(TxBase.Status):

+ 2 - 2
mmgen/proto/btc/tx/unsigned.py

@@ -12,10 +12,10 @@
 proto.btc.tx.unsigned: Bitcoin unsigned transaction class
 proto.btc.tx.unsigned: Bitcoin unsigned transaction class
 """
 """
 
 
-import mmgen.tx.unsigned as TxBase
-from .completed import Completed
+from ....tx import unsigned as TxBase
 from ....obj import CoinTxID,MMGenDict
 from ....obj import CoinTxID,MMGenDict
 from ....util import msg,msg_r,ymsg,suf,die
 from ....util import msg,msg_r,ymsg,suf,die
+from .completed import Completed
 
 
 class Unsigned(Completed,TxBase.Unsigned):
 class Unsigned(Completed,TxBase.Unsigned):
 	desc = 'unsigned transaction'
 	desc = 'unsigned transaction'

+ 1 - 1
mmgen/proto/eth/tx/base.py

@@ -14,7 +14,7 @@ proto.eth.tx.base: Ethereum base transaction class
 
 
 from collections import namedtuple
 from collections import namedtuple
 
 
-import mmgen.tx.base as TxBase
+from ....tx import base as TxBase
 from ....obj import HexStr,Int
 from ....obj import HexStr,Int
 
 
 class Base(TxBase.Base):
 class Base(TxBase.Base):

+ 1 - 1
mmgen/proto/eth/tx/bump.py

@@ -14,7 +14,7 @@ proto.eth.tx.bump: Ethereum transaction bump class
 
 
 from decimal import Decimal
 from decimal import Decimal
 
 
-import mmgen.tx.bump as TxBase
+from ....tx import bump as TxBase
 from .completed import Completed,TokenCompleted
 from .completed import Completed,TokenCompleted
 from .new import New,TokenNew
 from .new import New,TokenNew
 
 

+ 1 - 1
mmgen/proto/eth/tx/completed.py

@@ -12,7 +12,7 @@
 proto.eth.tx.completed: Ethereum completed transaction class
 proto.eth.tx.completed: Ethereum completed transaction class
 """
 """
 
 
-import mmgen.tx.completed as TxBase
+from ....tx import completed as TxBase
 from .base import Base,TokenBase
 from .base import Base,TokenBase
 
 
 class Completed(Base,TxBase.Completed):
 class Completed(Base,TxBase.Completed):

+ 2 - 2
mmgen/proto/eth/tx/new.py

@@ -14,13 +14,13 @@ proto.eth.tx.new: Ethereum new transaction class
 
 
 import json
 import json
 
 
-import mmgen.tx.new as TxBase
-from .base import Base,TokenBase
+from ....tx import new as TxBase
 from ....obj import Int,ETHNonce,MMGenTxID,Str,HexStr
 from ....obj import Int,ETHNonce,MMGenTxID,Str,HexStr
 from ....util import msg,is_int,is_hex_str,make_chksum_6,suf,die
 from ....util import msg,is_int,is_hex_str,make_chksum_6,suf,die
 from ....tw.ctl import TwCtl
 from ....tw.ctl import TwCtl
 from ....addr import is_mmgen_id,is_coin_addr
 from ....addr import is_mmgen_id,is_coin_addr
 from ..contract import Token
 from ..contract import Token
+from .base import Base,TokenBase
 
 
 class New(Base,TxBase.New):
 class New(Base,TxBase.New):
 	desc = 'transaction'
 	desc = 'transaction'

+ 3 - 3
mmgen/proto/eth/tx/online.py

@@ -12,10 +12,10 @@
 proto.eth.tx.online: Ethereum online signed transaction class
 proto.eth.tx.online: Ethereum online signed transaction class
 """
 """
 
 
-import mmgen.tx.online as TxBase
-from .signed import Signed,TokenSigned
-from .. import erigon_sleep
 from ....util import msg,rmsg,die
 from ....util import msg,rmsg,die
+from ....tx import online as TxBase
+from .. import erigon_sleep
+from .signed import Signed,TokenSigned
 
 
 class OnlineSigned(Signed,TxBase.OnlineSigned):
 class OnlineSigned(Signed,TxBase.OnlineSigned):
 
 

+ 2 - 2
mmgen/proto/eth/tx/signed.py

@@ -12,10 +12,10 @@
 proto.eth.tx.signed: Ethereum signed transaction class
 proto.eth.tx.signed: Ethereum signed transaction class
 """
 """
 
 
-import mmgen.tx.signed as TxBase
-from .completed import Completed,TokenCompleted
+from ....tx import signed as TxBase
 from ....obj import Str,CoinTxID,ETHNonce,HexStr
 from ....obj import Str,CoinTxID,ETHNonce,HexStr
 from ....addr import CoinAddr,TokenAddr
 from ....addr import CoinAddr,TokenAddr
+from .completed import Completed,TokenCompleted
 
 
 class Signed(Completed,TxBase.Signed):
 class Signed(Completed,TxBase.Signed):
 
 

+ 1 - 1
mmgen/proto/eth/tx/status.py

@@ -12,7 +12,7 @@
 proto.eth.tx.status: Ethereum transaction status class
 proto.eth.tx.status: Ethereum transaction status class
 """
 """
 
 
-import mmgen.tx.status as TxBase
+from ....tx import status as TxBase
 from ....util import msg,die,suf,capfirst
 from ....util import msg,die,suf,capfirst
 
 
 class Status(TxBase.Status):
 class Status(TxBase.Status):

+ 3 - 3
mmgen/proto/eth/tx/unsigned.py

@@ -14,12 +14,12 @@ proto.eth.tx.unsigned: Ethereum unsigned transaction class
 
 
 import json
 import json
 
 
-import mmgen.tx.unsigned as TxBase
-from .completed import Completed,TokenCompleted
-from ..contract import Token
+from ....tx import unsigned as TxBase
 from ....util import msg,msg_r
 from ....util import msg,msg_r
 from ....obj import Str,CoinTxID,ETHNonce,Int,HexStr
 from ....obj import Str,CoinTxID,ETHNonce,Int,HexStr
 from ....addr import CoinAddr,TokenAddr
 from ....addr import CoinAddr,TokenAddr
+from ..contract import Token
+from .completed import Completed,TokenCompleted
 
 
 class Unsigned(Completed,TxBase.Unsigned):
 class Unsigned(Completed,TxBase.Unsigned):
 	desc = 'unsigned transaction'
 	desc = 'unsigned transaction'

+ 2 - 2
mmgen/protocol.py

@@ -101,8 +101,8 @@ class CoinProtocol(MMGenObject):
 				self.keccak_256 = get_keccak(cfg)
 				self.keccak_256 = get_keccak(cfg)
 
 
 			if need_amt:
 			if need_amt:
-				import mmgen.amt
-				self.coin_amt = getattr(mmgen.amt,self.coin_amt)
+				from . import amt
+				self.coin_amt = getattr(amt,self.coin_amt)
 				self.max_tx_fee = self.coin_amt(self.max_tx_fee) if hasattr(self,'max_tx_fee') else None
 				self.max_tx_fee = self.coin_amt(self.max_tx_fee) if hasattr(self,'max_tx_fee') else None
 			else:
 			else:
 				self.coin_amt = None
 				self.coin_amt = None

+ 1 - 1
mmgen/term.py

@@ -294,7 +294,7 @@ def init_term(cfg,noecho=False):
 
 
 	term.init(noecho=noecho)
 	term.init(noecho=noecho)
 
 
-	import mmgen.term as self
+	from . import term as self
 	for var in ('get_char','get_char_raw','kb_hold_protect','get_terminal_size'):
 	for var in ('get_char','get_char_raw','kb_hold_protect','get_terminal_size'):
 		setattr( self, var, getattr(term,var) )
 		setattr( self, var, getattr(term,var) )
 
 

+ 1 - 1
mmgen/tool/help.py

@@ -20,7 +20,7 @@
 tool.help: Help screen routines for the 'mmgen-tool' utility
 tool.help: Help screen routines for the 'mmgen-tool' utility
 """
 """
 
 
-from mmgen import main_tool
+from .. import main_tool
 
 
 from .common import tool_cmd_base
 from .common import tool_cmd_base
 
 

+ 2 - 2
mmgen/ui.py

@@ -138,8 +138,8 @@ def do_license_msg(cfg,immed=False):
 	if cfg.quiet or cfg.no_license or cfg.yes or not cfg.stdin_tty:
 	if cfg.quiet or cfg.no_license or cfg.yes or not cfg.stdin_tty:
 		return
 		return
 
 
-	import mmgen.contrib.license as gpl
-	from mmgen.cfg import gc
+	from .contrib import license as gpl
+	from .cfg import gc
 	msg(gpl.warning.format(gc=gc))
 	msg(gpl.warning.format(gc=gc))
 
 
 	from .term import get_char
 	from .term import get_char

+ 4 - 6
mmgen/util.py

@@ -163,8 +163,8 @@ def die(ev,s='',stdout=False):
 		else:
 		else:
 			raise MMGenError(ev,s,stdout)
 			raise MMGenError(ev,s,stdout)
 	elif isinstance(ev,str):
 	elif isinstance(ev,str):
-		import mmgen.exception
-		raise getattr(mmgen.exception,ev)(s)
+		from . import exception
+		raise getattr(exception,ev)(s)
 	else:
 	else:
 		raise ValueError(f'{ev}: exit value must be string or int instance')
 		raise ValueError(f'{ev}: exit value must be string or int instance')
 
 
@@ -396,10 +396,8 @@ class oneshot_warning:
 	def do(self,wcls,div,fmt_args,reverse):
 	def do(self,wcls,div,fmt_args,reverse):
 
 
 		def do_warning():
 		def do_warning():
-			import mmgen.color
-			message = getattr(wcls,'message')
-			color = getattr( mmgen.color, getattr(wcls,'color') )
-			msg(color('WARNING: ' + message.format(*fmt_args)))
+			from . import color
+			msg(getattr(color, getattr(wcls,'color'))('WARNING: ' + getattr(wcls,'message').format(*fmt_args)))
 
 
 		if not hasattr(wcls,'data'):
 		if not hasattr(wcls,'data'):
 			setattr(wcls,'data',[])
 			setattr(wcls,'data',[])

+ 1 - 1
mmgen/wallet/enc.py

@@ -19,7 +19,7 @@ from .base import wallet
 class wallet(wallet):
 class wallet(wallet):
 
 
 	def __init__(self,*args,**kwargs):
 	def __init__(self,*args,**kwargs):
-		from mmgen.crypto import Crypto
+		from ..crypto import Crypto
 		self.crypto = Crypto(self.cfg)
 		self.crypto = Crypto(self.cfg)
 		super().__init__(*args,**kwargs)
 		super().__init__(*args,**kwargs)
 
 

+ 1 - 1
test/overlay/fakemods/mmgen/tw/view.py

@@ -1,5 +1,5 @@
 import os as overlay_fake_os
 import os as overlay_fake_os
-import mmgen.tw.view_orig as overlay_fake_orig_mod
+from . import view_orig as overlay_fake_orig_mod
 
 
 from .view_orig import *
 from .view_orig import *