11""" Routines to support optional packages """
2- from distutils .version import LooseVersion
2+ from packaging .version import Version
33from .tripwire import TripWire
44
55
66def _check_pkg_version (pkg , min_version ):
77 # Default version checking function
88 if isinstance (min_version , str ):
9- min_version = LooseVersion (min_version )
9+ min_version = Version (min_version )
1010 try :
11- return min_version <= pkg .__version__
11+ return min_version <= Version ( pkg .__version__ )
1212 except AttributeError :
1313 return False
1414
@@ -24,9 +24,9 @@ def optional_package(name, trip_msg=None, min_version=None):
2424 message to give when someone tries to use the return package, but we
2525 could not import it at an acceptable version, and have returned a
2626 TripWire object instead. Default message if None.
27- min_version : None or str or LooseVersion or callable
27+ min_version : None or str or Version or callable
2828 If None, do not specify a minimum version. If str, convert to a
29- `distutils .version.LooseVersion` . If str or LooseVersion ` compare to
29+ ``packaging .version.Version`` . If str or ``Version` ` compare to
3030 version of package `name` with ``min_version <= pkg.__version__``. If
3131 callable, accepts imported ``pkg`` as argument, and returns value of
3232 callable is True for acceptable package versions, False otherwise.
0 commit comments