version.py 999 B

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