Change aux module to unpopulated base module name

This commit is contained in:
nolash 2021-07-05 11:28:27 +02:00
parent bc8851ad06
commit 2f09ac9110
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 46 additions and 27 deletions

View File

@ -27,4 +27,4 @@ licence_files =
include_package_data = True include_package_data = True
python_requires = >= 3.6 python_requires = >= 3.6
packages = packages =
cic_eth.aux.erc20_demurrage_token cic_eth_aux.erc20_demurrage_token

View File

@ -7,7 +7,7 @@ import datetime
import celery import celery
# cic-eth imports # cic-eth imports
from cic_eth.aux.erc20_demurrage_token import ( from cic_eth_aux.erc20_demurrage_token import (
DemurrageCalculationTask, DemurrageCalculationTask,
aux_setup, aux_setup,
) )
@ -33,7 +33,7 @@ def test_demurrage_calulate_task(
since = datetime.datetime.utcnow() - datetime.timedelta(minutes=1) since = datetime.datetime.utcnow() - datetime.timedelta(minutes=1)
s = celery.signature( s = celery.signature(
'cic_eth.aux.erc20_demurrage_token.get_adjusted_balance', 'cic_eth_aux.erc20_demurrage_token.get_adjusted_balance',
[ [
demurrage_token_symbol, demurrage_token_symbol,
1000, 1000,

View File

@ -196,42 +196,61 @@ connect_token_registry(rpc, chain_spec)
# detect aux # detect aux
# TODO: move to separate file # TODO: move to separate file
aux_dir = os.path.join(script_dir, '..', '..', 'aux') #aux_dir = os.path.join(script_dir, '..', '..', 'aux')
aux = [] aux = []
if args.aux_all: if args.aux_all:
if len(args.aux) > 0: if len(args.aux) > 0:
logg.warning('--aux-all is set so --aux will have no effect') logg.warning('--aux-all is set so --aux will have no effect')
for v in os.listdir(aux_dir): for p in sys.path:
if v[:1] == '.': logg.debug('checking for aux modules in {}'.format(p))
logg.debug('dotfile, skip {}'.format(v)) aux_dir = os.path.join(p, 'cic_eth_aux')
continue
aux_mod_path = os.path.join(aux_dir, v)
st = os.stat(aux_mod_path)
if not stat.S_ISDIR(st.st_mode):
logg.debug('not a dir, skip {}'.format(v))
continue
aux_mod_file = os.path.join(aux_dir, v,'__init__.py')
try: try:
st = os.stat(aux_mod_file) d = os.listdir(aux_dir)
except FileNotFoundError: except FileNotFoundError:
logg.debug('__init__.py not found, skip {}'.format(v)) logg.debug('no aux module found in {}'.format(aux_dir))
continue continue
aux.append(v) for v in d:
if v[:1] == '.':
logg.debug('dotfile, skip {}'.format(v))
continue
aux_mod_path = os.path.join(aux_dir, v)
st = os.stat(aux_mod_path)
if not stat.S_ISDIR(st.st_mode):
logg.debug('not a dir, skip {}'.format(v))
continue
aux_mod_file = os.path.join(aux_dir, v,'__init__.py')
try:
st = os.stat(aux_mod_file)
except FileNotFoundError:
logg.debug('__init__.py not found, skip {}'.format(v))
continue
aux.append(v)
logg.debug('found module {} in {}'.format(v, aux_dir))
elif len(args.aux) > 0: elif len(args.aux) > 0:
for v in args.aux: for p in sys.path:
aux_mod_file = os.path.join(aux_dir, v,'__init__.py') v_found = None
try: for v in args.aux:
st = os.stat(aux_mod_file) aux_dir = os.path.join(p, 'cic_eth_aux')
except FileNotFoundError: aux_mod_file = os.path.join(aux_dir, v, '__init__.py')
logg.critical('cannot find explicity requested aux module {}'.format(v)) try:
st = os.stat(aux_mod_file)
v_found = v
except FileNotFoundError:
logg.debug('cannot find explicity requested aux module {} in path {}'.format(v, aux_dir))
continue
if v_found == None:
logg.critical('excplicity requested aux module {} not found in any path'.format(v))
sys.exit(1) sys.exit(1)
logg.info('aux module {} found in path'.format(v))
logg.info('aux module {} found in path {}'.format(v, aux_dir))
aux.append(v) aux.append(v)
for v in aux: for v in aux:
mod = importlib.import_module('cic_eth.aux.' + v) mname = 'cic_eth_aux.' + v
mod.setup(rpc, config) mod = importlib.import_module(mname)
mod.aux_setup(rpc, config)
logg.info('loaded aux module {}'.format(mname))
def main(): def main():