Skip to content

Commit

Permalink
Issue 100: enhance rule 01 (#105)
Browse files Browse the repository at this point in the history
* updated factory comments

The abstract factories are crucial but not well documented. Updated the documentation dawgie to help explain what needs to be done and how it should be done.

* extend rule 01

The factory methods that dawgie depends on were not being fully checked. The number of arguments was being checked but that let errors creep through with defaults and types. Some parts of the system require default values for the factory arguments. Therefore, extended the rule 01 testing to be parameter count first, then default values followed by types.

* updated the testing
  • Loading branch information
al-niessner authored Jan 27, 2020
1 parent b82effa commit ad879d9
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 21 deletions.
10 changes: 10 additions & 0 deletions Python/dawgie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ class Distribution(enum.Enum):
pass

# An enumeration of allowable factories in ae/<task>/__init__.py
# The should follow this form:
# analysis (prefix:str, ps_hint:int=0, runid:int=-1)
# events()
# regression (prefix:str, ps_hint:int=0, target:str='__none__')
# task (prefix:str, ps_hint:int=0, runid:int=-1, target:str='__none__')
# where
# prefix must be supplied
# ps_hint is a pool size hint for multiprocessing and should default to 0
# runid is the data to retrieve and should default to -1
# target is the name to be used for look up and should default to __none__
class Factories(enum.Enum):
analysis = enum.auto() # create an dawgie.Analysis for all targets
events = enum.auto() # list of dawgie.EVENT
Expand Down
57 changes: 45 additions & 12 deletions Python/dawgie/tools/compliant.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,30 @@ def main():
return yes

def rule_01 (task):
'''Verify that their is a factory function.
The architecture requires that each package within dawgie.ae have a
task() if they want to be detected. Obviously, if -t or --task-list
was not specified, then this unit will always pass because auto-detection
uses the task() in the package to identify the package as a task.
'''Verify that there is at least one factory function.
The architecture requires that AE packages either have ignore=True attribute
or one of the abstract factory names defined by dawgie.Factories. Each of
these abstract factories requires some number of parameters and some have
default values. They should look like:
analysis (prefix:str, ps_hint:int=0, runid:int=-1)
events()
regression (prefix:str, ps_hint:int=0, target:str='__none__')
task (prefix:str, ps_hint:int=0, runid:int=-1, target:str='__none__')
where
prefix must be supplied
ps_hint is a pool size hint for multiprocessing and should default to 0
runid is the data to retrieve and should default to -1
target is the name to be used for look up and should default to __none__
'''
fargs = {dawgie.Factories.analysis:3,
dawgie.Factories.task:4,
dawgie.Factories.events:0,
dawgie.Factories.regress:3}
fargs = {dawgie.Factories.analysis:(3, ['', '=0', '=-1'], ['','int','int']),
dawgie.Factories.events:(0, [], []),
dawgie.Factories.regress:(3, ['', '=0', "='__none__'"],
['','int','str']),
dawgie.Factories.task:(4, ['', '=0', '=-1', "='__none__'"],
['','int','int','str'])}
findings = []
mod = importlib.import_module (task)
names = dir (mod)
Expand All @@ -222,9 +235,29 @@ def rule_01 (task):
f = getattr (mod, e.name)
findings.append (inspect.isfunction (f) and
len (inspect.signature (f).parameters.keys()) ==
fargs[e])
fargs[e][0])

if findings[-1]:
findings.append (True)
for d,v in zip (fargs[e][1],
inspect.signature (f).parameters.values()):
if d: findings[-1] &= str(v).endswith (d)
pass

if not findings[-1]: logging.error ('Number of arguments for task %s in package %s', e.name, task)
if findings[-1]:
findings.append (True)
for d,v in zip (fargs[e][2],
inspect.signature (f).parameters.values()):
if d: findings[-1] &= 0 < str(v).find (':' + d + '=')
pass
if not findings[-1]:
logging.error ('Args not typed of factory %s in package %s',
e.name, task)
pass
else: logging.error ('Missing defaults of factory %s in package %s',
e.name, task)
else: logging.error ('Number of arguments for factory %s in package %s',
e.name, task)
pass
return all (findings)

Expand Down
2 changes: 1 addition & 1 deletion Test/ae/disk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
'''
ignore = False # forces the pipeline to ignore this package (aka task)

def task (prefix, ps_hint=0, runid=-1, target='__none__'):
def task (prefix, ps_hint:int=0, runid:int=-1, target:str='__none__'):
import ae.disk.bot
return ae.disk.bot.Actor(prefix, ps_hint, runid, target)
2 changes: 1 addition & 1 deletion Test/ae/feedback/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
'''
ignore = False # forces the pipeline to ignore this package (aka task)

def task (prefix, ps_hint=0, runid=-1, target='__none__'):
def task (prefix, ps_hint:int=0, runid:int=-1, target:str='__none__'):
import ae.feedback.bot
return ae.feedback.bot.Actor(prefix, ps_hint, runid, target)
4 changes: 2 additions & 2 deletions Test/ae/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
ignore = False # forces the pipeline to ignore this package (aka task)

# pylint: disable=redefined-builtin
def analysis (prefix, ps_hint=0, runid=-1):
def analysis (prefix, ps_hint:int=0, runid:int=-1):
import ae.network.bot
return ae.network.bot.Actor(prefix, ps_hint, runid)

Expand All @@ -48,6 +48,6 @@ def events():
import dawgie
return [dawgie.schedule(analysis, ae.network.bot.Analyzer(), True)]

def task (prefix, ps_hint=0, runid=-1, target='__none__'):
def task (prefix, ps_hint:int=0, runid:int=-1, target:str='__none__'):
import ae.network.bot
return ae.network.bot.Agent(prefix, ps_hint, runid, target)
2 changes: 1 addition & 1 deletion Test/ae/noio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
'''
ignore = False # forces the pipeline to ignore this package (aka task)

def task (prefix, ps_hint=0, runid=-1, target='__none__'):
def task (prefix, ps_hint:int=0, runid:int=-1, target:str='__none__'):
import ae.noio.bot
return ae.noio.bot.Actor(prefix, ps_hint, runid, target)
4 changes: 2 additions & 2 deletions Test/ae/review/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
ignore = False # forces the pipeline to ignore this package (aka task)

# pylint: disable=redefined-builtin
def analysis (prefix, ps_hint=0, runid=-1):
def analysis (prefix, ps_hint:int=0, runid:int=-1):
import ae.review.bot
return ae.review.bot.Actor(prefix, ps_hint, runid)

def regress (prefix, ps_hint=0, target='__none__'):
def regress (prefix, ps_hint:int=0, target:str='__none__'):
import ae.review.bot
return ae.review.bot.Regress(prefix, ps_hint, target)
4 changes: 2 additions & 2 deletions Test/bae/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
ignore = False # forces the pipeline to ignore this package (aka task)

# pylint: disable=redefined-builtin
def analysis (prefix, ps_hint=0, runid=-1):
def analysis (prefix, ps_hint:int=0, runid:int=-1):
import bae.network.bot
return bae.network.bot.Actor(prefix, ps_hint, runid)

Expand All @@ -48,6 +48,6 @@ def events():
return [dawgie.EVENT (dawgie.ALG_REF(None, None),
dawgie.MOMENT(True, True, None, None, None))]

def task (prefix, ps_hint=0, runid=-1, target='__none__'):
def task (prefix, ps_hint:int=0, runid:int=-1, target:str='__none__'):
import bae.network.bot
return bae.network.bot.Agent(prefix, ps_hint, runid, target)

0 comments on commit ad879d9

Please sign in to comment.