<commit_before>import docker
from docker.errors import APIError
from docker.utils import kwargs_from_env

class ProcessError(Exception):
    def __init__(self, container, exit_status, command, image, stderr):
        self.container = container
        self.exit_status = exit_status
        self.command = command
        self.image = image
        self.stderr = stderr
        super(ProcessError, self).__init__("Command '%s' in image '%s' returned non-zero exit status %s: %s" % (command, image, exit_status, stderr))

CREATE_KWARGS = ["hostname", "user", "detach", "stdin_open", "tty", "mem_limit", "ports", "environment", "dns", "volumes", "volumes_from", "network_disabled", "name", "entrypoint", "cpu_shares", "working_dir", "domainname", "memswap_limit", "cpuset", "host_config", "mac_address", "labels"]

START_KWARGS = ["binds", "port_bindings", "lxc_conf", "publish_all_ports", "links", "privileged", "dns", "dns_search", "volumes_from", "network_mode", "restart_policy", "cap_add", "cap_drop", "devices", "extra_hosts", "read_only", "pid_mode", "ipc_mode", "security_opt", "ulimits"]

def _dict_filter(d, keys):
    return dict((k, v) for k, v in d.items() if k in keys)

def from_env():
    return Client.from_env()

class Client(docker.Client):
    def run(self, image, command=None, detach=False, stdout=True, stderr=False, **kwargs):
        create_kwargs = _dict_filter(kwargs, CREATE_KWARGS)
        start_kwargs = _dict_filter(kwargs, START_KWARGS)
        create_kwargs['host_config'] = self.create_host_config(start_kwargs)
        try:
            container = self.create_container(image, command, **create_kwargs)
        except APIError as e:
            if e.response.status_code == 404 \
                    and e.explanation \
                    and 'No such image' in str(e.explanation):
                self.pull(image)
                container = self.create_container(image, command)
            else:
                raise


        self.start(container)

        if detach:
            return container

        exit_status = self.wait(container)
        if exit_status != 0:
            raise ProcessError(
                container,
                exit_status,
                command,
                image,
                self.logs(container, stdout=False, stderr=True)
            )
        return self.logs(container, stdout=stdout, stderr=stderr)<commit_msg>Allow arguments to be passed to from_env<commit_after>import docker
from docker.errors import APIError
from docker.utils import kwargs_from_env

class ProcessError(Exception):
    def __init__(self, container, exit_status, command, image, stderr):
        self.container = container
        self.exit_status = exit_status
        self.command = command
        self.image = image
        self.stderr = stderr
        super(ProcessError, self).__init__("Command '%s' in image '%s' returned non-zero exit status %s: %s" % (command, image, exit_status, stderr))

CREATE_KWARGS = ["hostname", "user", "detach", "stdin_open", "tty", "mem_limit", "ports", "environment", "dns", "volumes", "volumes_from", "network_disabled", "name", "entrypoint", "cpu_shares", "working_dir", "domainname", "memswap_limit", "cpuset", "host_config", "mac_address", "labels"]

START_KWARGS = ["binds", "port_bindings", "lxc_conf", "publish_all_ports", "links", "privileged", "dns", "dns_search", "volumes_from", "network_mode", "restart_policy", "cap_add", "cap_drop", "devices", "extra_hosts", "read_only", "pid_mode", "ipc_mode", "security_opt", "ulimits"]

def _dict_filter(d, keys):
    return dict((k, v) for k, v in d.items() if k in keys)

class Client(docker.Client):
    def run(self, image, command=None, detach=False, stdout=True, stderr=False, **kwargs):
        create_kwargs = _dict_filter(kwargs, CREATE_KWARGS)
        start_kwargs = _dict_filter(kwargs, START_KWARGS)
        create_kwargs['host_config'] = self.create_host_config(start_kwargs)
        try:
            container = self.create_container(image, command, **create_kwargs)
        except APIError as e:
            if e.response.status_code == 404 \
                    and e.explanation \
                    and 'No such image' in str(e.explanation):
                self.pull(image)
                container = self.create_container(image, command)
            else:
                raise


        self.start(container)

        if detach:
            return container

        exit_status = self.wait(container)
        if exit_status != 0:
            raise ProcessError(
                container,
                exit_status,
                command,
                image,
                self.logs(container, stdout=False, stderr=True)
            )
        return self.logs(container, stdout=stdout, stderr=stderr)


from_env = Client.from_env
{'fraction_non_alphanumeric': 0.12266112266112267, 'fraction_numerical': 0.0016632016632016633, 'mean_word_length': 2.914564686737185, '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': '4767948', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1422, 'n_words': 353}