File size: 1,618 Bytes
484b847
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import logging
import os

from git import Repo

"""
Collection of utility functions for running experiments.
"""


def is_wandb_online():
    """
    Check if wandb is online based on wandb setting file.
    """
    # Get W&B directory - default to current directory
    wandb_dir = os.environ.get("WANDB_DIR", ".")
    settings_file = os.path.join("wandb", "settings")
    disabled = False
    mode = "online"

    with open(os.path.join(wandb_dir, settings_file), "r") as file:
        for line in file:
            line = line.strip()
            if line.startswith("disabled"):
                disabled = "true" in line.split("=")[1].strip().lower()
            if line.startswith("mode"):
                mode = line.split("=")[1].strip().lower()
    return mode == "online" and not disabled


def validate_git_status():
    """
    Check if the git repository is clean to run experiments.
    """
    # Check the env variable if we are in a dev environment in which case,
    # we ignore any git dirty status
    is_dev_env = os.environ.get("META_DEV", "false").lower() == "true"
    if is_dev_env:
        return

    wandb_online = is_wandb_online()
    repo = Repo(".", search_parent_directories=True)
    repo_is_dirty = repo.is_dirty()
    if wandb_online:
        assert (
            not repo_is_dirty
        ), "Git repository is dirty! Please commit your changes before running wandb online experiments."
    elif repo_is_dirty:
        logging.warning(
            "Git repository is dirty! You may test out runs locally but commit your changes before running any wandb online experiments."
        )