예제 #1
0
def uninstall_eggs(reqs):
    """ Remove eggs matching the given requirements.
    """
    # XXX This doesn't do dependencies?
    dists = []
    for i in pkg_resources.parse_requirements(reqs):
        dist = next((d for d in pkg_resources.working_set
                     if d.project_name == i.project_name), None)
        if not dist:
            raise DistutilsOptionError('Cannot remove package, not installed',
                                       i.project_name)
        if not dist.location.endswith('.egg'):
            raise DistutilsOptionError('Not an egg at %s, chickening out' %
                                       dist.location)
        dists.append(dist)

    for dist in dists:
        if is_local(dist.location):
            log.info("Removing %s (%s)" % (dist, dist.location))
            # Clear references to egg - http://trac.edgewall.org/ticket/7014
            uncache_zipdir(dist.location)
            try:
                os.remove(dist.location)
            except OSError as ex:
                if ex.errno == errno.EISDIR:
                    shutil.rmtree(dist.location)
                else:
                    raise
        else:
            log.info("Not uninstalling egg, it's not in our virtualenv: %s",
                     dist.location)
        dependency.remove_from_ws(pkg_resources.working_set, dist)
    def _permitted(self, path):
        """
        Return True if the given path is one we are permitted to
        remove/modify, False otherwise.

        """
        return is_local(path)
예제 #3
0
파일: buildout.py 프로젝트: drkjam/pkglib
def uninstall_eggs(reqs):
    """ Remove eggs matching the given requirements.
    """
    # XXX This doesn't do dependencies?
    dists = []
    names = [i.project_name for i in pkg_resources.parse_requirements(reqs)]
    for name in names:
        dist = [d for d in pkg_resources.working_set if d.project_name == name]
        if not dist:
            raise DistutilsOptionError('Cannot remove package not yet '
                                       'installed: %s' % name)
        dist = dist[0]
        if not dist.location.endswith('.egg'):
            raise DistutilsOptionError('Not an egg at %s, chickening out' %
                                       dist.location)
        if is_local(dist.location):
            dists.append(dist)
        else:
            log.info("Not uninstalling egg, it's not in our virtualenv: %s" %
                     dist.location)

    for dist in dists:
        log.info("Removing %s (%s)" % (dist, dist.location))
        shutil.rmtree(dist.location)
        dependency.remove_from_ws(pkg_resources.working_set, dist)
예제 #4
0
def uninstall_eggs(reqs):
    """ Remove eggs matching the given requirements.
    """
    # XXX This doesn't do dependencies?
    dists = []
    for i in pkg_resources.parse_requirements(reqs):
        dist = next((d for d in pkg_resources.working_set
                     if d.project_name == i.project_name), None)
        if not dist:
            raise DistutilsOptionError('Cannot remove package, not installed',
                                       i.project_name)
        if not dist.location.endswith('.egg'):
            raise DistutilsOptionError('Not an egg at %s, chickening out' %
                                       dist.location)
        dists.append(dist)

    for dist in dists:
        if is_local(dist.location):
            log.info("Removing %s (%s)" % (dist, dist.location))
            # Clear references to egg - http://trac.edgewall.org/ticket/7014
            uncache_zipdir(dist.location)
            try:
                os.remove(dist.location)
            except OSError as ex:
                if ex.errno == errno.EISDIR:
                    shutil.rmtree(dist.location)
                else:
                    raise
        else:
            log.info("Not uninstalling egg, it's not in our virtualenv: %s",
                     dist.location)
        dependency.remove_from_ws(pkg_resources.working_set, dist)
    def _permitted(self, path):
        """
        Return True if the given path is one we are permitted to
        remove/modify, False otherwise.

        """
        return is_local(path)
예제 #6
0
파일: freeze.py 프로젝트: codysoyland/pip
    def run(self, options, args):
        requirement = options.requirement
        find_links = options.find_links or []
        local_only = options.local
        ## FIXME: Obviously this should be settable:
        find_tags = False
        skip_match = None

        skip_regex = options.skip_requirements_regex
        if skip_regex:
            skip_match = re.compile(skip_regex)

        logger.move_stdout_to_stderr()
        dependency_links = []

        f = sys.stdout

        for dist in pkg_resources.working_set:
            if dist.has_metadata('dependency_links.txt'):
                dependency_links.extend(dist.get_metadata_lines('dependency_links.txt'))
        for link in find_links:
            if '#egg=' in link:
                dependency_links.append(link)
        for link in find_links:
            f.write('-f %s\n' % link)
        installations = {}
        for dist in pkg_resources.working_set:
            if local_only and not is_local(dist_location(dist)):
                continue
            if dist.key in ('setuptools', 'pip', 'python'):
                ## FIXME: also skip virtualenv?
                continue
            req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
            installations[req.name] = req
        if requirement:
            req_f = open(requirement)
            for line in req_f:
                if not line.strip() or line.strip().startswith('#'):
                    f.write(line)
                    continue
                if skip_match and skip_match.search(line):
                    f.write(line)
                    continue
                elif line.startswith('-e') or line.startswith('--editable'):
                    if line.startswith('-e'):
                        line = line[2:].strip()
                    else:
                        line = line[len('--editable'):].strip().lstrip('=')
                    line_req = InstallRequirement.from_editable(line, default_vcs=options.default_vcs)
                elif (line.startswith('-r') or line.startswith('--requirement')
                      or line.startswith('-Z') or line.startswith('--always-unzip')
                      or line.startswith('-f') or line.startswith('-i')
                      or line.startswith('--extra-index-url')):
                    f.write(line)
                    continue
                else:
                    line_req = InstallRequirement.from_line(line)
                if not line_req.name:
                    logger.notify("Skipping line because it's not clear what it would install: %s"
                                  % line.strip())
                    logger.notify("  (add #egg=PackageName to the URL to avoid this warning)")
                    continue
                if line_req.name not in installations:
                    logger.warn("Requirement file contains %s, but that package is not installed"
                                % line.strip())
                    continue
                f.write(str(installations[line_req.name]))
                del installations[line_req.name]
            f.write('## The following requirements were added by pip --freeze:\n')
        for installation in sorted(installations.values(), key=lambda x: x.name):
            f.write(str(installation))