version.py 951 B

12345678910111213141516171819202122232425262728293031323334
  1. """
  2. Utilities for version comparison
  3. It is a bit ridiculous that we need these.
  4. """
  5. # Copyright (c) Jupyter Development Team.
  6. # Distributed under the terms of the Modified BSD License.
  7. from packaging.version import Version
  8. def check_version(v, min_v, max_v=None):
  9. """check version string v >= min_v and v < max_v
  10. Parameters
  11. ----------
  12. v : str
  13. version of the package
  14. min_v : str
  15. minimal version supported
  16. max_v : str
  17. earliest version not supported
  18. Note: If dev/prerelease tags result in TypeError for string-number
  19. comparison, it is assumed that the check passes and the version dependency
  20. is satisfied. Users on dev branches are responsible for keeping their own
  21. packages up to date.
  22. """
  23. try:
  24. below_max = Version(v) < Version(max_v) if max_v is not None else True
  25. return Version(v) >= Version(min_v) and below_max
  26. except TypeError:
  27. return True