From 0d51475f48c79797ea012047803bacc5fd083089 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 18 Jan 2021 10:49:28 -0800 Subject: [PATCH] check_git_status() asserts (#1977) --- Dockerfile | 4 ++-- utils/general.py | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 24529d2b9415..4c11b036d6b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,8 +7,8 @@ RUN apt update && apt install -y screen libgl1-mesa-glx # Install python dependencies RUN pip install --upgrade pip COPY requirements.txt . -RUN pip install -r requirements.txt -RUN pip install gsutil +RUN pip install -r requirements.txt gsutil wandb +RUN wandb disabled # Create working directory RUN mkdir -p /usr/src/app diff --git a/utils/general.py b/utils/general.py index 23dbc93ec1c4..4822709d1753 100755 --- a/utils/general.py +++ b/utils/general.py @@ -60,16 +60,19 @@ def check_git_status(): # Recommend 'git pull' if code is out of date print(colorstr('github: '), end='') try: - if Path('.git').exists() and not Path('/workspace').exists() and check_online(): # not exist '/.dockerenv' - url = subprocess.check_output( - 'git fetch && git config --get remote.origin.url', shell=True).decode('utf-8')[:-1] - n = int(subprocess.check_output( - 'git rev-list $(git rev-parse --abbrev-ref HEAD)..origin/master --count', shell=True)) # commits behind - if n > 0: - print(f"⚠️ WARNING: code is out of date by {n} {'commits' if n > 1 else 'commmit'}. " - f"Use 'git pull' to update or 'git clone {url}' to download latest.") - else: - print(f'up to date with {url} ✅') + assert Path('.git').exists(), 'skipping check (not a git repository)' + assert not Path('/workspace').exists(), 'skipping check (Docker image)' # not Path('/.dockerenv').exists() + assert check_online(), 'skipping check (offline)' + + cmd = 'git fetch && git config --get remote.origin.url' # github repo url + url = subprocess.check_output(cmd, shell=True).decode()[:-1] + cmd = 'git rev-list $(git rev-parse --abbrev-ref HEAD)..origin/master --count' # commits behind + n = int(subprocess.check_output(cmd, shell=True)) + if n > 0: + print(f"⚠️ WARNING: code is out of date by {n} {'commits' if n > 1 else 'commmit'}. " + f"Use 'git pull' to update or 'git clone {url}' to download latest.") + else: + print(f'up to date with {url} ✅') except Exception as e: print(e)