def install(pypmenv, reqname): """Install the given requirement""" if reqname == 'setuptools': reqname = 'distribute' req, = parse_requirements(reqname) def get_installed_requirement(req): """Return the installed package that matches the requirement""" ipkg = pypmenv.installed_store.find_only_package(req.project_name) # TODO: support for req.specs in the above find if ipkg.version not in req: raise error.VersionConflict, \ 'Conflicting version is installed: %s' % ipkg.full_name return ipkg try: ipkg = get_installed_requirement(req) except error.NoPackageInstalled: pkg = pypmenv.repo_store.find_requirement(req) else: pkg = pypmenv.repo_store.find_requirement(req) if pkg.full_version == ipkg.full_version: # FIXME: This is not accurate; we should check the # dependencies as well. For instance, the second time the # user may type with extras .. as in: "pypm install # zope.component[docs]" .. and this time we should install # the 'docs' dependencies. But currently, we don't. LOG.info('%s is already installed', ipkg.full_name) return return installer.Installer(pypmenv).install(pkg, req.extras)
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)
def install_local_file(pypmenv, pypmfile): # nodeps = True (always!) """Install a local .pypm files Dependency is not automatically resolved, although we should do this in future """ assert pypmfile.endswith(BinaryPackage.EXTENSION) and P.exists(pypmfile) LOG.debug('Installing local package "%s"', pypmfile) bpkg = PackageFile(pypmfile).to_binary_package() # sanity check if bpkg.pyver != pypmenv.pyenv.pyver: raise ValueError( 'cannot install a {0} package on python {1}; {2}'.format( bpkg.pyver, pypmenv.pyenv.pyver, pypmfile)) if bpkg.osarch != PLATNAME: raise ValueError( 'incompatible platform {0}; {1}'.format( bpkg.osarch, pypmfile)) pkg = RepoPackage.create_from(bpkg, relpath=pypmfile, tags='local') with pypmenv.locked(): installer.Installer(pypmenv)._install(pkg, pypmfile)
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)
def uninstall(pypmenv, package_name): """Uninstall the given package""" if package_name == 'setuptools': package_name = 'distribute' req, = parse_requirements(package_name) if req.extras or req.specs: raise ValueError, ( 'The "uninstall" command does not support requirement ' 'specifiers. Please specify only the package name.') installed_package = pypmenv.installed_store.find_only_package( req.project_name) return installer.Installer(pypmenv).uninstall(installed_package)