Commit
•
333ccc5
1
Parent(s):
75feeb7
YOLOv5 PyTorch Hub models >> check_requirements() (#2592)
Browse files- utils/general.py +14 -3
utils/general.py
CHANGED
@@ -52,6 +52,11 @@ def isdocker():
|
|
52 |
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
|
53 |
|
54 |
|
|
|
|
|
|
|
|
|
|
|
55 |
def check_online():
|
56 |
# Check internet connectivity
|
57 |
import socket
|
@@ -79,7 +84,7 @@ def check_git_status():
|
|
79 |
f"Use 'git pull' to update or 'git clone {url}' to download latest."
|
80 |
else:
|
81 |
s = f'up to date with {url} ✅'
|
82 |
-
print(s
|
83 |
except Exception as e:
|
84 |
print(e)
|
85 |
|
@@ -93,14 +98,20 @@ def check_requirements(file='requirements.txt', exclude=()):
|
|
93 |
print(f"{prefix} {file.resolve()} not found, check failed.")
|
94 |
return
|
95 |
|
|
|
96 |
requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(file.open()) if x.name not in exclude]
|
97 |
for r in requirements:
|
98 |
try:
|
99 |
pkg.require(r)
|
100 |
except Exception as e: # DistributionNotFound or VersionConflict if requirements not met
|
101 |
-
|
|
|
102 |
print(subprocess.check_output(f"pip install '{e.req}'", shell=True).decode())
|
103 |
-
|
|
|
|
|
|
|
|
|
104 |
|
105 |
|
106 |
def check_img_size(img_size, s=32):
|
|
|
52 |
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
|
53 |
|
54 |
|
55 |
+
def emojis(str=''):
|
56 |
+
# Return platform-dependent emoji-safe version of string
|
57 |
+
return str.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else str
|
58 |
+
|
59 |
+
|
60 |
def check_online():
|
61 |
# Check internet connectivity
|
62 |
import socket
|
|
|
84 |
f"Use 'git pull' to update or 'git clone {url}' to download latest."
|
85 |
else:
|
86 |
s = f'up to date with {url} ✅'
|
87 |
+
print(emojis(s)) # emoji-safe
|
88 |
except Exception as e:
|
89 |
print(e)
|
90 |
|
|
|
98 |
print(f"{prefix} {file.resolve()} not found, check failed.")
|
99 |
return
|
100 |
|
101 |
+
n = 0 # number of packages updates
|
102 |
requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(file.open()) if x.name not in exclude]
|
103 |
for r in requirements:
|
104 |
try:
|
105 |
pkg.require(r)
|
106 |
except Exception as e: # DistributionNotFound or VersionConflict if requirements not met
|
107 |
+
n += 1
|
108 |
+
print(f"{prefix} {e.req} not found and is required by YOLOv5, attempting auto-update...")
|
109 |
print(subprocess.check_output(f"pip install '{e.req}'", shell=True).decode())
|
110 |
+
|
111 |
+
if n: # if packages updated
|
112 |
+
s = f"{prefix} {n} package{'s' * (n > 1)} updated per {file.resolve()}\n" \
|
113 |
+
f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n"
|
114 |
+
print(emojis(s)) # emoji-safe
|
115 |
|
116 |
|
117 |
def check_img_size(img_size, s=32):
|