"""
Job metadata stored along side the code
"""

from yaml_model import LoadOnAccess, Model, OnAccess


def get_job(slug):
    """
    Wrapper to import, and return a Job object for the JobConfig to avoid
    cyclic import
    """
    from dockci.models.job import Job
    return Job.query.filter_by(slug=slug).first()


class JobConfig(Model):  # pylint:disable=too-few-public-methods
    """
    Job config, loaded from the repo
    """

    slug = 'dockci.yaml'

    job = OnAccess(lambda self: get_job(self.job_slug))
    job_slug = OnAccess(lambda self: self.job.slug)  # TODO infinite loop

    job_output = LoadOnAccess(default=lambda _: {})
    services = LoadOnAccess(default=lambda _: {})
    utilities = LoadOnAccess(default=lambda _: [])
    dockerfile = LoadOnAccess(default='Dockerfile')

    repo_name = LoadOnAccess(default=lambda self: self.job.project.slug)

    skip_tests = LoadOnAccess(default=False)

    def __init__(self, job):
        super(JobConfig, self).__init__()

        assert job is not None, "Job is given"

        self.job = job
        self.job_slug = job.slug

    def data_file_path(self):
        # Our data file path is <job output>/<slug>
        return self.job.job_output_path().join(JobConfig.slug)

"""
Job metadata stored along side the code
"""

from yaml_model import LoadOnAccess, Model, OnAccess


def get_job(slug):
    """
    Wrapper to import, and return a Job object for the JobConfig to avoid
    cyclic import
    """
    from dockci.models.job import Job
    return Job.load(slug)


class JobConfig(Model):  # pylint:disable=too-few-public-methods
    """
    Job config, loaded from the repo
    """

    slug = 'dockci.yaml'

    job = OnAccess(lambda self: get_job(self.job_slug))
    job_slug = OnAccess(lambda self: self.job.slug)  # TODO infinite loop

    job_output = LoadOnAccess(default=lambda _: {})
    services = LoadOnAccess(default=lambda _: {})
    utilities = LoadOnAccess(default=lambda _: [])
    dockerfile = LoadOnAccess(default='Dockerfile')

    repo_name = LoadOnAccess(default=lambda self: self.job.project.slug)

    skip_tests = LoadOnAccess(default=False)

    def __init__(self, job):
        super(JobConfig, self).__init__()

        assert job is not None, "Job is given"

        self.job = job
        self.job_slug = job.slug

    def data_file_path(self):
        # Our data file path is <job output>/<slug>
        return self.job.job_output_path().join(JobConfig.slug)

Fix OnAccess job link for JobConfig
Fix OnAccess job link for JobConfig
