Skip to content

Instantly share code, notes, and snippets.

@kotfic
Last active April 29, 2016 17:55
Show Gist options
  • Save kotfic/6e6e34d297479fa8ea62790c1c9ce36a to your computer and use it in GitHub Desktop.
Save kotfic/6e6e34d297479fa8ea62790c1c9ce36a to your computer and use it in GitHub Desktop.
In [2]: from analysis import PythonAnalysis
In [3]: p = PythonAnalysis(name='sum', path='/tmp/sum.py')
In [4]: p.inputs
Out[4]:
[{'kwarg': False,
'name': 'a',
'optional': False,
'type': 'number',
'vararg': False},
{'kwarg': False,
'name': 'b',
'optional': False,
'type': 'number',
'vararg': False}]
In [5]: p(2, 2)
Out[5]: 4
In [6]: from girder_worker_analysis import GirderWorkerPythonAnalysis
In [7]: p = GirderWorkerPythonAnalysis(name='sum', path='/tmp/sum.py')
In [8]: p.inputs
Out[8]:
[{'format': 'number', 'id': 'a', 'type': 'number'},
{'format': 'number', 'id': 'b', 'type': 'number'}]
In [9]: p.outputs
Out[9]: [{'format': 'number', 'id': 'c', 'type': 'number'}]
In [10]: p.spec
Out[10]:
{'inputs': [{'format': 'number', 'id': 'a', 'type': 'number'},
{'format': 'number', 'id': 'b', 'type': 'number'}],
'mode': 'python',
'output': [{'format': 'number', 'id': 'c', 'type': 'number'}],
'script': "\nimport imp\nfp, pathname, desc = imp.find_module('sum', ['/tmp'])\nmodule = imp.load_module('sum', fp, pathname, desc)\nc = module.run(a, b)\n"}
def run(a, b):
"""Sum a list of numbers passed to run
:type a: number
:format a: number
:type b: number
:format b: number
:return type c: number
:return format c: number
"""
return sum([a, b])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment