Example #1
0
def test_uninstallation_paths():
    class dist(object):
        def get_metadata_lines(self, record):
            return ['file.py,,',
                    'file.pyc,,',
                    'file.so,,',
                    'nopyc.py']
        location = ''

    d = dist()

    paths = list(wheel.uninstallation_paths(d))

    expected = ['file.py',
                'file.pyc',
                'file.so',
                'nopyc.py',
                'nopyc.pyc']

    assert paths == expected

    # Avoid an easy 'unique generator' bug
    paths2 = list(wheel.uninstallation_paths(d))

    assert paths2 == paths
Example #2
0
def test_uninstallation_paths():
    class dist(object):
        def get_metadata_lines(self, record):
            return ['file.py,,',
                    'file.pyc,,',
                    'file.so,,',
                    'nopyc.py']
        location = ''

    d = dist()

    paths = list(wheel.uninstallation_paths(d))

    expected = ['file.py',
                'file.pyc',
                'file.so',
                'nopyc.py',
                'nopyc.pyc']

    assert paths == expected

    # Avoid an easy 'unique generator' bug
    paths2 = list(wheel.uninstallation_paths(d))

    assert paths2 == paths
Example #3
0
def test_uninstallation_paths():
    class dist(object):
        def get_metadata_lines(self, record):
            return ["file.py,,", "file.pyc,,", "file.so,,", "nopyc.py"]

        location = ""

    d = dist()

    paths = list(wheel.uninstallation_paths(d))

    expected = ["file.py", "file.pyc", "file.so", "nopyc.py", "nopyc.pyc"]

    assert paths == expected

    # Avoid an easy 'unique generator' bug
    paths2 = list(wheel.uninstallation_paths(d))

    assert paths2 == paths
Example #4
0
    def _get_pkg_files(self, dist):
        """
        Shamelessly taken from pip/req.py/InstallRequirement.uninstall()
        """
        paths = set()

        def add(pth):
            paths.add(normalize_path(pth))
            if os.path.splitext(pth)[1] == '.py' and uses_pycache:
                add(cache_from_source(pth))

        pip_egg_info_path = os.path.join(
            dist.location, dist.egg_name()) + '.egg-info'
        dist_info_path = os.path.join(
            dist.location, '-'.join(dist.egg_name().split('-')[:2])
        ) + '.dist-info'
        # workaround http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=618367
        debian_egg_info_path = pip_egg_info_path.replace('-py' + PY_MAJOR, '')
        pip_egg_info_exists = os.path.exists(pip_egg_info_path)
        debian_egg_info_exists = os.path.exists(debian_egg_info_path)
        dist_info_exists = os.path.exists(dist_info_path)
        if pip_egg_info_exists or debian_egg_info_exists:
            # package installed by pip
            if pip_egg_info_exists:
                egg_info_path = pip_egg_info_path
            else:
                egg_info_path = debian_egg_info_path
            add(egg_info_path)
            if dist.has_metadata('installed-files.txt'):
                for installed_file in dist.get_metadata(
                        'installed-files.txt').splitlines():
                    path = os.path.normpath(
                        os.path.join(egg_info_path, installed_file))
                    add(path)
            elif dist.has_metadata('top_level.txt'):
                if dist.has_metadata('namespace_packages.txt'):
                    namespaces = dist.get_metadata('namespace_packages.txt')
                else:
                    namespaces = []
                for top_level_pkg in [
                    p for p in dist.get_metadata('top_level.txt').splitlines()
                        if p and p not in namespaces]:
                    path = os.path.join(dist.location, top_level_pkg)
                    add(path)
                    add(path + '.py')
                    add(path + '.pyc')
        elif dist_info_exists:
            for path in wheel.uninstallation_paths(dist):
                add(path)
        return paths