示例#1
0
def install(pypmenv, requirements, nodeps=False, hint_upgrade=False, skip_missing=False):
    """Install the given requirements into ``pypmenv.pyenv``
    
    - requirements: List of requirement strings
    - nodeps: don't install dependencies automatically
    - hint_upgrade: don't print 'skipping' messages
    - skip_missing: proceed installing others when some are missing.
    """
    depgraph = installer.PyPMDepGraph(pypmenv)
    for rs in requirements:
        r = Requirement.parse(rs)
        try:
            added = depgraph.add_requirement(r, nodeps=nodeps)
            if not added and not hint_upgrade:
                LOG.info('skipping "%s"; already installed at %s',
                         rs, pypmenv.pyenv.printable_location)
        except error.PackageNotFound as e:
            if e.required_by is None and skip_missing:
                # just warn of missing packages (unless it is a missing
                # dependency); allow other packages to be installed.
                if not hint_upgrade:
                    LOG.warn(e)
            else:
                raise
    return installer.Installer(pypmenv).apply(depgraph)
示例#2
0
def uninstall(pypmenv, names, nodeps=False):
    depgraph = installer.PyPMDepGraph(pypmenv)
    for name in names:
        if not depgraph.has_package(name):
            LOG.info('skipping "%s"; not installed', name)
        else:
            depgraph.remove_package(name, nodeps=nodeps)
    return installer.Installer(pypmenv).apply(
        depgraph, _requested_rmlist=names)
示例#3
0
    def _do_depgraph(self, subcmd, opts, *names):
        """${cmd_name}: Show the dependency graph

        ${cmd_usage}
        ${cmd_option_list}
        """
        with self.bootstrapped():
            depgraph = installer.PyPMDepGraph(self.pypmenv)
            for name in names:
                name = six.u(name)
                if opts.remove:
                    depgraph.remove_package(name)
                else:
                    depgraph.add_requirement(Requirement.parse(name))
            depgraph.display()
            return depgraph
示例#4
0
    def do_show(self, subcmd, opts, name, version=None):
        """${cmd_name}: Display detailed information about a package

        If the package is already installed, show the location of the
        site-packages directory under which it is installed.
        
        ${cmd_usage}
        ${cmd_option_list}
        """
        with self.bootstrapped():
            self._autosync()
            
            pkg = self.pypmenv.repo_store.find_package(name, version)
            dependencies = pkg.install_requires['']
            extra_dependencies = []
            for extra in pkg.install_requires:
                if extra == '': continue
                extra_dependencies.append('`pypm install {0}[{1}]` ->\n    {2}'.format(
                    pkg.name,
                    extra,
                    ',\n    '.join(pkg.install_requires[extra])))
            
            # Show package metadata
            LOG.info('Name: %s', pkg.name)
            LOG.info('Latest version: %s', pkg.printable_version)
            if pkg.author or pkg.author_email:
                LOG.info('Author: %s %s',
                         pkg.author,
                         pkg.author_email and '<%s>' % pkg.author_email or '')
            LOG.info('Summary: %s', pkg.summary)
            if pkg.home_page:
                LOG.info('Home Page: %s', pkg.home_page)
            if pkg.license:
                LOG.info('License: %s', pkg.license)
            
            # Show package dependencies
            if dependencies:
                LOG.info('Dependencies:')
                for dep in dependencies:
                    LOG.info(' %s', dep)
                if extra_dependencies:
                    LOG.info('Optional dependencies:')
                    for ed in extra_dependencies:
                        LOG.info(' %s', ed)
                        
            # Optionally, show packages depending on it
            if opts.rdepends:
                LOG.info('Depended by:')
                rdependencies = {}
                for rpkg in self.pypmenv.repo_store._query():
                    for req in rpkg.install_requires['']:
                        req = Requirement.parse(req)
                        if pkg.name == req_name(req):
                            if pkg.version in req:
                                prev_rpkg = rdependencies.get(rpkg.name, None)
                                if (not prev_rpkg) or (
                                    rpkg.version_key > prev_rpkg.version_key):
                                        rdependencies[rpkg.name] = rpkg
                if rdependencies:
                    LOG.info(wrapped(
                        ', '.join(sorted(
                            [p.full_name for p in rdependencies.values()])),
                        prefix=' ',
                        break_on_hyphens=False))
            
            # Show list of (older) versions available in the repository
            if not version:
                pkglist = self.pypmenv.repo_store.find_package_releases(name)
                LOG.info('Available versions: %s', ', '.join(
                    [p.printable_version for p in pkglist]))
            
            # Status: is this package installed or not? Does it require BE?
            try:
                ipkg = self.pypmenv.installed_store.find_only_package(name)
            except error.NoPackageInstalled:
                LOG.info('Status: Not installed')
                if pkg.requires_be_license and not licensing.user_has_be_license():
                    LOG.info(
                        'NOTE: This package requires a valid Business Edition '
                        'license. Please visit %s for more details.',
                        licensing.BE_HOME_PAGE)
            else:
                # Is this package installed because another package?
                depgraph = installer.PyPMDepGraph(self.pypmenv)
                required_by = depgraph.edges[ipkg.name].items()
                if required_by:
                    LOG.info('Required by:')
                    for rpkg, rl in required_by:
                        LOG.info(' %s [%s]', rpkg, req2str(*rl))
                    
                LOG.info('Status: Already installed (%s) at %s',
                         ipkg.printable_version,
                         self.pypmenv.pyenv.printable_location)
                # Is a newer version available for upgrade?
                if ipkg.version_key < pkg.version_key:
                    # TODO: Need --force
                    LOG.info('Status: '
                             'A newer version (%s) is available. '
                             'Type "pypm install %s" to upgrade',
                             pkg.printable_version,
                             pkg.name)

            # Show postinstall notes for this package
            for note in pkg.get_notes(postinstall=True):
                LOG.info('***NOTE***: %s', note['content'].strip())
                    
            if opts.open_home_page:
                import webbrowser
                u = 'http://code.activestate.com/pypm/{0}/'.format(pkg.name)
                webbrowser.open(pkg.home_page or u)
                
            return pkg