MCPcopy
hub / github.com/mne-tools/mne-python / check_version

Function check_version

mne/utils/check.py:80–130  ·  view source on GitHub ↗

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

(library, min_version="0.0", *, strip=True, return_version=False)

Source from the content-addressed store, hash-verified

78
79
80def check_version(library, min_version="0.0", *, strip=True, return_version=False):
81 r"""Check minimum library version required.
82
83 Parameters
84 ----------
85 library : str
86 The library name to import. Must have a ``__version__`` property.
87 min_version : str
88 The minimum version string. Anything that matches
89 ``'(\d+ | [a-z]+ | \.)'``. Can also be empty to skip version
90 check (just check for library presence).
91 strip : bool
92 If True (default), then PEP440 development markers like ``.devN``
93 will be stripped from the version. This makes it so that
94 ``check_version('mne', '1.1')`` will be ``True`` even when on version
95 ``'1.1.dev0'`` (prerelease/dev version). This option is provided for
96 backward compatibility with the behavior of ``LooseVersion``, and
97 diverges from how modern parsing in ``packaging.version.parse`` works.
98
99 .. versionadded:: 1.0
100 return_version : bool
101 If True (default False), also return the version (can be None if the
102 library is missing).
103
104 .. versionadded:: 1.0
105
106 Returns
107 -------
108 ok : bool
109 True if the library exists with at least the specified version.
110 version : str | None
111 The version. Only returned when ``return_version=True``.
112 """
113 ok = True
114 version = None
115 try:
116 library = import_module(library)
117 except ImportError:
118 ok = False
119 else:
120 check_version = min_version and min_version != "0.0"
121 get_version = check_version or return_version
122 if get_version:
123 version = library.__version__
124 if strip:
125 version = _strip_dev(version)
126 if check_version:
127 if _compare_version(version, "<", min_version):
128 ok = False
129 out = (ok, version) if return_version else ok
130 return out
131
132
133def _strip_dev(version):

Callers 15

pixel_ratioFunction · 0.90
test_strip_devFunction · 0.90
test_ica.pyFile · 0.90
test_search_light_basicFunction · 0.90
test_get_coefFunction · 0.90
_test_raw_readerFunction · 0.90
test_bem.pyFile · 0.90

Calls 2

_strip_devFunction · 0.85
_compare_versionFunction · 0.85

Tested by 11

pixel_ratioFunction · 0.72
test_strip_devFunction · 0.72
test_search_light_basicFunction · 0.72
test_get_coefFunction · 0.72
_test_raw_readerFunction · 0.72
test_merge_annotationsFunction · 0.72
test_brain_tracesFunction · 0.72
requires_openmeeg_markFunction · 0.68
_get_suptitleFunction · 0.68