<commit_before># No shebang line, this module is meant to be imported
#
# Copyright 2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
.. include:: ../include/references.rst
"""

import inspect

try:
    import pwd
except ImportError:
    pwd = None

try:
    import json
except ImportError:
    import simplejson as json

from textwrap import dedent
from sqlalchemy import event
from sqlalchemy.orm import validates
from sqlalchemy.schema import UniqueConstraint
from pyfarm.core.config import cfg
from pyfarm.models.core.app import db
from pyfarm.core.enums import WorkState
from pyfarm.models.core.functions import WorkColumns
from pyfarm.models.core.types import (
    IDColumn, IDType, JobType, JSONDict, JSONList)
from pyfarm.models.core.cfg import (
    TABLE_JOB, TABLE_JOB_TAGS, TABLE_JOB_SOFTWARE)
from pyfarm.models.mixins import WorkValidationMixin, StateChangedMixin


class JobTagsModel(db.Model):
    """
    Model which provides tagging for :class:`.JobModel` objects

    .. note::
        This table enforces two forms of uniqueness.  The :attr:`id` column
        must be unique and the combination of these columns must also be
        unique to limit the frequency of duplicate data:

            * :attr:`_jobid`
            * :attr:`tag`

    .. autoattribute:: _jobid
    """
    __tablename__ = TABLE_JOB_TAGS
    __table_args__ = (
        UniqueConstraint("_jobid", "tag"),
        {"extend_existing": True})

    id = IDColumn()
    _jobid = db.Column(IDType, db.ForeignKey("%s.id" % TABLE_JOB),
                       doc=dedent("""
                       Foreign key which stores :attr:`JobModel.id`"""))

    tag = db.Column(db.String, nullable=False)


class JobSoftwareModel(db.Model):
    """
    Model which allows specific software to be associated with a
    :class:`.JobModel` object.

    .. note::
        This table enforces two forms of uniqueness.  The :attr:`id` column
        must be unique and the combination of these columns must also be
        unique to limit the frequency of duplicate data:

            * :attr:`_jobid`
            * :attr:`software`
            * :attr:`version`

    .. autoattribute:: _jobid
    """
    __tablename__ = TABLE_JOB_SOFTWARE
    __table_args__ = (
        UniqueConstraint("_jobid", "software", "version"),
        {"extend_existing": True})

    id = IDColumn()
    _jobid = db.Column(IDType, db.ForeignKey("%s.id" % TABLE_JOB),
                       doc=dedent("""
                       The foreign key which stores :attr:`JobModel.id`"""))
    software = db.Column(db.String, nullable=False,
                         doc=dedent("""
                         The name of the software required to run a job"""))
    version = db.Column(db.String, default="any", nullable=False,
                        doc=dedent("""
                        The version of software required to run the job.  This
                        value does not follow any special formatting rules
                        because the format depends on the 3rd party."""))


class JobModel(db.Model, WorkValidationMixin, StateChangedMixin):
    """
    Defines the attributes and environment for a job.  Individual commands
    are kept track of by |TaskModel|<commit_msg>removing  (should fix the problem instead)<commit_after># No shebang line, this module is meant to be imported
#
# Copyright 2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
.. include:: ../include/references.rst
"""

import inspect

try:
    import pwd
except ImportError:
    pwd = None

try:
    import json
except ImportError:
    import simplejson as json

from textwrap import dedent
from sqlalchemy import event
from sqlalchemy.orm import validates
from sqlalchemy.schema import UniqueConstraint
from pyfarm.core.config import cfg
from pyfarm.models.core.app import db
from pyfarm.core.enums import WorkState
from pyfarm.models.core.functions import WorkColumns
from pyfarm.models.core.types import (
    IDColumn, IDType, JobType, JSONDict, JSONList)
from pyfarm.models.core.cfg import (
    TABLE_JOB, TABLE_JOB_TAGS, TABLE_JOB_SOFTWARE)
from pyfarm.models.mixins import WorkValidationMixin, StateChangedMixin


class JobTagsModel(db.Model):
    """
    Model which provides tagging for :class:`.JobModel` objects

    .. note::
        This table enforces two forms of uniqueness.  The :attr:`id` column
        must be unique and the combination of these columns must also be
        unique to limit the frequency of duplicate data:

            * :attr:`_jobid`
            * :attr:`tag`

    .. autoattribute:: _jobid
    """
    __tablename__ = TABLE_JOB_TAGS
    __table_args__ = (
        UniqueConstraint("_jobid", "tag"), )

    id = IDColumn()
    _jobid = db.Column(IDType, db.ForeignKey("%s.id" % TABLE_JOB),
                       doc=dedent("""
                       Foreign key which stores :attr:`JobModel.id`"""))

    tag = db.Column(db.String, nullable=False)


class JobSoftwareModel(db.Model):
    """
    Model which allows specific software to be associated with a
    :class:`.JobModel` object.

    .. note::
        This table enforces two forms of uniqueness.  The :attr:`id` column
        must be unique and the combination of these columns must also be
        unique to limit the frequency of duplicate data:

            * :attr:`_jobid`
            * :attr:`software`
            * :attr:`version`

    .. autoattribute:: _jobid
    """
    __tablename__ = TABLE_JOB_SOFTWARE
    __table_args__ = (
        UniqueConstraint("_jobid", "software", "version"), )

    id = IDColumn()
    _jobid = db.Column(IDType, db.ForeignKey("%s.id" % TABLE_JOB),
                       doc=dedent("""
                       The foreign key which stores :attr:`JobModel.id`"""))
    software = db.Column(db.String, nullable=False,
                         doc=dedent("""
                         The name of the software required to run a job"""))
    version = db.Column(db.String, default="any", nullable=False,
                        doc=dedent("""
                        The version of software required to run the job.  This
                        value does not follow any special formatting rules
                        because the format depends on the 3rd party."""))


class JobModel(db.Model, WorkValidationMixin, StateChangedMixin):
    """
    Defines the attributes and environment for a job.  Individual commands
    are kept track of by |TaskModel|
{'fraction_non_alphanumeric': 0.08962833758218167, 'fraction_numerical': 0.0024151348450288474, 'mean_word_length': 2.695587506197323, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1960742', 'n_tokens_mistral': 2102, 'n_tokens_neox': 2009, 'n_words': 730}