Similar to site.addsitedir() but prefers new sitedir over existing ones.
    Therefore, prefers local packages over installed packages.

    .. note::
        This allows to support *.pth files and zip-/egg-imports
        similar to an installed site-packages directory.

def project_workspace_addsitedir(sitedir):
    """
    Similar to site.addsitedir() but prefers new sitedir over existing ones.
    Therefore, prefers local packages over installed packages.

    .. note::
        This allows to support *.pth files and zip-/egg-imports
        similar to an installed site-packages directory.
    """
    assert os.path.isdir(sitedir)
    try:
        from site import addsitedir
    except ImportError:
        # -- USE: Python2.7 site.py package
        from pysite import addsitedir
    next_package_pos = len(sys.path)
    addsitedir(sitedir)

    # -- POST-PROCESS: Move new packages from end to begin of sys.path list.
    pos = 0
    new_packages = sys.path[next_package_pos:]
    del sys.path[next_package_pos:]
    sys.path[pos:pos] = new_packages