<commit_before>from __future__ import absolute_import
from __future__ import print_function

import os
import shutil
import subprocess
from contextlib import contextmanager
from tempfile import mkdtemp

from .bootstrapping import from_project_root
from .source_package import prepare_source_package

import logbook
import yaml
import docker

_docker = None


def get_docker_client():
    global _docker
    if _docker is None:
        _docker = docker.Client(version='1.11')
    return _docker


def build_docker_image(root, tag):

    with _get_temp_path() as path:
        _generate_dockerfile(os.path.join(path, "Dockerfile"))

        shutil.copy(prepare_source_package(), path)

        subprocess.check_call(
            "docker build -t {0} .".format(tag), shell=True, cwd=path)

@contextmanager
def _get_temp_path():
    path = mkdtemp()
    try:
        yield path
    finally:
        shutil.rmtree(path)


def _generate_dockerfile(path):
    with open(path, "w") as outfile:
        for line in _generate_dockerfile_lines():
            print(line, file=outfile)<commit_msg>Pull postgres on docker build<commit_after>from __future__ import absolute_import
from __future__ import print_function

import os
import shutil
import subprocess
from contextlib import contextmanager
from tempfile import mkdtemp

from .bootstrapping import from_project_root
from .source_package import prepare_source_package

import logbook
import yaml
import docker

_docker = None


def get_docker_client():
    global _docker
    if _docker is None:
        _docker = docker.Client(version='1.11')
    return _docker


def build_docker_image(root, tag):

    with _get_temp_path() as path:
        _generate_dockerfile(os.path.join(path, "Dockerfile"))

        shutil.copy(prepare_source_package(), path)

        subprocess.check_call(
            "docker build -t {0} .".format(tag), shell=True, cwd=path)
    subprocess.check_call(
        "docker pull postgres")

@contextmanager
def _get_temp_path():
    path = mkdtemp()
    try:
        yield path
    finally:
        shutil.rmtree(path)


def _generate_dockerfile(path):
    with open(path, "w") as outfile:
        for line in _generate_dockerfile_lines():
            print(line, file=outfile)
{'fraction_non_alphanumeric': 0.07706013363028953, 'fraction_numerical': 0.0035634743875278397, 'mean_word_length': 3.6213991769547325, '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': '5157044', 'n_tokens_mistral': 718, 'n_tokens_neox': 673, 'n_words': 191}