How to use the sacred.dependencies.get_digest function in sacred

To help you get started, we’ve selected a few sacred examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IDSIA / sacred / tests / test_observers / test_mongo_observer.py View on Github external
def test_mongo_observer_resource_event(mongo_obs, sample_run):
    mongo_obs.started_event(**sample_run)

    filename = "setup.py"
    md5 = get_digest(filename)

    mongo_obs.resource_event(filename)

    db_run = mongo_obs.runs.find_one()
    assert db_run["resources"] == [[filename, md5]]
github IDSIA / sacred / tests / test_observers / test_tinydb_reader.py View on Github external
host = {"hostname": "test_host", "cpu_count": 1, "python_version": "3.4"}
    config = {"config": "True", "foo": "bar", "answer": 42}
    command = "run"
    meta_info = {"comment": "test run"}
    sample_run = {
        "_id": "FED235DA13",
        "ex_info": exp,
        "command": command,
        "host_info": host,
        "start_time": T1,
        "config": config,
        "meta_info": meta_info,
    }

    filename = "setup.py"
    md5 = get_digest(filename)
    sample_run["ex_info"]["sources"] = [[filename, md5]]

    return sample_run
github IDSIA / sacred / tests / test_observers / test_tinydb_observer.py View on Github external
def test_tinydb_observer_started_event_saves_given_sources(tinydb_obs, sample_run):
    filename = "setup.py"
    md5 = get_digest(filename)

    sample_run["ex_info"]["sources"] = [[filename, md5]]
    _id = tinydb_obs.started_event(**sample_run)

    assert _id is not None
    assert len(tinydb_obs.runs) == 1
    db_run = tinydb_obs.runs.get(eid=1)

    # Check all but the experiment section
    db_run_copy = db_run.copy()
    del db_run_copy["experiment"]
    assert db_run_copy == {
        "_id": _id,
        "format": tinydb_obs.VERSION,
        "command": sample_run["command"],
        "host": sample_run["host_info"],
github IDSIA / sacred / sacred / observers / s3_observer.py View on Github external
def find_or_save(self, filename, store_dir):
        source_name, ext = os.path.splitext(os.path.basename(filename))
        md5sum = get_digest(filename)
        store_name = source_name + "_" + md5sum + ext
        store_path = s3_join(store_dir, store_name)
        if len(self._list_s3_subdirs(prefix=store_path)) == 0:
            self.save_file(filename, store_path)
        return store_path, md5sum
github IDSIA / sacred / sacred / observers / file_storage.py View on Github external
def find_or_save(self, filename, store_dir: Path):
        os.makedirs(str(store_dir), exist_ok=True)
        source_name, ext = os.path.splitext(os.path.basename(filename))
        md5sum = get_digest(filename)
        store_name = source_name + "_" + md5sum + ext
        store_path = store_dir / store_name
        if not store_path.exists():
            copyfile(filename, str(store_path))
        return store_path, md5sum
github IDSIA / sacred / sacred / observers / sql_bases.py View on Github external
def get_or_create(cls, filename, session):
        md5sum = get_digest(filename)
        instance = (
            session.query(cls).filter_by(filename=filename, md5sum=md5sum).first()
        )
        if instance:
            return instance
        with open(filename, "rb") as f:
            return cls(filename=filename, md5sum=md5sum, content=f.read())