glenn-jocher commited on
Commit
d2e754b
·
unverified ·
1 Parent(s): 5a40ce6

Add isdocker() (#2232)

Browse files

* Add isdocker()

* Update general.py

* Update general.py

Files changed (1) hide show
  1. utils/general.py +8 -2
utils/general.py CHANGED
@@ -47,6 +47,11 @@ def get_latest_run(search_dir='.'):
47
  return max(last_list, key=os.path.getctime) if last_list else ''
48
 
49
 
 
 
 
 
 
50
  def check_online():
51
  # Check internet connectivity
52
  import socket
@@ -62,7 +67,7 @@ def check_git_status():
62
  print(colorstr('github: '), end='')
63
  try:
64
  assert Path('.git').exists(), 'skipping check (not a git repository)'
65
- assert not Path('/workspace').exists(), 'skipping check (Docker image)' # not Path('/.dockerenv').exists()
66
  assert check_online(), 'skipping check (offline)'
67
 
68
  cmd = 'git fetch && git config --get remote.origin.url'
@@ -98,13 +103,14 @@ def check_img_size(img_size, s=32):
98
  def check_imshow():
99
  # Check if environment supports image displays
100
  try:
 
101
  cv2.imshow('test', np.zeros((1, 1, 3)))
102
  cv2.waitKey(1)
103
  cv2.destroyAllWindows()
104
  cv2.waitKey(1)
105
  return True
106
  except Exception as e:
107
- print(f'WARNING: Environment does not support cv2.imshow() or PIL Image.show() image previews\n{e}')
108
  return False
109
 
110
 
 
47
  return max(last_list, key=os.path.getctime) if last_list else ''
48
 
49
 
50
+ def isdocker():
51
+ # Is environment a Docker container
52
+ return Path('/workspace').exists() # or Path('/.dockerenv').exists()
53
+
54
+
55
  def check_online():
56
  # Check internet connectivity
57
  import socket
 
67
  print(colorstr('github: '), end='')
68
  try:
69
  assert Path('.git').exists(), 'skipping check (not a git repository)'
70
+ assert not isdocker(), 'skipping check (Docker image)'
71
  assert check_online(), 'skipping check (offline)'
72
 
73
  cmd = 'git fetch && git config --get remote.origin.url'
 
103
  def check_imshow():
104
  # Check if environment supports image displays
105
  try:
106
+ assert not isdocker(), 'cv2.imshow() is disabled in Docker environments'
107
  cv2.imshow('test', np.zeros((1, 1, 3)))
108
  cv2.waitKey(1)
109
  cv2.destroyAllWindows()
110
  cv2.waitKey(1)
111
  return True
112
  except Exception as e:
113
+ print(f'WARNING: Environment does not support cv2.imshow() or PIL Image.show() image displays\n{e}')
114
  return False
115
 
116