From f9ef6cc5a43c7e402db7fc16283b31d922dadd8c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 16 Feb 2021 15:46:49 -0800 Subject: [PATCH 1/3] Add isdocker() --- utils/general.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index 2d3e83ede35e..e7486370153a 100755 --- a/utils/general.py +++ b/utils/general.py @@ -47,6 +47,11 @@ def get_latest_run(search_dir='.'): return max(last_list, key=os.path.getctime) if last_list else '' +def isdocker(): + # Is environment a Docker container + return Path('/workspace').exists() + + def check_online(): # Check internet connectivity import socket @@ -62,7 +67,7 @@ def check_git_status(): print(colorstr('github: '), end='') try: assert Path('.git').exists(), 'skipping check (not a git repository)' - assert not Path('/workspace').exists(), 'skipping check (Docker image)' # not Path('/.dockerenv').exists() + assert not isdocker(), 'skipping check (Docker image)' # not Path('/.dockerenv').exists() assert check_online(), 'skipping check (offline)' cmd = 'git fetch && git config --get remote.origin.url' @@ -98,13 +103,14 @@ def check_img_size(img_size, s=32): def check_imshow(): # Check if environment supports image displays try: + assert not isdocker() cv2.imshow('test', np.zeros((1, 1, 3))) cv2.waitKey(1) cv2.destroyAllWindows() cv2.waitKey(1) return True except Exception as e: - print(f'WARNING: Environment does not support cv2.imshow() or PIL Image.show() image previews\n{e}') + print(f'WARNING: Environment does not support cv2.imshow() or PIL Image.show() image displays\n{e}') return False From a3a4c4256996ad49fed3364939efee96a64cd067 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 16 Feb 2021 15:48:59 -0800 Subject: [PATCH 2/3] Update general.py --- utils/general.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index e7486370153a..0df11923d19e 100755 --- a/utils/general.py +++ b/utils/general.py @@ -49,7 +49,7 @@ def get_latest_run(search_dir='.'): def isdocker(): # Is environment a Docker container - return Path('/workspace').exists() + return Path('/workspace').exists() # or Path('/.dockerenv').exists() def check_online(): @@ -67,7 +67,7 @@ def check_git_status(): print(colorstr('github: '), end='') try: assert Path('.git').exists(), 'skipping check (not a git repository)' - assert not isdocker(), 'skipping check (Docker image)' # not Path('/.dockerenv').exists() + assert not isdocker(), 'skipping check (Docker image)' assert check_online(), 'skipping check (offline)' cmd = 'git fetch && git config --get remote.origin.url' From 650cbb3b5c03a86e4359821363cdb418ed5e5ede Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 16 Feb 2021 15:54:09 -0800 Subject: [PATCH 3/3] Update general.py --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 0df11923d19e..64b360fbe7df 100755 --- a/utils/general.py +++ b/utils/general.py @@ -103,7 +103,7 @@ def check_img_size(img_size, s=32): def check_imshow(): # Check if environment supports image displays try: - assert not isdocker() + assert not isdocker(), 'cv2.imshow() is disabled in Docker environments' cv2.imshow('test', np.zeros((1, 1, 3))) cv2.waitKey(1) cv2.destroyAllWindows()