def warn_setuptools_issue(out=None): if not out: out = sys.stderr import setuptools from pkg_resources import parse_version as parse if parse('5.4') <= parse(setuptools.__version__) < parse('5.7') and \ not os.environ.get('PKG_RESOURCES_CACHE_ZIP_MANIFESTS'): out.write("Warning: Detected setuptools version %s. The environment " "variable 'PKG_RESOURCES_CACHE_ZIP_MANIFESTS' must be set " "to avoid significant performance degradation.\n" % setuptools.__version__)
def _compare_version(version_a, operator, version_b): """Compare two version strings via a user-specified operator. ``distutils`` has been deprecated since Python 3.10 and is scheduled for removal from the standard library with the release of Python 3.12. For version comparisons, we use setuptools's `parse_version` if available. Note: This function is inspired from MNE-Python. See https://github.com/mne-tools/mne-python/blob/main/mne/fixes.py Parameters ---------- version_a : :obj:`str` First version string. operator : {'==', '!=','>', '<', '>=', '<='} Operator to compare ``version_a`` and ``version_b`` in the form of ``version_a operator version_b``. version_b : :obj:`str` Second version string. Returns ------- result : :obj:`bool` The result of the version comparison. """ # TODO: # The setuptools doc encourages the use of importlib.metadata instead # of pkg_resources. However, importlib.metadata is only part of the stdlib # for Python >= 3.8. When Nilearn will only support Python >= 3.8, # please consider changing the following line to: # from importlib.metadata import version as parse try: from pkg_resources import parse_version as parse # noqa:F401 except ImportError: from distutils.version import LooseVersion as parse # noqa:F401 if operator not in VERSION_OPERATORS: raise ValueError( "'_compare_version' received an unexpected " "operator {0}.".format(operator) ) return VERSION_OPERATORS[operator](parse(version_a), parse(version_b))