|
|
@ -197,7 +197,19 @@ def check_python(minimum: str = '3.7.0') -> bool:
|
|
|
|
|
|
|
|
|
|
|
|
@TryExcept()
|
|
|
|
@TryExcept()
|
|
|
|
def check_requirements(requirements=ROOT.parent / 'requirements.txt', exclude=(), install=True, cmds=''):
|
|
|
|
def check_requirements(requirements=ROOT.parent / 'requirements.txt', exclude=(), install=True, cmds=''):
|
|
|
|
# Check installed dependencies meet YOLOv5 requirements (pass *.txt file or list of packages or single package str)
|
|
|
|
"""
|
|
|
|
|
|
|
|
Check if installed dependencies meet YOLOv5 requirements and attempt to auto-update if needed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
requirements (Union[Path, str, List[str]]): Path to a requirements.txt file, a single package requirement as a
|
|
|
|
|
|
|
|
string, or a list of package requirements as strings.
|
|
|
|
|
|
|
|
exclude (Tuple[str]): Tuple of package names to exclude from checking.
|
|
|
|
|
|
|
|
install (bool): If True, attempt to auto-update packages that don't meet requirements.
|
|
|
|
|
|
|
|
cmds (str): Additional commands to pass to the pip install command when auto-updating.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
"""
|
|
|
|
prefix = colorstr('red', 'bold', 'requirements:')
|
|
|
|
prefix = colorstr('red', 'bold', 'requirements:')
|
|
|
|
check_python() # check python version
|
|
|
|
check_python() # check python version
|
|
|
|
file = None
|
|
|
|
file = None
|
|
|
@ -209,8 +221,8 @@ def check_requirements(requirements=ROOT.parent / 'requirements.txt', exclude=()
|
|
|
|
elif isinstance(requirements, str):
|
|
|
|
elif isinstance(requirements, str):
|
|
|
|
requirements = [requirements]
|
|
|
|
requirements = [requirements]
|
|
|
|
|
|
|
|
|
|
|
|
s = ''
|
|
|
|
s = '' # console string
|
|
|
|
n = 0
|
|
|
|
n = 0 # number of packages updates
|
|
|
|
for r in requirements:
|
|
|
|
for r in requirements:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
pkg.require(r)
|
|
|
|
pkg.require(r)
|
|
|
@ -226,7 +238,7 @@ def check_requirements(requirements=ROOT.parent / 'requirements.txt', exclude=()
|
|
|
|
LOGGER.info(f"{prefix} YOLOv8 requirement{'s' * (n > 1)} {s}not found, attempting AutoUpdate...")
|
|
|
|
LOGGER.info(f"{prefix} YOLOv8 requirement{'s' * (n > 1)} {s}not found, attempting AutoUpdate...")
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
assert is_online(), 'AutoUpdate skipped (offline)'
|
|
|
|
assert is_online(), 'AutoUpdate skipped (offline)'
|
|
|
|
LOGGER.info(subprocess.check_output(f'pip install {s} {cmds}', shell=True).decode())
|
|
|
|
LOGGER.info(subprocess.check_output(f'pip install --no-cache {s} {cmds}', shell=True).decode())
|
|
|
|
s = f"{prefix} {n} package{'s' * (n > 1)} updated per {file or requirements}\n" \
|
|
|
|
s = f"{prefix} {n} package{'s' * (n > 1)} updated per {file or requirements}\n" \
|
|
|
|
f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n"
|
|
|
|
f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n"
|
|
|
|
LOGGER.info(s)
|
|
|
|
LOGGER.info(s)
|
|
|
|