version.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # encoding: utf-8
  2. """
  3. Utilities for version comparison
  4. It is a bit ridiculous that we need these.
  5. """
  6. #-----------------------------------------------------------------------------
  7. # Copyright (C) 2013 The IPython Development Team
  8. #
  9. # Distributed under the terms of the BSD License. The full license is in
  10. # the file COPYING, distributed as part of this software.
  11. #-----------------------------------------------------------------------------
  12. #-----------------------------------------------------------------------------
  13. # Imports
  14. #-----------------------------------------------------------------------------
  15. from distutils.version import LooseVersion
  16. #-----------------------------------------------------------------------------
  17. # Code
  18. #-----------------------------------------------------------------------------
  19. def check_version(v, check):
  20. """check version string v >= check
  21. If dev/prerelease tags result in TypeError for string-number comparison,
  22. it is assumed that the dependency is satisfied.
  23. Users on dev branches are responsible for keeping their own packages up to date.
  24. """
  25. try:
  26. return LooseVersion(v) >= LooseVersion(check)
  27. except TypeError:
  28. return True