python类version_info()的实例源码

common.py 文件源码 项目:itango 作者: tango-controls 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_ipython_version():
    """Returns the current IPython version"""
    import IPython
    v = None
    if hasattr(IPython, "version_info"):
        v = '.'.join(map(str, IPython.version_info[:3]))
    else:
        try:
            try:
                v = IPython.Release.version
            except:
                try:
                    v = IPython.release.version
                except:
                    pass
        except:
            pass
    return StrictVersion(v)


# PyTango utilities
iptest.py 文件源码 项目:leetcode 作者: thomasyimgit 项目源码 文件源码 阅读 73 收藏 0 点赞 0 评论 0
def test_for(item, min_version=None, callback=extract_version):
    """Test to see if item is importable, and optionally check against a minimum
    version.

    If min_version is given, the default behavior is to check against the
    `__version__` attribute of the item, but specifying `callback` allows you to
    extract the value you are interested in. e.g::

        In [1]: import sys

        In [2]: from IPython.testing.iptest import test_for

        In [3]: test_for('sys', (2,6), callback=lambda sys: sys.version_info)
        Out[3]: True

    """
    try:
        check = import_item(item)
    except (ImportError, RuntimeError):
        # GTK reports Runtime error if it can't be initialized even if it's
        # importable.
        return False
    else:
        if min_version:
            if callback:
                # extra processing step to get version to compare
                check = callback(check)

            return check >= min_version
        else:
            return True

# Global dict where we can store information on what we have and what we don't
# have available at test run time
iptest.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_for(item, min_version=None, callback=extract_version):
    """Test to see if item is importable, and optionally check against a minimum
    version.

    If min_version is given, the default behavior is to check against the
    `__version__` attribute of the item, but specifying `callback` allows you to
    extract the value you are interested in. e.g::

        In [1]: import sys

        In [2]: from IPython.testing.iptest import test_for

        In [3]: test_for('sys', (2,6), callback=lambda sys: sys.version_info)
        Out[3]: True

    """
    try:
        check = import_item(item)
    except (ImportError, RuntimeError):
        # GTK reports Runtime error if it can't be initialized even if it's
        # importable.
        return False
    else:
        if min_version:
            if callback:
                # extra processing step to get version to compare
                check = callback(check)

            return check >= min_version
        else:
            return True

# Global dict where we can store information on what we have and what we don't
# have available at test run time
lifecycle.py 文件源码 项目:rlipython 作者: ipython 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def install():
    """Register `rlipython` as the default interactive interface for IPython.

    When you run this inside IPython, the preference gets applied to the
    current IPython profile. When run using plain Python, the preference gets
    applied to the default profile.

    Run `uninstall()` if you ever change your mind and want to revert to the
    default IPython behavior.
    """
    if ipython_version < (5,4):
        print("`rliptyhon` will only work with IPython 5.4. or above. Aborting")
        return

    cfg, json_path = get_config()

    installed = cfg.get(app_key, {}).get(shell_key) == rl_config

    if installed:
        print ("Looks like rlipython is already installed.")
        return

    if get_ipython() is None:
        log.warning(DEFAULT_WARNING + json_path)

    with open(json_path, 'w') as f:
        cfg.update({app_key: {shell_key: rl_config}})
        json.dump(cfg, f)

    print("Installation succeeded: enjoy rlipython the next time you run ipython!")

    if sys.platform == "darwin" and sys.version_info[:2] >= (3, 6):
        print(OSX_PY36_GNUREADLINE_WARNING)
iptest.py 文件源码 项目:blender 作者: gastrodia 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_for(item, min_version=None, callback=extract_version):
    """Test to see if item is importable, and optionally check against a minimum
    version.

    If min_version is given, the default behavior is to check against the
    `__version__` attribute of the item, but specifying `callback` allows you to
    extract the value you are interested in. e.g::

        In [1]: import sys

        In [2]: from IPython.testing.iptest import test_for

        In [3]: test_for('sys', (2,6), callback=lambda sys: sys.version_info)
        Out[3]: True

    """
    try:
        check = import_item(item)
    except (ImportError, RuntimeError):
        # GTK reports Runtime error if it can't be initialized even if it's
        # importable.
        return False
    else:
        if min_version:
            if callback:
                # extra processing step to get version to compare
                check = callback(check)

            return check >= min_version
        else:
            return True

# Global dict where we can store information on what we have and what we don't
# have available at test run time
common.py 文件源码 项目:itango 作者: tango-controls 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_python_version():
    return StrictVersion('.'.join(map(str, sys.version_info[:3])))


# IPython utilities
iptest.py 文件源码 项目:yatta_reader 作者: sound88 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def test_for(item, min_version=None, callback=extract_version):
    """Test to see if item is importable, and optionally check against a minimum
    version.

    If min_version is given, the default behavior is to check against the
    `__version__` attribute of the item, but specifying `callback` allows you to
    extract the value you are interested in. e.g::

        In [1]: import sys

        In [2]: from IPython.testing.iptest import test_for

        In [3]: test_for('sys', (2,6), callback=lambda sys: sys.version_info)
        Out[3]: True

    """
    try:
        check = import_item(item)
    except (ImportError, RuntimeError):
        # GTK reports Runtime error if it can't be initialized even if it's
        # importable.
        return False
    else:
        if min_version:
            if callback:
                # extra processing step to get version to compare
                check = callback(check)

            return check >= min_version
        else:
            return True

# Global dict where we can store information on what we have and what we don't
# have available at test run time


问题


面经


文章

微信
公众号

扫码关注公众号