<commit_before>import os
import re
import sys
import json
import logging

import docker.errors


APIError = docker.errors.APIError

log = logging.getLogger(__name__)

DEFAULT_URL = 'http+unix:///var/tmp/docker.sock'


def echo_download_progress(output):
    last_id = None
    for line in output:
        log.debug(line)
        progress = json.loads(line.decode('utf-8'))

        progress_id = progress.get('id')
        if last_id:
            if progress_id == last_id:
                sys.stdout.write('\x1b[2K\r')
            elif not progress_id or progress_id != last_id:
                sys.stdout.write('\n')
        last_id = progress_id

        if progress_id:
            sys.stdout.write('{}: '.format(progress_id))
        sys.stdout.write(progress.get('status') or progress.get('error') or '')

        progress_bar = progress.get('progress')
        if progress_bar:
            sys.stdout.write(' ' + progress_bar)

        if not progress_id:
            sys.stdout.write('\n')
        sys.stdout.flush()
    if last_id:
        sys.stdout.write('\n')
        sys.stdout.flush()


def echo_build_progress(client, output):
    latest_container = None
    try:
        for line in output:
            log.debug(line)
            status = json.loads(line.decode('utf-8'))
            if 'stream' in status:
                sys.stdout.write(status['stream'])
                match = re.search(u'Running in ([0-9a-f]+)', status['stream'])
                if match:
                    latest_container = match.group(1)
            elif 'error' in status:
                sys.stdout.write(status['error'])
    except BaseException as original_exc:
        try:
            if latest_container is not None:
                sys.stdout.write('Stopping current container {}...'
                                 .format(latest_container))
                client.stop(latest_container, 5)
                client.remove_container(latest_container)
        except:
            log.exception('Failed to delete current container')
        finally:
            raise original_exc


def get_client():
    url = os.environ.get('DOCKER_HOST', DEFAULT_URL)
    return docker.Client(url)<commit_msg>Using proper default DOCKER_HOST location on the Linux systems<commit_after>import os
import re
import sys
import json
import logging

import docker.errors


APIError = docker.errors.APIError

log = logging.getLogger(__name__)


DEFAULT_DOCKER_HOST = None  # default defined in docker-py
if sys.platform == 'darwin':
    # default location used by "Docker for Mac"
    DEFAULT_DOCKER_HOST = 'http+unix:///var/tmp/docker.sock'


def echo_download_progress(output):
    last_id = None
    for line in output:
        log.debug(line)
        progress = json.loads(line.decode('utf-8'))

        progress_id = progress.get('id')
        if last_id:
            if progress_id == last_id:
                sys.stdout.write('\x1b[2K\r')
            elif not progress_id or progress_id != last_id:
                sys.stdout.write('\n')
        last_id = progress_id

        if progress_id:
            sys.stdout.write('{}: '.format(progress_id))
        sys.stdout.write(progress.get('status') or progress.get('error') or '')

        progress_bar = progress.get('progress')
        if progress_bar:
            sys.stdout.write(' ' + progress_bar)

        if not progress_id:
            sys.stdout.write('\n')
        sys.stdout.flush()
    if last_id:
        sys.stdout.write('\n')
        sys.stdout.flush()


def echo_build_progress(client, output):
    latest_container = None
    try:
        for line in output:
            log.debug(line)
            status = json.loads(line.decode('utf-8'))
            if 'stream' in status:
                sys.stdout.write(status['stream'])
                match = re.search(u'Running in ([0-9a-f]+)', status['stream'])
                if match:
                    latest_container = match.group(1)
            elif 'error' in status:
                sys.stdout.write(status['error'])
    except BaseException as original_exc:
        try:
            if latest_container is not None:
                sys.stdout.write('Stopping current container {}...'
                                 .format(latest_container))
                client.stop(latest_container, 5)
                client.remove_container(latest_container)
        except:
            log.exception('Failed to delete current container')
        finally:
            raise original_exc


def get_client():
    url = os.environ.get('DOCKER_HOST', DEFAULT_DOCKER_HOST)
    return docker.Client(url)
{'fraction_non_alphanumeric': 0.11, 'fraction_numerical': 0.0034782608695652175, 'mean_word_length': 2.0170491803278687, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5139630', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1291, 'n_words': 291}