<commit_before>import requests
import docker
import retrying


CONTAINER_NAME = 'mountebank-test'

MB_HOST = 'localhost'
MB_PORT = 2525

docker_client = docker.Client()


@retrying.retry(stop_max_attempt_number=5, wait_fixed=500)
def wait_for_service_ready(url):
    response = requests.get(url)
    response.raise_for_status()
    return True


def start_mb(port=MB_PORT, stubbed_ports=None):
    print('starting {} on port {}'.format(CONTAINER_NAME, port))
    stubbed_ports = stubbed_ports or []

    port_bindings = {port: port}

    for stubbed_port in stubbed_ports:
        port_bindings[stubbed_port] = stubbed_port

    host_config = docker_client.create_host_config(
        port_bindings=port_bindings)

    response = docker_client.create_container(
        'kevinjqiu/mountebank', ports=[port, 27351, 27352],
        name=CONTAINER_NAME, host_config=host_config)

    if response and response['Id']:
        docker_client.start(container=response['Id'])
        mb_url = 'http://{}:{}'.format(MB_HOST, port)
        wait_for_service_ready(mb_url)
        print('{} started on port {}'.format(CONTAINER_NAME, port))
        return mb_url
<commit_msg>Pull image before creating a container<commit_after>import requests
import docker
import retrying


MOUNTEBANK_IMAGE_NAME = 'kevinjqiu/mountebank'
CONTAINER_NAME = 'mountebank-test'

MB_HOST = 'localhost'
MB_PORT = 2525

docker_client = docker.Client()


@retrying.retry(stop_max_attempt_number=5, wait_fixed=500)
def wait_for_service_ready(url):
    response = requests.get(url)
    response.raise_for_status()
    return True


def start_mb(port=MB_PORT, stubbed_ports=None):
    print('starting {} on port {}'.format(CONTAINER_NAME, port))
    stubbed_ports = stubbed_ports or []

    port_bindings = {port: port}

    for stubbed_port in stubbed_ports:
        port_bindings[stubbed_port] = stubbed_port

    host_config = docker_client.create_host_config(
        port_bindings=port_bindings)

    docker_client.pull(MOUNTEBANK_IMAGE_NAME)
    response = docker_client.create_container(
        MOUNTEBANK_IMAGE_NAME, ports=[port, 27351, 27352],
        name=CONTAINER_NAME, host_config=host_config)

    if response and response['Id']:
        docker_client.start(container=response['Id'])
        mb_url = 'http://{}:{}'.format(MB_HOST, port)
        wait_for_service_ready(mb_url)
        print('{} started on port {}'.format(CONTAINER_NAME, port))
        return mb_url

{'fraction_non_alphanumeric': 0.10405571487095452, 'fraction_numerical': 0.014748054076198279, 'mean_word_length': 4.297180043383948, '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': '1335436', 'n_tokens_mistral': 877, 'n_tokens_neox': 812, 'n_words': 150}