Args: Compares a library version to some requirement using a given operation. library_or_version (`str` or `packaging.version.Version`): A library name or a version to check. operation (`str`): A string representation of an operator, such as `">"` or
(library_or_version: Union[str, Version], operation: str, requirement_version: str)
| 569 | |
| 570 | # This function was copied from: https://github.com/huggingface/accelerate/blob/874c4967d94badd24f893064cc3bef45f57cadf7/src/accelerate/utils/versions.py#L319 |
| 571 | def compare_versions(library_or_version: Union[str, Version], operation: str, requirement_version: str): |
| 572 | """ |
| 573 | Args: |
| 574 | Compares a library version to some requirement using a given operation. |
| 575 | library_or_version (`str` or `packaging.version.Version`): |
| 576 | A library name or a version to check. |
| 577 | operation (`str`): |
| 578 | A string representation of an operator, such as `">"` or `"<="`. |
| 579 | requirement_version (`str`): |
| 580 | The version to compare the library version against |
| 581 | """ |
| 582 | if operation not in STR_OPERATION_TO_FUNC.keys(): |
| 583 | raise ValueError(f"`operation` must be one of {list(STR_OPERATION_TO_FUNC.keys())}, received {operation}") |
| 584 | operation = STR_OPERATION_TO_FUNC[operation] |
| 585 | if isinstance(library_or_version, str): |
| 586 | library_or_version = parse(importlib_metadata.version(library_or_version)) |
| 587 | return operation(library_or_version, parse(requirement_version)) |
| 588 | |
| 589 | |
| 590 | # This function was copied from: https://github.com/huggingface/accelerate/blob/874c4967d94badd24f893064cc3bef45f57cadf7/src/accelerate/utils/versions.py#L338 |
no outgoing calls
no test coverage detected