-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
I was trying to figure out why running with main (1.1.0.dev):
from mne.utils import check_version, requires_version
check_version("mne", "1.1") # returns True
requires_version("mne", "1.1") # marks to skip, i.e. check_version returned False
And it turns out there is both
Lines 69 to 120 in c6a86f1
| def check_version(library, min_version='0.0', *, strip=True, | |
| return_version=False): | |
| r"""Check minimum library version required. | |
| Parameters | |
| ---------- | |
| library : str | |
| The library name to import. Must have a ``__version__`` property. | |
| min_version : str | |
| The minimum version string. Anything that matches | |
| ``'(\d+ | [a-z]+ | \.)'``. Can also be empty to skip version | |
| check (just check for library presence). | |
| strip : bool | |
| If True (default), then PEP440 development markers like ``.devN`` | |
| will be stripped from the version. This makes it so that | |
| ``check_version('mne', '1.1')`` will be ``True`` even when on version | |
| ``'1.1.dev0'`` (prerelease/dev version). This option is provided for | |
| backward compatibility with the behavior of ``LooseVersion``, and | |
| diverges from how modern parsing in ``packaging.version.parse`` works. | |
| .. versionadded:: 1.0 | |
| return_version : bool | |
| If True (default False), also return the version (can be None if the | |
| library is missing). | |
| .. versionadded:: 1.0 | |
| Returns | |
| ------- | |
| ok : bool | |
| True if the library exists with at least the specified version. | |
| version : str | None | |
| The version. Only returned when ``return_version=True``. | |
| """ | |
| ok = True | |
| version = None | |
| try: | |
| library = import_module(library) | |
| except ImportError: | |
| ok = False | |
| else: | |
| check_version = min_version and min_version != '0.0' | |
| get_version = check_version or return_version | |
| if get_version: | |
| version = library.__version__ | |
| if strip: | |
| version = _strip_dev(version) | |
| if check_version: | |
| if _compare_version(version, '<', min_version): | |
| ok = False | |
| out = (ok, version) if return_version else ok | |
| return out |
and
mne-python/mne/utils/_testing.py
Lines 170 to 197 in c6a86f1
| def check_version(library, min_version): | |
| r"""Check minimum library version required. | |
| Parameters | |
| ---------- | |
| library : str | |
| The library name to import. Must have a ``__version__`` property. | |
| min_version : str | |
| The minimum version string. Anything that matches | |
| ``'(\d+ | [a-z]+ | \.)'``. Can also be empty to skip version | |
| check (just check for library presence). | |
| Returns | |
| ------- | |
| ok : bool | |
| True if the library exists with at least the specified version. | |
| """ | |
| ok = True | |
| try: | |
| library = __import__(library) | |
| except ImportError: | |
| ok = False | |
| else: | |
| if min_version: | |
| this_version = getattr(library, '__version__', '0.0').lstrip('v') | |
| if _compare_version(this_version, '<', min_version): | |
| ok = False | |
| return ok |
Which don't exactly do the same thing, but maybe they should?