Skip to content

Instantly share code, notes, and snippets.

@malleor
Last active December 11, 2015 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malleor/4536629 to your computer and use it in GitHub Desktop.
Save malleor/4536629 to your computer and use it in GitHub Desktop.
Script execution concept Opt. 2: Denoted functions

Concept

  • The algorithm is a function, exposed to the framework through the script decorator.
  • The decorator describes the algorithm's metadata.
  • Input parameters are given by keyword arguments (all with defaults).
  • Output parameters are not declared.
  • The documentation is given as a docstring.
  • The algorithm is identified as module_name.func_name.

Pros

  • Utilizing the language syntax and features to manage execution.
  • Concise declaration of the algorithm.
  • The direct call to the denoted function might actually call execute for the execution to be managed by the framework. If so, there's no easy way to hack it.

Cons

  • More bootstrapping.
from glob import glob
from os import cwd
from os.path import join, split, splitext
from frames import execute, script
@script(author='John Doe', version='0.6', multithreaded=False) # Declare the algorithm's info.
def load_clouds(cloud_extension='copsxml'): # Name and input params are given a a function with kwargs.
''' Loads all clouds of given format from the CWD. ''' # Documentation in a docstring.
cloud_ids = []
for path in glob(join(cwd(), '*.'+cloud_extension)):
name = split(splitext(path)[0])[-1]
cloud_id = execute('import_cloud', path, name)
cloud_ids.append(cloud_id)
return {'cloud_ids': cloud_ids} # Results as a return value.
from frames import script
@script
def hello():
print 'Hello, framework.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment