<commit_before>import os
import tempfile
from fabric.api import *

SITE_DIR = "site"
WHITELIST_DIRS = [".git",]
WHITELIST_FILES = [ ".gitignore", ]

SANITY_CHECK_PROJECT_FILES = ["fabfile.py", "setup.py", "mkdocs.yml"]
SANITY_CHECK_BUILD_FILES = ["index.html", "js", "css"]

def _splitpath(path):
    path = os.path.normpath(path)
    return path.split(os.sep)

def deploy_docs():
    # Sanity check dir.
    root_dir = os.getcwd()
    assert all([os.path.exists(os.path.join(root_dir,f)) for f in SANITY_CHECK_PROJECT_FILES])

    local("rm -rf %s" % SITE_DIR)
    local("mkdocs build")
    tempdir = tempfile.mkdtemp()

    local("mv %s/* %s" % (SITE_DIR, tempdir))
    
    current_branch = local("git rev-parse --abbrev-ref HEAD", capture=True)
    last_commit = local("git log -1 --pretty=\%B", capture=True)

    # Add the new site to build
    local("git checkout gh-pages")
    
    # Sanity check dir.
    root_dir = os.getcwd()
    assert all([os.path.exists(os.path.join(root_dir,f)) for f in SANITY_CHECK_BUILD_FILES])


    for root, dirs, files in os.walk(root_dir, topdown=False):
        for name in files:
            if not name in WHITELIST_FILES and not any([r in WHITELIST_DIRS for r in _splitpath(root)]):
                # print "removing %s" % (os.path.join(root, name))
                os.remove(os.path.join(root, name))
        for name in dirs:
            if not name in WHITELIST_DIRS and not any([r in WHITELIST_DIRS for r in _splitpath(root)]):
                # print "removing %s" % (os.path.join(root, name))
                os.rmdir(os.path.join(root, name))
    
    local("cp -rv %s/* ." % tempdir)
    with settings(warn_only=True):
        result = local("git diff --exit-code")

    if result.return_code != 0:
        local("git add -A .")
        local("git commit -m 'Auto-update of docs: %s'" % last_commit)
        local("git push")
    else:
        print "No changes to the docs."
    local("git checkout %s" % current_branch)<commit_msg>Adds version tagging to doc deploy.<commit_after>import os
import tempfile
from fabric.api import *

SITE_DIR = "site"
WHITELIST_DIRS = [".git",]
WHITELIST_FILES = [ ".gitignore", ]

SANITY_CHECK_PROJECT_FILES = ["fabfile.py", "setup.py", "mkdocs.yml"]
SANITY_CHECK_BUILD_FILES = ["index.html", "js", "css"]

def _splitpath(path):
    path = os.path.normpath(path)
    return path.split(os.sep)

def tag_release():
    # Tag the release:
    from setup import VERSION
    local("git tag %s" % VERSION)
    local("git push --tags")
    
def deploy_docs():
    # Sanity check dir.
    root_dir = os.getcwd()
    assert all([os.path.exists(os.path.join(root_dir,f)) for f in SANITY_CHECK_PROJECT_FILES])

    local("rm -rf %s" % SITE_DIR)
    local("mkdocs build")
    tempdir = tempfile.mkdtemp()

    local("mv %s/* %s" % (SITE_DIR, tempdir))
    
    current_branch = local("git rev-parse --abbrev-ref HEAD", capture=True)
    last_commit = local("git log -1 --pretty=\%B", capture=True)

    # Add the new site to build
    local("git checkout gh-pages")
    
    # Sanity check dir.
    root_dir = os.getcwd()
    assert all([os.path.exists(os.path.join(root_dir,f)) for f in SANITY_CHECK_BUILD_FILES])


    for root, dirs, files in os.walk(root_dir, topdown=False):
        for name in files:
            if not name in WHITELIST_FILES and not any([r in WHITELIST_DIRS for r in _splitpath(root)]):
                # print "removing %s" % (os.path.join(root, name))
                os.remove(os.path.join(root, name))
        for name in dirs:
            if not name in WHITELIST_DIRS and not any([r in WHITELIST_DIRS for r in _splitpath(root)]):
                # print "removing %s" % (os.path.join(root, name))
                os.rmdir(os.path.join(root, name))
    
    local("cp -rv %s/* ." % tempdir)
    with settings(warn_only=True):
        result = local("git diff --exit-code")

    if result.return_code != 0:
        local("git add -A .")
        local("git commit -m 'Auto-update of docs: %s'" % last_commit)
        local("git push")
    else:
        print "No changes to the docs."
    local("git checkout %s" % current_branch)

    tag_release()
{'fraction_non_alphanumeric': 0.13917649891644596, 'fraction_numerical': 0.000963159162051529, 'mean_word_length': 2.7763636363636364, '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': '6286037', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1443, 'n_words': 379}