<commit_before># Third Party
from invoke import task

DOCKER_COMPOSE_RUN_OPT = "docker-compose -f local.yml run {opt} --rm {service} {cmd}"
DOCKER_COMPOSE_RUN_OPT_USER = DOCKER_COMPOSE_RUN_OPT.format(
    opt="-u $(id -u):$(id -g) {opt}", service="{service}", cmd="{cmd}"
)
DOCKER_COMPOSE_RUN = DOCKER_COMPOSE_RUN_OPT.format(
    opt="", service="{service}", cmd="{cmd}"
)
DJANGO_RUN = DOCKER_COMPOSE_RUN.format(service="muckrock_django", cmd="{cmd}")
DJANGO_RUN_USER = DOCKER_COMPOSE_RUN_OPT_USER.format(
    opt="", service="muckrock_django", cmd="{cmd}"
)

# Release
# --------------------------------------------------------------------------------


@task(aliases=["prod", "p"])
def production(c):
    """Merge your dev branch into master and push to production"""
    c.run("git pull origin dev")
    c.run("git checkout master")
    c.run("git pull origin master")
    c.run("git merge dev")
    c.run("git push origin master")
    c.run("git checkout dev")
    c.run("git push origin dev")


@task
def staging(c):
    """Push out staging"""
    c.run("git push origin staging")


# Test
# --------------------------------------------------------------------------------


@task
def test(c, test_path="", reuse="0", capture=False, warning=False):
    """Run all tests, or a specific subset of tests"""
    cmd = DOCKER_COMPOSE_RUN_OPT_USER.format(
        opt="-e REUSE_DB={reuse}".format(reuse=reuse),
        service="muckrock_django",
        cmd="python {warn} manage.py test {test_path} {capture} "
        "--settings=muckrock.settings.test".format(
            warn="-Wd" if warning else "",
            test_path=test_path,
            capture="--nologcapture" if not capture else "",
        ),
    )
    c.run(cmd)


@task
def coverage(c, settings="test", reuse="0"):
    """Run the tests and generate a coverage report"""
    cmd = DOCKER_COMPOSE_RUN_OPT_USER.format(
        opt="-e REUSE_DB={reuse}".format(reuse=reuse),
        service="muckrock_django",
        cmd="sh -c 'coverage erase && "
        'coverage run --branch --source muckrock --omit="*/migrations/*" '
        "manage.py test --settings=muckrock.settings.{settings} && "
        "coverage html -i'".format(settings=settings),
    )
    c.run(cmd)


# Code Quality
# --------------------------------------------------------------------------------


@task
def pylint(c):
    """Run the linter"""
    c.run(
        DOCKER_COMPOSE_RUN_OPT.format(
            opt="-e DJANGO_SETTINGS_MODULE=muckrock.settings.local",
            service="muckrock_django",
            cmd="pylint muckrock --rcfile=config/pylint.conf",
        )
    )


@task
def format(c):
    """Format your code"""
    c.run(
        DJANGO_RUN_USER.format(
            cmd="black muckrock --exclude migrations\\|vendor && isort -rc muckrock"
        )
    )


@task(name="format-check")
def format_check(c):
    """Check your code format"""
    c.run(
        DJANGO_RUN_USER.format(
            cmd="black --check muckrock --exclude migrations\\|vendor && "
            "isort --check-only -rc muckrock"
        )
    )


# Run
# --------------------------------------------------------------------------------


@task
def up(c):<commit_msg>update invoke tasks for codeship<commit_after># Third Party
from invoke import task

DOCKER_COMPOSE_RUN_OPT = "docker-compose -f local.yml run {opt} --rm {service} {cmd}"
DOCKER_COMPOSE_RUN_OPT_USER = DOCKER_COMPOSE_RUN_OPT.format(
    opt="-u $(id -u):$(id -g) {opt}", service="{service}", cmd="{cmd}"
)
DOCKER_COMPOSE_RUN = DOCKER_COMPOSE_RUN_OPT.format(
    opt="", service="{service}", cmd="{cmd}"
)
DJANGO_RUN = DOCKER_COMPOSE_RUN.format(service="muckrock_django", cmd="{cmd}")
DJANGO_RUN_USER = DOCKER_COMPOSE_RUN_OPT_USER.format(
    opt="", service="muckrock_django", cmd="{cmd}"
)

# Release
# --------------------------------------------------------------------------------


@task(aliases=["prod", "p"])
def production(c):
    """Merge your dev branch into master and push to production"""
    c.run("git pull origin dev")
    c.run("git checkout master")
    c.run("git pull origin master")
    c.run("git merge dev")
    c.run("git push origin master")
    c.run("git checkout dev")
    c.run("git push origin dev")


@task
def staging(c):
    """Push out staging"""
    c.run("git push origin staging")


# Test
# --------------------------------------------------------------------------------


@task
def test(c, test_path="", reuse="0", capture=False, warning=False):
    """Run all tests, or a specific subset of tests"""
    cmd = DOCKER_COMPOSE_RUN_OPT_USER.format(
        opt="-e REUSE_DB={reuse}".format(reuse=reuse),
        service="muckrock_django",
        cmd="python {warn} manage.py test {test_path} {capture} "
        "--settings=muckrock.settings.test".format(
            warn="-Wd" if warning else "",
            test_path=test_path,
            capture="--nologcapture" if not capture else "",
        ),
    )
    c.run(cmd)


@task
def coverage(c, settings="test", reuse="0", codeship=False):
    """Run the tests and generate a coverage report"""
    if codeship:
        settings = "codeship"
    cmds = [
        "coverage erase",
        'coverage run --branch --source muckrock --omit="*/migrations/*" '
        f"manage.py test --settings=muckrock.settings.{settings}",
        "coverage html -i",
    ]
    if codeship:
        for cmd in cmds:
            c.run(cmd)
    else:
        sh_cmd = " && ".join(cmds)
        cmd = DOCKER_COMPOSE_RUN_OPT_USER.format(
            opt="-e REUSE_DB={reuse}".format(reuse=reuse),
            service="muckrock_django",
            cmd=f"sh -c '{sh_cmd}'",
        )
        c.run(cmd)


# Code Quality
# --------------------------------------------------------------------------------


@task
def pylint(c, codeship=False):
    """Run the linter"""
    cmd = "pylint muckrock --rcfile=config/pylint.conf"
    if codeship:
        c.run(cmd)
    else:
        c.run(
            DOCKER_COMPOSE_RUN_OPT.format(
                opt="-e DJANGO_SETTINGS_MODULE=muckrock.settings.local",
                service="muckrock_django",
                cmd=cmd,
            )
        )


@task
def format(c):
    """Format your code"""
    c.run(
        DJANGO_RUN_USER.format(
            cmd="black muckrock --exclude migrations\\|vendor && isort -rc muckrock"
        )
    )


@task(name="format-check")
def format_check(c):
    """Check your code format"""
    c.run(
        DJANGO_RUN_USER.format(
            cmd="black --check muckrock --exclude migrations\\|vendor && "
            "isort --check-only -rc muckrock"
        )
    )


# Run
# --------------------------------------------------------------------------------


@task
def up(c):
{'fraction_non_alphanumeric': 0.23398245874832763, 'fraction_numerical': 0.0005946187007581388, 'mean_word_length': 1.970419426048565, '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': '4238882', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2077, 'n_words': 459}