<commit_before>
import construi.console as console

from compose.project import Project
from compose.cli.docker_client import docker_client

import dockerpty
import sys


class Target(object):
    def __init__(self, config):
        self.config = config
        self.project = Project.from_dicts(
            'construi', config.services, docker_client())

    def run(self):
        try:
            self.setup()

            service = self.project.get_service(self.config.construi['name'])

            for cmd in self.config.construi['run']:
                console.progress("> %s" % cmd)

                container = service.create_container(
                    one_off=True,
                    command=cmd,
                    tty=False,
                    stdin_open=True,
                    detach=False
                )

                dockerpty.start(
                    self.project.client, container.id, interactive=False)
                exit_code = container.wait()
                self.project.client.remove_container(container.id, force=True)

                if exit_code != 0:
                    console.error("\nBuild Failed.")
                    sys.exit(1)

            console.progress('Done.')
        except KeyboardInterrupt:
            console.warn("\nBuild Interrupted.")
            sys.exit(1)

        finally:
            self.cleanup()

    def setup(self):
        console.progress('Building Images...')
        self.project.build()

        console.progress('Pulling Images...')
        self.project.pull()

    def cleanup(self):
        console.progress('Cleaning up...')
        self.project.kill()
        self.project.remove_stopped(None, v=True)<commit_msg>Refactor target.py<commit_after>
import construi.console as console

from compose.project import Project
from compose.cli.docker_client import docker_client

import dockerpty
import sys


class Target(object):
    def __init__(self, config):
        self.config = config
        self.project = Project.from_dicts(
            'construi', config.services, docker_client())

    @property
    def client(self):
        return self.project.client

    @property
    def commands(self):
        return self.config.construi['run']

    @property
    def name(self):
        return self.config.construi['name']

    @property
    def service(self):
        return self.project.get_service(self.name)

    def run(self):
        try:
            self.setup()

            for command in self.commands:
                self.run_command(command)

            console.progress('Done.')

        except KeyboardInterrupt:
            console.warn("\nBuild Interrupted.")
            sys.exit(1)

        finally:
            self.cleanup()

    def run_command(self, command):
        console.progress("> %s" % command)

        container = self.service.create_container(
            one_off=True,
            command=command,
            tty=False,
            stdin_open=True,
            detach=False
        )

        try:
            dockerpty.start(self.client, container.id, interactive=False)

            if container.wait() != 0:
                console.error("\nBuild Failed.")
                sys.exit(1)

        finally:
            self.client.remove_container(container.id, force=True)

    def setup(self):
        console.progress('Building Images...')
        self.project.build()

        console.progress('Pulling Images...')
        self.project.pull()

    def cleanup(self):
        console.progress('Cleaning up...')
        self.project.kill()
        self.project.remove_stopped(None, v=True)
{'fraction_non_alphanumeric': 0.10542335362479248, 'fraction_numerical': 0.0016602102933038186, 'mean_word_length': 1.802325581395349, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3991983', 'n_tokens_mistral': 1009, 'n_tokens_neox': 942, 'n_words': 193}