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 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 main(args=None): if args is None: args = sys.argv[1:] # Configure our deprecation warnings to be sent through loggers deprecation.install_warning_logger() autocomplete() try: cmd_name, cmd_args = parseopts(args) except PipError as exc: sys.stderr.write("ERROR: %s" % exc) sys.stderr.write(os.linesep) sys.exit(1) # Needed for locale.getpreferredencoding(False) to work # in pip.utils.encoding.auto_decode try: locale.setlocale(locale.LC_ALL, '') except locale.Error as e: # setlocale can apparently crash if locale are uninitialized logger.debug("Ignoring error %s when setting locale", e) command = commands_dict[cmd_name](isolated=check_isolated(cmd_args)) return command.main(cmd_args)
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 uninstall(install_dir, egg): raise NotImplementedError() from pip.commands import UninstallCommand initial_args = ['uninstall', egg] cmd_name, options = pip.parseopts(initial_args) command = UninstallCommand() return command.main(options)
def get_pip_requirement_set(self, arguments, use_remote_index): """ Get the unpacked requirement(s) specified by the caller by running pip. :param arguments: The command line arguments to ``pip install ..`` (a list of strings). :param use_remote_index: A boolean indicating whether pip is allowed to connect to the main package index (http://pypi.python.org by default). :returns: A :py:class:`pip.req.RequirementSet` object created by pip. :raises: Any exceptions raised by pip. """ # Compose the pip command line arguments. command_line = ['pip', 'install', '--no-install'] if use_remote_index: command_line.append('--download-cache=%s' % self.config.download_cache) else: command_line.append('--no-index') command_line.extend([ '--find-links=file://%s' % self.config.source_index, '--build-directory=%s' % self.build_directory, ]) command_line.extend(arguments) logger.info("Executing command: %s", ' '.join(command_line)) # Clear the build directory to prevent PreviousBuildDirError exceptions. self.clear_build_directory() # pip 1.4 has some global state in its command line parser (which we # use) and this can causes problems when we invoke more than one # InstallCommand in the same process. Here's a workaround. requirements_option.default = [] # Parse the command line arguments so we can pass the resulting parser # object to InstallCommand. cmd_name, options, args, parser = parseopts(command_line[1:]) # Initialize our custom InstallCommand. pip = CustomInstallCommand(parser) # Run the `pip install ...' command. exit_status = pip.main(args[1:], options) # Make sure the output of pip and pip-accel are not intermingled. sys.stdout.flush() # If our custom install command intercepted an exception we re-raise it # after the local source index has been updated. if exit_status != SUCCESS: raise pip.intercepted_exception elif pip.requirement_set is None: raise NothingToDoError(""" pip didn't generate a requirement set, most likely you specified an empty requirements file? """) else: return self.transform_pip_requirement_set(pip.requirement_set)
def main(args=None): if args is None: args = sys.argv[1:] try: cmd_name, cmd_args = pip.parseopts(args) except pip.PipError as exc: sys.stderr.write("ERROR: %s" % exc) sys.stderr.write(os.linesep) sys.exit(1) freeze_command = pip.commands_dict[cmd_name] freeze_command.run = run command = pip.commands_dict[cmd_name](isolated=pip.check_isolated(cmd_args)) return command.main(cmd_args)
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 get_pip_requirement_set(self, arguments, use_remote_index): """ Get the unpacked requirement(s) specified by the caller by running pip. :param arguments: The command line arguments to ``pip install ..`` (a list of strings). :param use_remote_index: A boolean indicating whether pip is allowed to connect to the main package index (http://pypi.python.org by default). :returns: A :py:class:`pip.req.RequirementSet` object created by pip. :raises: Any exceptions raised by pip. """ # Compose the pip command line arguments. command_line = ['pip', 'install', '--no-install'] if use_remote_index: command_line.append('--download-cache=%s' % self.config.download_cache) else: command_line.append('--no-index') command_line.extend([ '--find-links=file://%s' % self.config.source_index, '--build-directory=%s' % self.build_directory, ]) command_line.extend(arguments) logger.info("Executing command: %s", ' '.join(command_line)) # Clear the build directory to prevent PreviousBuildDirError exceptions. self.clear_build_directory() # pip 1.4 has some global state in its command line parser (which we # use) and this can causes problems when we invoke more than one # InstallCommand in the same process. Here's a workaround. requirements_option.default = [] # Parse the command line arguments so we can pass the resulting parser # object to InstallCommand. cmd_name, options, args, parser = parseopts(command_line[1:]) # Initialize our custom InstallCommand. pip = CustomInstallCommand(parser) # Run the `pip install ...' command. exit_status = pip.main(args[1:], options) # Make sure the output of pip and pip-accel are not intermingled. sys.stdout.flush() # If our custom install command intercepted an exception we re-raise it # after the local source index has been updated. if exit_status != SUCCESS: raise pip.intercepted_exception return self.transform_pip_requirement_set(pip.requirement_set)
def run_pip(arguments, use_remote_index, build_directory=None): """ Execute a modified ``pip install`` command. This function assumes that the arguments concern a ``pip install`` command (:py:func:`main()` makes sure of this). :param arguments: A list of strings containing the arguments that will be passed to ``pip``. :param use_remote_index: A boolean indicating whether ``pip`` is allowed to contact http://pypi.python.org. :returns: A ``RequirementSet`` object created by ``pip``, unless an exception is raised by ``pip`` (in which case the exception will bubble up). """ command_line = [] for i, arg in enumerate(arguments): if arg == 'install': command_line += ['pip'] + arguments[:i + 1] + [ '--download-cache=%s' % download_cache, '--find-links=file://%s' % source_index ] if build_directory: command_line += ['--build-directory=%s' % build_directory] if not use_remote_index: command_line += ['--no-index'] command_line += arguments[i + 1:] break else: command_line = ['pip'] + arguments logger.info("Executing command: %s", ' '.join(command_line)) # XXX Nasty hack required for pip 1.4 compatibility (workaround for global state). requirements_option.default = [] cmd_name, options, args, parser = parseopts(command_line[1:]) pip = CustomInstallCommand(parser) exit_status = pip.main(args[1:], options) # Make sure the output of pip and pip-accel are not intermingled. sys.stdout.flush() update_source_dists_index() if exit_status == SUCCESS: return pip.requirement_set else: raise pip.intercepted_exception
def run_pip(arguments, use_remote_index, build_directory=None): """ Execute a modified ``pip install`` command. This function assumes that the arguments concern a ``pip install`` command (:py:func:`main()` makes sure of this). :param arguments: A list of strings containing the arguments that will be passed to ``pip``. :param use_remote_index: A boolean indicating whether ``pip`` is allowed to contact http://pypi.python.org. :returns: A ``RequirementSet`` object created by ``pip``, unless an exception is raised by ``pip`` (in which case the exception will bubble up). """ command_line = [] for i, arg in enumerate(arguments): if arg == 'install': command_line += ['pip'] + arguments[:i+1] + [ '--download-cache=%s' % download_cache, '--find-links=file://%s' % source_index] if build_directory: command_line += ['--build-directory=%s' % build_directory] if not use_remote_index: command_line += ['--no-index'] command_line += arguments[i+1:] break else: command_line = ['pip'] + arguments logger.info("Executing command: %s", ' '.join(command_line)) # XXX Nasty hack required for pip 1.4 compatibility (workaround for global state). requirements_option.default = [] cmd_name, options, args, parser = parseopts(command_line[1:]) pip = CustomInstallCommand(parser) exit_status = pip.main(args[1:], options) # Make sure the output of pip and pip-accel are not intermingled. sys.stdout.flush() update_source_dists_index() if exit_status == SUCCESS: return pip.requirement_set else: raise pip.intercepted_exception
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 uninstall(self, package): cmd_name, args = pip.parseopts(['uninstall', '--yes', package]) UninstallCommand().main(args) self.assertFalse(self.is_exists(package))
def pip(self, args): cmd_name, cmd_args = parseopts(args.split()) command = commands_dict[cmd_name](isolated=check_isolated(cmd_args)) rtn = command.main(cmd_args)