Exemplo n.º 1
0
def patch(env):
    assert env.sys_version_info[:2] == (3, 1)
    pytest_location, pytest_version = _scan(env)
    if parse_version(pytest_version) >= parse_version("2.6.0"):
        return
    print("Patching installed pytest package...")
    file_path = os.path.join(pytest_location, "_pytest", "runner.py")
    file_temp_path = _file_temp_path(file_path)
    try:
        try:
            prepatched_count, patched_count = _patch(file_path, file_temp_path,
                unpatched_regex="(.*\s)callable([(].*)$",
                patched_regex="(.*\s)py[.]builtin[.]callable([(].*)",
                patch_pattern="%spy.builtin.callable%s")
            if (prepatched_count, patched_count) not in ((1, 0), (0, 1)):
                _error(file_path, "file content not recognized")
            if prepatched_count:
                print("WARNING: pytest already patched")
            else:
                os.remove(file_path)
                os.rename(file_temp_path, file_path)
        finally:
            _try_remove_file(file_temp_path)
    except (EnvironmentSetupError, KeyboardInterrupt, SystemExit):
        raise
    except Exception:
        _error(file_path, str(sys.exc_info()[1]))
Exemplo n.º 2
0
def check_Python24_pytest_requirements():
    """
    Check pytest requirements in the current Python 2.4.x environment.

    Installing pytest into a Python 2.4.x environment requires specific py &
    pytest package versions. This function checks whether the environment has
    such compatible Python environments installed.

    Returns a 2-tuple (have_pytest, have_py) indicating whether valid pytest &
    py library packages have been detected in the current Python 2.4.x
    environment. If the pytest package has not been detected, the py library
    package will not be checked and the have_py value will be set to None.

    See the module docstring for more detailed information.

    """
    assert sys.version_info[:2] == (2, 4)
    try:
        from pytest import __version__ as pytest_version
    except ImportError:
        return False, None  # no pytest
    pv_from = parse_version(_first_supported_pytest_version)
    pv_to = parse_version(_first_unsupported_pytest_version_on_Python_24)
    if not (pv_from <= parse_version(pytest_version) < pv_to):
        return False, None  # incompatible pytest version
    try:
        from py import __version__ as py_version
    except ImportError:
        return True, False  # no py library package
    pv_unsupported = parse_version(_first_unsupported_py_version_on_Python_24)
    if parse_version(py_version) >= pv_unsupported:
        return True, False  # incompatible py library package version
    return True, True
Exemplo n.º 3
0
def check_Python24_pytest_requirements():
    """
    Check pytest requirements in the current Python 2.4.x environment.

    Installing pytest into a Python 2.4.x environment requires specific py &
    pytest package versions. This function checks whether the environment has
    such compatible Python environments installed.

    Returns a 2-tuple (have_pytest, have_py) indicating whether valid pytest &
    py library packages have been detected in the current Python 2.4.x
    environment. If the pytest package has not been detected, the py library
    package will not be checked and the have_py value will be set to None.

    See the module docstring for more detailed information.

    """
    assert sys.version_info[:2] == (2, 4)
    try:
        from pytest import __version__ as pytest_version
    except ImportError:
        return False, None  # no pytest
    pv_from = parse_version(_first_supported_pytest_version)
    pv_to = parse_version(_first_unsupported_pytest_version_on_Python_24)
    if not (pv_from <= parse_version(pytest_version) < pv_to):
        return False, None  # incompatible pytest version
    try:
        from py import __version__ as py_version
    except ImportError:
        return True, False  # no py library package
    pv_unsupported = parse_version(_first_unsupported_py_version_on_Python_24)
    if parse_version(py_version) >= pv_unsupported:
        return True, False  # incompatible py library package version
    return True, True
Exemplo n.º 4
0
def _reuse_pre_installed_setuptools(env, installer):
    """
    Return whether a pre-installed setuptools distribution should be reused.

    """
    if not env.setuptools_version:
        return  # no prior setuptools ==> no reuse
    reuse_old = config.reuse_old_setuptools
    reuse_best = config.reuse_best_setuptools
    reuse_future = config.reuse_future_setuptools
    reuse_comment = None
    if reuse_old or reuse_best or reuse_future:
        pv_old = parse_version(env.setuptools_version)
        pv_new = parse_version(installer.setuptools_version())
        if pv_old < pv_new:
            if reuse_old:
                reuse_comment = "%s+ recommended" % (
                    installer.setuptools_version(),)
        elif pv_old > pv_new:
            if reuse_future:
                reuse_comment = "%s+ required" % (
                    installer.setuptools_version(),)
        elif reuse_best:
            reuse_comment = ""
    if reuse_comment is None:
        return  # reuse not allowed by configuration
    if reuse_comment:
        reuse_comment = " (%s)" % (reuse_comment,)
    print("Reusing pre-installed setuptools %s distribution%s." % (
        env.setuptools_version, reuse_comment))
    return True  # reusing pre-installed setuptools
