'Start of environment context'

def __enter__(self):

    log.info('Creating    container')
    try:
        state = self.container_state()
        if (state is not None):
            if (state.get('Running') is True):
                exc = BuildEnvironmentError(_('A    build    environment    is    currently    running    for    this    version'))
                self.failure = exc
                self.build['state'] = BUILD_STATE_FINISHED
                raise exc
            else:
                log.warn(LOG_TEMPLATE.format(project=self.project.slug, version=self.version.slug, msg='Removing    stale    container    {0}'.format(self.container_id)))
                client = self.get_client()
                client.remove_container(self.container_id)
    except DockerAPIError:
        pass
    if (not os.path.exists(self.project.doc_path)):
        os.makedirs(self.project.doc_path)
    try:
        self.create_container()
    except:
        self.__exit__(*sys.exc_info())
        raise
    return self
