|
|
@ -90,55 +90,61 @@ def check_imgsz(imgsz, stride=32, min_dim=1, max_dim=2, floor=0):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_version(current: str = '0.0.0',
|
|
|
|
def check_version(current: str = '0.0.0',
|
|
|
|
minimum: str = '0.0.0',
|
|
|
|
required: str = '0.0.0',
|
|
|
|
maximum: str = None,
|
|
|
|
|
|
|
|
name: str = 'version ',
|
|
|
|
name: str = 'version ',
|
|
|
|
pinned: bool = False,
|
|
|
|
|
|
|
|
hard: bool = False,
|
|
|
|
hard: bool = False,
|
|
|
|
verbose: bool = False) -> bool:
|
|
|
|
verbose: bool = False) -> bool:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Check current version against the required minimum and/or maximum version.
|
|
|
|
Check current version against the required version or range.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
current (str): Current version.
|
|
|
|
current (str): Current version.
|
|
|
|
minimum (str): Required minimum version.
|
|
|
|
required (str): Required version or range (in pip-style format).
|
|
|
|
maximum (str, optional): Required maximum version.
|
|
|
|
|
|
|
|
name (str): Name to be used in warning message.
|
|
|
|
name (str): Name to be used in warning message.
|
|
|
|
pinned (bool): If True, versions must match exactly. If False, minimum version must be satisfied.
|
|
|
|
hard (bool): If True, raise an AssertionError if the requirement is not met.
|
|
|
|
hard (bool): If True, raise an AssertionError if the minimum or maximum version is not met.
|
|
|
|
verbose (bool): If True, print warning message if requirement is not met.
|
|
|
|
verbose (bool): If True, print warning message if minimum or maximum version is not met.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
(bool): True if minimum and maximum versions are met, False otherwise.
|
|
|
|
(bool): True if requirement is met, False otherwise.
|
|
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
Example:
|
|
|
|
```python
|
|
|
|
# check if current version is exactly 22.04
|
|
|
|
# Check if current version is exactly 22.04
|
|
|
|
check_version(current='22.04', required='==22.04')
|
|
|
|
check_version(current='22.04', minimum='22.04', pinned=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check if current version is greater than or equal to 22.04
|
|
|
|
# check if current version is greater than or equal to 22.04
|
|
|
|
check_version(current='22.10', minimum='22.04')
|
|
|
|
check_version(current='22.10', required='22.04') # assumes '>=' inequality if none passed
|
|
|
|
|
|
|
|
|
|
|
|
# Check if current version is less than or equal to 22.04
|
|
|
|
# check if current version is less than or equal to 22.04
|
|
|
|
check_version(current='22.04', maximum='22.04')
|
|
|
|
check_version(current='22.04', required='<=22.04')
|
|
|
|
|
|
|
|
|
|
|
|
# Check if current version is between 20.04 (inclusive) and 22.04 (exclusive)
|
|
|
|
# check if current version is between 20.04 (inclusive) and 22.04 (exclusive)
|
|
|
|
check_version(current='21.10', minimum='20.04', maximum='22.04')
|
|
|
|
check_version(current='21.10', required='>20.04,<22.04')
|
|
|
|
```
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
current = pkg.parse_version(current)
|
|
|
|
current = pkg.parse_version(current)
|
|
|
|
minimum = pkg.parse_version(minimum)
|
|
|
|
constraints = re.findall(r'([<>!=]{1,2}\s*\d+\.\d+)', required) or [f'>={required}']
|
|
|
|
maximum = pkg.parse_version(maximum) if maximum else None
|
|
|
|
|
|
|
|
if pinned:
|
|
|
|
result = True
|
|
|
|
result = (current == minimum)
|
|
|
|
for constraint in constraints:
|
|
|
|
else:
|
|
|
|
op, version = re.match(r'([<>!=]{1,2})\s*(\d+\.\d+)', constraint).groups()
|
|
|
|
result = (current >= minimum) and (current <= maximum if maximum else True)
|
|
|
|
version = pkg.parse_version(version)
|
|
|
|
version_message = f'a version between {minimum} and {maximum}' if maximum else f'a minimum version {minimum}'
|
|
|
|
if op == '==' and current != version:
|
|
|
|
warning_message = f'WARNING ⚠️ {name} requires {version_message}, but {name}{current} is currently installed.'
|
|
|
|
result = False
|
|
|
|
if hard:
|
|
|
|
elif op == '!=' and current == version:
|
|
|
|
assert result, emojis(warning_message) # assert version requirements met
|
|
|
|
result = False
|
|
|
|
if verbose and not result:
|
|
|
|
elif op == '>=' and not (current >= version):
|
|
|
|
LOGGER.warning(warning_message)
|
|
|
|
result = False
|
|
|
|
|
|
|
|
elif op == '<=' and not (current <= version):
|
|
|
|
|
|
|
|
result = False
|
|
|
|
|
|
|
|
elif op == '>' and not (current > version):
|
|
|
|
|
|
|
|
result = False
|
|
|
|
|
|
|
|
elif op == '<' and not (current < version):
|
|
|
|
|
|
|
|
result = False
|
|
|
|
|
|
|
|
if not result:
|
|
|
|
|
|
|
|
warning_message = f'WARNING ⚠️ {name}{required} is required, but {name}{current} is currently installed'
|
|
|
|
|
|
|
|
if hard:
|
|
|
|
|
|
|
|
raise ModuleNotFoundError(emojis(warning_message)) # assert version requirements met
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
|
|
|
|
LOGGER.warning(warning_message)
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|