<commit_before>#!/usr/bin/env python

import os
import click
import yaml

from colors import red
from glob import glob
from subprocess import check_output
from brume.template import CfnTemplate
from brume.stack import Stack


def load_configuration(config_file='brume.yml'):
    """Return the YAML configuration for a project based on the `config_file` template."""
    from jinja2 import Template

    def env(key):
        """Return the value of the `key` environment variable."""
        try:
            os.environ[key]
        except KeyError:
            print(red('[ERROR] No environment variable with key {}'.format(key)))
            exit(1)

    def git_commit():
        """Return the SHA1 of the latest Git commit (HEAD)."""
        return check_output(['git', 'rev-parse', '--short', 'HEAD']).strip()

    def git_branch():
        """Return the name of the current Git branch."""
        return check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip()

    template = Template(open(config_file, 'r').read())
    return yaml.load(template.render(env=env, git_commit=git_commit(), git_branch=git_branch()))


conf = load_configuration()
s3_config = conf['templates']
cf_config = conf['stack']


def collect_templates():
    return [CfnTemplate(t) for t in glob('*.cform')]


@click.command()
def config():
    """Print the current stack confguration."""
    print(yaml.dump(conf))


@click.command()
def create():
    """Create a new CloudFormation stack."""
    stack = Stack(cf_config)
    stack.create()
    stack.tail()


@click.command()
def update():
    """Update an existing CloudFormation stack."""
    stack = Stack(cf_config)
    stack.update()
    stack.tail()


@click.command()
def deploy():
    """Create or update a CloudFormation stack."""
    stack = Stack(cf_config)
    stack.create_or_update()
    stack.tail()


@click.command()
def delete():
    """Delete a CloudFormation stack."""
    stack = Stack(cf_config)
    stack.delete()
    stack.tail()


@click.command()
def validate():
    """Validate CloudFormation templates."""
    templates = collect_templates()
    return map(lambda t: t.validate(), templates)


@click.command()
def events():
    """Tail the events of the stack."""
    Stack(cf_config).tail()


@click.command()
@click.option('--bucket', required=True, help='Name of the bucket')
@click.option('--prefix', required=True, help='Prefix to the file name')
def upload(templates, bucket, path_prefix):
    """Upload CloudFormation templates to S3."""
    [t.upload(bucket, path_prefix) for t in templates]
    return templates<commit_msg>Attempt to fix imports<commit_after>#!/usr/bin/env python

import os
import click
import yaml

from colors import red
from glob import glob
from subprocess import check_output
import brume


def load_configuration(config_file='brume.yml'):
    """Return the YAML configuration for a project based on the `config_file` template."""
    from jinja2 import Template

    def env(key):
        """Return the value of the `key` environment variable."""
        try:
            os.environ[key]
        except KeyError:
            print(red('[ERROR] No environment variable with key {}'.format(key)))
            exit(1)

    def git_commit():
        """Return the SHA1 of the latest Git commit (HEAD)."""
        return check_output(['git', 'rev-parse', '--short', 'HEAD']).strip()

    def git_branch():
        """Return the name of the current Git branch."""
        return check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip()

    template = Template(open(config_file, 'r').read())
    return yaml.load(template.render(env=env, git_commit=git_commit(), git_branch=git_branch()))


conf = load_configuration()
s3_config = conf['templates']
cf_config = conf['stack']


def collect_templates():
    return [brume.CfnTemplate(t) for t in glob('*.cform')]


@click.command()
def config():
    """Print the current stack confguration."""
    print(yaml.dump(conf))


@click.command()
def create():
    """Create a new CloudFormation stack."""
    stack = brume.Stack(cf_config)
    stack.create()
    stack.tail()


@click.command()
def update():
    """Update an existing CloudFormation stack."""
    stack = brume.Stack(cf_config)
    stack.update()
    stack.tail()


@click.command()
def deploy():
    """Create or update a CloudFormation stack."""
    stack = brume.Stack(cf_config)
    stack.create_or_update()
    stack.tail()


@click.command()
def delete():
    """Delete a CloudFormation stack."""
    stack = brume.Stack(cf_config)
    stack.delete()
    stack.tail()


@click.command()
def validate():
    """Validate CloudFormation templates."""
    templates = collect_templates()
    return map(lambda t: t.validate(), templates)


@click.command()
def events():
    """Tail the events of the stack."""
    brume.Stack(cf_config).tail()


@click.command()
@click.option('--bucket', required=True, help='Name of the bucket')
@click.option('--prefix', required=True, help='Prefix to the file name')
def upload(templates, bucket, path_prefix):
    """Upload CloudFormation templates to S3."""
    [t.upload(bucket, path_prefix) for t in templates]
    return templates
{'fraction_non_alphanumeric': 0.14684910387357872, 'fraction_numerical': 0.001927153594141453, 'mean_word_length': 3.675675675675676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '543310', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1507, 'n_words': 458}