def populate_requirement_set(self, requirement_set, args, options, finder, session, name, wheel_cache): # add all of the standard reqs first. InstallCommand.populate_requirement_set(requirement_set, args, options, finder, session, name, wheel_cache) # add our constraints. if hasattr(self, "constraint_dict"): for package_name, specifier in self.constraint_dict.items(): requirement = package_name if specifier: requirement += specifier for req in process_line(requirement, "", 0, finder=finder, options=options, session=session, wheel_cache=wheel_cache, constraint=True): try: existing_req = requirement_set.get_requirement( package_name) existing_req.req.specifier &= req.specifier except KeyError: requirement_set.add_requirement(req) for r in requirement_set.unnamed_requirements: if r.editable: r.run_egg_info() name = r.pkg_info()["name"] if name in requirement_set.requirements: del requirement_set.requirements._dict[name] requirement_set.requirements._keys.remove(name)
def run_actions(self, actions): for action in actions: if isinstance(action, InstallAction): ui.info('Installing', ui.dep(action.dependency)) command = InstallCommand() with pip_progress(): command.main([ '--no-deps', '--index-url', self.index_url, '--prefix', self.virtualenv, '--ignore-installed', '--upgrade', str(action.dependency) ]) if isinstance(action, SaveAction): self.requirements.add(action.spec) if isinstance(action, FailAction): sys.exit(1) if isinstance(action, RemoveAction): ui.info('Removing', ui.pkg(action.package)) entries = action.package.metadata.get_metadata('RECORD').splitlines() for line in entries: path = line.split(',')[0] path = os.path.join(self.site_packages, path) if os.path.exists(path): os.unlink(path) if len(os.listdir(os.path.split(path)[0])) == 0: os.rmdir(os.path.split(path)[0])
def install(install_dir, egg, url): initial_args = ["install", "--install-option=--install-purelib={}".format(install_dir), url] cmd_name, options, args, parser = pip.parseopts(initial_args) command = InstallCommand(parser) return command.main(args[1:], options)
def install(install_dir, egg, url): initial_args = ['install', '--install-option=--install-purelib={}'.format(install_dir), url] try: # This version works for Pip 6. from pip.commands import InstallCommand cmd_name, options = pip.parseopts(initial_args) command = InstallCommand() return command.main(options) except: pass try: # An earlier version of pip cmd_name, options, args, parser = pip.parseopts(initial_args) command = InstallCommand(parser) return command.main(args[1:], options) except ValueError: from pip.commands import commands cmd_name, cmd_args = pip.parseopts(initial_args) command = commands[cmd_name]() return command.main(cmd_args)
def pip_install_single_package(package, site_wide = False, isolated=False): try: from pip.commands import InstallCommand except ImportError: # log.info('error importing InstallCommand') import sys sys.exit(0) try: from pip.exceptions import BadCommand, InstallationError, UninstallationError, CommandError, PreviousBuildDirError except ImportError: # log.info('error importing pip.exceptions') import sys sys.exit(0) try: from pip.status_codes import ERROR, UNKNOWN_ERROR, PREVIOUS_BUILD_DIR_ERROR except ImportError: # log.info('error importing pip status codes') import sys sys.exit(0) if site_wide: cmd_name, cmd_args = 'install', [package] else: cmd_name, cmd_args = 'install', [package, '--user'] command = InstallCommand(isolated=isolated) options, args = command.parse_args(cmd_args) try: status = command.run(options, args) if isinstance(status, int): return status except PreviousBuildDirError as exc: # log.critical(str(exc)) # log.debug('Exception information:', exc_info=True) # log.info('PREVIOUS_BUILD_DIR_ERROR') return PREVIOUS_BUILD_DIR_ERROR except (InstallationError, UninstallationError, BadCommand) as exc: # log.critical(str(exc)) # log.debug('Exception information:', exc_info=True) # log.info('InstallationError, UninstallationError, BadCommand') return ERROR except CommandError as exc: # log.critical('ERROR: %s', exc) # log.debug('Exception information:', exc_info=True) # log.info('CommandError') return ERROR except KeyboardInterrupt: # log.critical('Operation cancelled by user') # log.debug('Exception information:', exc_info=True) return ERROR except: # log.info('Installation failed') # log.critical('Exception:', exc_info=True) return UNKNOWN_ERROR
class InstallCmd(object): def __init__(self): self.cmd = InstallCommand() def dry_run(self, name, local, remote): print("Would update {0} {1} -> {2}".format( name, display_version(local), display_version(remote))) def upgrade(self, name): options, args = self.cmd.parser.parse_args(['-U', name]) self.cmd.run(options, args)
def install(args, update=False, register=True): c = InstallCommand() dev = False try: dev_option_index = args.index("-d") or args.index("--dev") dev = True args.pop(dev_option_index) except ValueError: pass options, packages = separate_packages_n_options(c, args) for pkg in packages: if pkg == "install": continue per_package_args = [pkg] + options if update: per_package_args.append("--upgrade") if c.main(per_package_args) == 0 and register: register_dependency(pkg, dev=dev)
def install(install_dir, egg, url): initial_args = [ 'install', '--install-option=--install-purelib={}'.format(install_dir), url ] try: # An earlier version of pip cmd_name, options, args, parser = pip.parseopts(initial_args) command = InstallCommand(parser) return command.main(args[1:], options) except ValueError: from pip.commands import commands cmd_name, cmd_args = pip.parseopts(initial_args) command = commands[cmd_name]() return command.main(cmd_args) raise Exception()
def populate_requirement_set(self, requirement_set, args, options, finder, session, name, wheel_cache): # add all of the standard reqs first. InstallCommand.populate_requirement_set(requirement_set, args, options, finder, session, name, wheel_cache) packages_config = getattr(self, "packages_config", {}) # add our constraints. if hasattr(self, "constraint_dict"): for package_name, specifier in self.constraint_dict.items(): requirement = package_name if specifier: requirement += specifier for req in process_line(requirement, "", 0, finder=finder, options=options, session=session, wheel_cache=wheel_cache, constraint=True): if packages_config and req.name in packages_config: # Wrap the requirement's install method so we can # apply custom install options if provided req.install = functools.partial( types.MethodType(requirement_install, req), packages_config.get(req.name)) try: existing_req = requirement_set.get_requirement( package_name) existing_req.req.specifier &= req.specifier except KeyError: requirement_set.add_requirement(req) for r in requirement_set.unnamed_requirements: if r.editable: r.run_egg_info() name = r.pkg_info()["name"] if name in requirement_set.requirements: del requirement_set.requirements._dict[name] requirement_set.requirements._keys.remove(name)
def populate_requirement_set(self, requirement_set, args, options, finder, session, name, wheel_cache): # add all of the standard reqs first. InstallCommand.populate_requirement_set( requirement_set, args, options, finder, session, name, wheel_cache ) packages_config = getattr(self, "packages_config", {}) # add our constraints. if hasattr(self, "constraint_dict"): for package_name, specifier in self.constraint_dict.items(): requirement = package_name if specifier: requirement += specifier for req in process_line( requirement, "", 0, finder=finder, options=options, session=session, wheel_cache=wheel_cache, constraint=True ): if packages_config and req.name in packages_config: # Wrap the requirement's install method so we can # apply custom install options if provided req.install = functools.partial( types.MethodType(requirement_install, req), packages_config.get(req.name)) try: existing_req = requirement_set.get_requirement( package_name) existing_req.req.specifier &= req.specifier except KeyError: requirement_set.add_requirement(req) for r in requirement_set.unnamed_requirements: if r.editable: r.run_egg_info() name = r.pkg_info()["name"] if name in requirement_set.requirements: del requirement_set.requirements._dict[name] requirement_set.requirements._keys.remove(name)
def handle_noargs(self, **options): if options.get('requirements', False): req_files = options["requirements"] elif os.path.exists("requirements.txt"): req_files = ["requirements.txt"] elif os.path.exists("requirements"): req_files = [ "requirements/{0}".format(f) for f in os.listdir("requirements") if os.path.isfile(os.path.join("requirements", f)) and f.lower().endswith(".txt") ] else: sys.exit("requirements not found") initial_args = ['install', '--upgrade', '--no-deps'] [ initial_args.extend( ['--requirement', os.path.join(settings.BASE_DIR, req)]) for req in req_files ] cmd_name, args = pip.parseopts(initial_args) InstallCommand().main(args)
def __init__(self): self.cmd = InstallCommand()