# Path: sacred/commandline_options.py
# def cli_option(short_flag: str, long_flag: str, is_flag=False):
#     def wrapper(f: CLIFunction):
#         return CLIOption(f, short_flag, long_flag, is_flag)
# 
#     return wrapper
# 
# Path: sacred/observers/base.py
# class RunObserver:
#     """Defines the interface for all run observers."""
# 
#     priority = 0
# 
#     def queued_event(
#         self, ex_info, command, host_info, queue_time, config, meta_info, _id
#     ):
#         pass
# 
#     def started_event(
#         self, ex_info, command, host_info, start_time, config, meta_info, _id
#     ):
#         pass
# 
#     def heartbeat_event(self, info, captured_out, beat_time, result):
#         pass
# 
#     def completed_event(self, stop_time, result):
#         pass
# 
#     def interrupted_event(self, interrupt_time, status):
#         pass
# 
#     def failed_event(self, fail_time, fail_trace):
#         pass
# 
#     def resource_event(self, filename):
#         pass
# 
#     def artifact_event(self, name, filename, metadata=None, content_type=None):
#         pass
# 
#     def log_metrics(self, metrics_by_name, info):
#         pass
# 
#     def join(self):
#         pass
# 
# Path: sacred/serializer.py
# def flatten(obj):
#     return _json.loads(json.encode(obj, keys=True))


import json
import warnings
        import sqlalchemy as sa
from threading import Lock
from sacred.commandline_options import cli_option
from sacred.observers.base import RunObserver
from sacred.serializer import flatten
        from sqlalchemy.orm import sessionmaker, scoped_session
        from .sql_bases import Base, Experiment, Host, Run
        from .sql_bases import Resource
        from .sql_bases import Artifact
        from .sql_bases import Run
            ex_info, command, host_info, config, meta_info, _id, "QUEUED"
        )

    def _add_event(
        self, ex_info, command, host_info, config, meta_info, _id, status, **kwargs
    ):

        Base.metadata.create_all(self.engine)
        sql_exp = Experiment.get_or_create(ex_info, self.session)
        sql_host = Host.get_or_create(host_info, self.session)
        if _id is None:
            i = self.session.query(Run).order_by(Run.id.desc()).first()
            _id = 0 if i is None else i.id + 1

        self.run = Run(
            run_id=str(_id),
            config=json.dumps(flatten(config)),
            command=command,
            priority=meta_info.get("priority", 0),
            comment=meta_info.get("comment", ""),
            experiment=sql_exp,
            host=sql_host,
            status=status,
            **kwargs,
        )
        self.session.add(self.run)
        self.save()
        return _id or self.run.run_id

    def heartbeat_event(self, info, captured_out, beat_time, result):

# Path: sacred/commandline_options.py
# def cli_option(short_flag: str, long_flag: str, is_flag=False):
#     def wrapper(f: CLIFunction):
#         return CLIOption(f, short_flag, long_flag, is_flag)
# 
#     return wrapper
# 
# Path: sacred/observers/base.py
# class RunObserver:
#     """Defines the interface for all run observers."""
# 
#     priority = 0
# 
#     def queued_event(
#         self, ex_info, command, host_info, queue_time, config, meta_info, _id
#     ):
#         pass
# 
#     def started_event(
#         self, ex_info, command, host_info, start_time, config, meta_info, _id
#     ):
#         pass
# 
#     def heartbeat_event(self, info, captured_out, beat_time, result):
#         pass
# 
#     def completed_event(self, stop_time, result):
#         pass
# 
#     def interrupted_event(self, interrupt_time, status):
#         pass
# 
#     def failed_event(self, fail_time, fail_trace):
#         pass
# 
#     def resource_event(self, filename):
#         pass
# 
#     def artifact_event(self, name, filename, metadata=None, content_type=None):
#         pass
# 
#     def log_metrics(self, metrics_by_name, info):
#         pass
# 
#     def join(self):
#         pass
# 
# Path: sacred/serializer.py
# def flatten(obj):
#     return _json.loads(json.encode(obj, keys=True))


# Path: sacred/observers/sql.py
import json
import warnings
        import sqlalchemy as sa
from threading import Lock
from sacred.commandline_options import cli_option
from sacred.observers.base import RunObserver
from sacred.serializer import flatten
        from sqlalchemy.orm import sessionmaker, scoped_session
        from .sql_bases import Base, Experiment, Host, Run
        from .sql_bases import Resource
        from .sql_bases import Artifact
        from .sql_bases import Run

            ex_info, command, host_info, config, meta_info, _id, "QUEUED"
        )

    def _add_event(
        self, ex_info, command, host_info, config, meta_info, _id, status, **kwargs
    ):

        Base.metadata.create_all(self.engine)
        sql_exp = Experiment.get_or_create(ex_info, self.session)
        sql_host = Host.get_or_create(host_info, self.session)
        if _id is None:
            i = self.session.query(Run).order_by(Run.id.desc()).first()
            _id = 0 if i is None else i.id + 1

        self.run = Run(
            run_id=str(_id),
            config=json.dumps(flatten(config)),
            command=command,
            priority=meta_info.get("priority", 0),
            comment=meta_info.get("comment", ""),
            experiment=sql_exp,
            host=sql_host,
            status=status,
            **kwargs,
        )
        self.session.add(self.run)
        self.save()
        return _id or self.run.run_id

    def heartbeat_event(self, info, captured_out, beat_time, result):

        self.run.info = json.dumps(flatten(info))