<commit_before>import docker
import copy
import sys
import os
import subprocess
import tempfile
import bugzoo
import time

from tempfile import NamedTemporaryFile
from typing import List, Iterator, Dict, Optional
from timeit import default_timer as timer

from bugzoo.core import Language
from bugzoo.cmd import ExecResponse, PendingExecResponse
from bugzoo.testing import TestOutcome, TestCase
from bugzoo.core import Patch
from bugzoo.tool import Tool
from bugzoo.coverage.base import ProjectLineCoverage, \
                                 ProjectCoverageMap
from bugzoo.coverage.spectra import Spectra
from bugzoo.compiler import Compiler, CompilationOutcome


class Container(object):
    """
    Containers provide ephemeral, mutable instances of registered bugs,
    and are used to conduct studies of software bugs. Behind the scenes,
    containers are implemented as `Docker containers <https://docker.com>`_.
    """
    def __init__(self,
                 bug: str = 'bugzoo.bug.Bug',
                 tools: Optional[List[Tool]] = None,
                 volumes: Optional[Dict[str, str]] = None,
                 network_mode: str = 'bridge',
                 ports: Optional[Dict[int, int]] = None,
                 uid: str = None,
                 interactive=False) -> None:
        """
        Constructs a container for a given bug.
        """
        if tools is None:
            tools = []
        if volumes is None:
            volumes = {}
        if ports is None:
            ports = {}

        self.__bug = bug
        self.__tools = tools
        self.__tool_containers = [t.provision() for t in tools]
        tool_container_ids = [c.id for c in self.__tool_containers]

        # prepare the environment for the container
        env = [(k, v) for t in tools for (k, v) in t.environment.items()]
        env = ["{}=\"{}\"".format(k, v) for (k, v) in env]
        env = "\n".join(env)
        self.__env_file = tempfile.NamedTemporaryFile(mode='w', suffix='.bugzoo.env')
        self.__env_file.write(env)
        self.__env_file.flush()

        # we don't want to accidentally disturb the dictionary that was passed
        volumes = copy.deepcopy(volumes)

        # mount the environment file
        volumes[self.__env_file.name] = \
            {'bind': '/.environment', 'mode': 'rw'}

        # construct a Docker container for this bug
        cmd = '/bin/bash -v -c "sudo chown $(whoami) ./environment && source /.environment && /bin/bash"'
        client = docker.from_env() # nooooooooo
        self.__container = \
            client.containers.create(bug.image,
                                     cmd,<commit_msg>bug fix: typo in container provisioning command<commit_after>import docker
import copy
import sys
import os
import subprocess
import tempfile
import bugzoo
import time

from tempfile import NamedTemporaryFile
from typing import List, Iterator, Dict, Optional
from timeit import default_timer as timer

from bugzoo.core import Language
from bugzoo.cmd import ExecResponse, PendingExecResponse
from bugzoo.testing import TestOutcome, TestCase
from bugzoo.core import Patch
from bugzoo.tool import Tool
from bugzoo.coverage.base import ProjectLineCoverage, \
                                 ProjectCoverageMap
from bugzoo.coverage.spectra import Spectra
from bugzoo.compiler import Compiler, CompilationOutcome


class Container(object):
    """
    Containers provide ephemeral, mutable instances of registered bugs,
    and are used to conduct studies of software bugs. Behind the scenes,
    containers are implemented as `Docker containers <https://docker.com>`_.
    """
    def __init__(self,
                 bug: str = 'bugzoo.bug.Bug',
                 tools: Optional[List[Tool]] = None,
                 volumes: Optional[Dict[str, str]] = None,
                 network_mode: str = 'bridge',
                 ports: Optional[Dict[int, int]] = None,
                 uid: str = None,
                 interactive=False) -> None:
        """
        Constructs a container for a given bug.
        """
        if tools is None:
            tools = []
        if volumes is None:
            volumes = {}
        if ports is None:
            ports = {}

        self.__bug = bug
        self.__tools = tools
        self.__tool_containers = [t.provision() for t in tools]
        tool_container_ids = [c.id for c in self.__tool_containers]

        # prepare the environment for the container
        env = [(k, v) for t in tools for (k, v) in t.environment.items()]
        env = ["{}=\"{}\"".format(k, v) for (k, v) in env]
        env = "\n".join(env)
        self.__env_file = tempfile.NamedTemporaryFile(mode='w', suffix='.bugzoo.env')
        self.__env_file.write(env)
        self.__env_file.flush()

        # we don't want to accidentally disturb the dictionary that was passed
        volumes = copy.deepcopy(volumes)

        # mount the environment file
        volumes[self.__env_file.name] = \
            {'bind': '/.environment', 'mode': 'rw'}

        # construct a Docker container for this bug
        cmd = '/bin/bash -v -c "sudo chown $(whoami) /.environment && source /.environment && /bin/bash"'
        client = docker.from_env() # nooooooooo
        self.__container = \
            client.containers.create(bug.image,
                                     cmd,
{'fraction_non_alphanumeric': 0.0943220022413149, 'fraction_numerical': 0.0, 'mean_word_length': 2.2395644283121596, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '765188', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1450, 'n_words': 483}