Exemplo n.º 5
0
def _reuse_pre_installed_setuptools(env, installer):
    """
    Return whether a pre-installed setuptools distribution should be reused.

    """
    if not env.setuptools_version:
        return  # no prior setuptools ==> no reuse
    reuse_old = config.reuse_old_setuptools
    reuse_best = config.reuse_best_setuptools
    reuse_future = config.reuse_future_setuptools
    reuse_comment = None
    if reuse_old or reuse_best or reuse_future:
        pv_old = parse_version(env.setuptools_version)
        pv_new = parse_version(installer.setuptools_version())
        if pv_old < pv_new:
            if reuse_old:
                reuse_comment = "%s+ recommended" % (
                    installer.setuptools_version(), )
        elif pv_old > pv_new:
            if reuse_future:
                reuse_comment = "%s+ required" % (
                    installer.setuptools_version(), )
        elif reuse_best:
            reuse_comment = ""
    if reuse_comment is None:
        return  # reuse not allowed by configuration
    if reuse_comment:
        reuse_comment = " (%s)" % (reuse_comment, )
    print("Reusing pre-installed setuptools %s distribution%s." %
          (env.setuptools_version, reuse_comment))
    return True  # reusing pre-installed setuptools
Exemplo n.º 6
0
def _avoid_setuptools_zipped_egg_upgrade_issue(env, ez_setup):
    """
    Avoid the setuptools self-upgrade issue.

    setuptools versions prior to version 3.5.2 have a bug that can cause their
    upgrade installations to fail when installing a new zipped egg distribution
    over an existing zipped egg setuptools distribution with the same name.

    The following Python versions are not affected by this issue:
      Python 2.4 - use setuptools 1.4.2 - installs itself as a non-zipped egg
      Python 2.6+ - use setuptools versions not affected by this issue
    That just leaves Python versions 2.5.x to worry about.

    This problem occurs because of an internal stale cache issue causing the
    upgrade to read data from the new zip archive at a location calculated
    based on the original zip archive's content, effectively causing such read
    operations to either succeed (if read content had not changed its
    location), fail with a 'bad local header' exception or even fail silently
    and return incorrect data.

    To avoid the issue, we explicitly uninstall the previously installed
    setuptools distribution before installing its new version.

    """
    if env.sys_version_info[:2] != (2, 5):
        return  # only Python 2.5.x affected by this
    if not env.setuptools_zipped_egg:
        return  # setuptools not pre-installed as a zipped egg
    pv_new = parse_version(ez_setup.setuptools_version())
    if pv_new != parse_version(env.setuptools_version):
        return  # issue avoided since zipped egg archive names will not match
    fixed_version = utility.lowest_version_string_with_prefix("3.5.2")
    if pv_new >= parse_version(fixed_version):
        return  # issue fixed in setuptools
    # We could check for pip and use it for a cleaner setuptools uninstall if
    # available, but YAGNI since only Python 2.5.x environments are affected by
    # the zipped egg upgrade issue.
    os.remove(env.setuptools_zipped_egg)
Exemplo n.º 7
0
def _avoid_setuptools_zipped_egg_upgrade_issue(env, ez_setup):
    """
    Avoid the setuptools self-upgrade issue.

    setuptools versions prior to version 3.5.2 have a bug that can cause their
    upgrade installations to fail when installing a new zipped egg distribution
    over an existing zipped egg setuptools distribution with the same name.

    The following Python versions are not affected by this issue:
      Python 2.4 - use setuptools 1.4.2 - installs itself as a non-zipped egg
      Python 2.6+ - use setuptools versions not affected by this issue
    That just leaves Python versions 2.5.x to worry about.

    This problem occurs because of an internal stale cache issue causing the
    upgrade to read data from the new zip archive at a location calculated
    based on the original zip archive's content, effectively causing such read
    operations to either succeed (if read content had not changed its
    location), fail with a 'bad local header' exception or even fail silently
    and return incorrect data.

    To avoid the issue, we explicitly uninstall the previously installed
    setuptools distribution before installing its new version.

    """
    if env.sys_version_info[:2] != (2, 5):
        return  # only Python 2.5.x affected by this
    if not env.setuptools_zipped_egg:
        return  # setuptools not pre-installed as a zipped egg
    pv_new = parse_version(ez_setup.setuptools_version())
    if pv_new != parse_version(env.setuptools_version):
        return  # issue avoided since zipped egg archive names will not match
    fixed_version = utility.lowest_version_string_with_prefix("3.5.2")
    if pv_new >= parse_version(fixed_version):
        return  # issue fixed in setuptools
    # We could check for pip and use it for a cleaner setuptools uninstall if
    # available, but YAGNI since only Python 2.5.x environments are affected by
    # the zipped egg upgrade issue.
    os.remove(env.setuptools_zipped_egg)