def build(): runtime = metadata.get('runtime') language = get_language_name_for_runtime(runtime) if language == 'python': # Use virtualenv and pip if not os.path.isfile('venv'): create_virtualenv('.') print run_in_virtualenv('pip install -r requirements.txt') else: # Fall back to a Makefile. try: make_log = check_output(['make'], stderr=STDOUT) for line in make_log.rstrip().split("\n"): say(line) except CalledProcessError as e: for line in e.output.rstrip().split("\n"): say(line) raise ClickException('make failure')
def create(function, runtime): runtime = get_sane_runtime(runtime) ext = get_file_extension_for_runtime(runtime) func_dir = function func_file = os.path.join(func_dir, '%s.%s' % (function, ext)) for path in (func_dir, func_file): if os.path.exists(path): raise ClickException('Path "%s" already exists.' % path) os.mkdir(func_dir) template_name = get_language_name_for_runtime(runtime) render_template(template_name, function, output_filename="%s.%s" % (function, ext)) if get_language_name_for_runtime(runtime) == 'python': create_virtualenv(function) render_template('requirements', function, output_filename='requirements.txt') render_template('gitignore-python', function, output_filename='.gitignore') else: render_template('makefile', function, output_filename='Makefile') render_template('gitignore', function, output_filename='.gitignore') our_metadata = { 'function': function, 'runtime': runtime, 'language': get_language_name_for_runtime(runtime), 'timeout': metadata.get('timeout') } metadata.write(subdirectory=function, **our_metadata) say('%s created as %s' % (function, func_file))