def main(initial_args=None): if initial_args is None: initial_args = sys.argv[1:] autocomplete() version_control() options, args = parser.parse_args(initial_args) if options.help and not args: args = ['help'] if not args: parser.error( 'You must give a command (use "pip help" to see a list of commands)' ) command = args[0].lower() load_command(command) if command not in command_dict: close_commands = difflib.get_close_matches(command, command_names()) if close_commands: guess = close_commands[0] if args[1:]: guess = "%s %s" % (guess, " ".join(args[1:])) else: guess = 'install %s' % command error_dict = { 'arg': command, 'guess': guess, 'script': os.path.basename(sys.argv[0]) } parser.error('No command by the name %(script)s %(arg)s\n ' '(maybe you meant "%(script)s %(guess)s")' % error_dict) command = command_dict[command] return command.main(args[1:], options)
def main(initial_args=None): if initial_args is None: initial_args = sys.argv[1:] autocomplete() version_control() options, args = parser.parse_args(initial_args) if options.help and not args: args = ['help'] if not args: parser.error('You must give a command (use "pip help" to see a list of commands)') command = args[0].lower() load_command(command) if command not in command_dict: close_commands = difflib.get_close_matches(command, command_names()) if close_commands: guess = close_commands[0] if args[1:]: guess = "{0!s} {1!s}".format(guess, " ".join(args[1:])) else: guess = 'install {0!s}'.format(command) error_dict = {'arg': command, 'guess': guess, 'script': os.path.basename(sys.argv[0])} parser.error('No command by the name %(script)s %(arg)s\n ' '(maybe you meant "%(script)s %(guess)s")' % error_dict) command = command_dict[command] return command.main(initial_args, args[1:], options)
def main(initial_args=None): if initial_args is None: initial_args = sys.argv[1:] autocomplete() options, args = parser.parse_args(initial_args) if options.help and not args: args = ["help"] if not args: parser.error("You must give a command " '(use "%s help" to see a list of commands)' % get_prog()) command = args[0].lower() load_command(command) if command not in command_dict: close_commands = difflib.get_close_matches(command, command_names()) if close_commands: guess = close_commands[0] if args[1:]: guess = "%s %s" % (guess, " ".join(args[1:])) else: guess = "install %s" % command error_dict = {"arg": command, "guess": guess, "script": os.path.basename(sys.argv[0])} parser.error( "No command by the name %(script)s %(arg)s\n " '(maybe you meant "%(script)s %(guess)s")' % error_dict ) command = command_dict[command] return command.main(args[1:], options)
def main(initial_args=None): if initial_args is None: initial_args = sys.argv[1:] autocomplete() options, args = parser.parse_args(initial_args) if options.help and not args: args = ['help'] if not args: parser.error('You must give a command (use "pip help" see a list of commands)') command = args[0].lower() load_command(command) ## FIXME: search for a command match? if command not in command_dict: parser.error('No command by the name %(script)s %(arg)s\n (maybe you meant "%(script)s install %(arg)s")' % dict(script=os.path.basename(sys.argv[0]), arg=command)) command = command_dict[command] return command.main(initial_args, args[1:], options)
def bundle_package(self, cache=True): """Makes the pybundle archive (that :program:`pip` can take to install) with completely resolved dependencies. It yields triple of package name, filename of the pybundle archive, and its full path. :: with build.bundle_package() as (package, filename, path): sftp.put(path, filename) :param cache: whether to cache the package file or not. ``True`` by default :type cache: :class:`bool` """ asuka_logger = self.get_logger('bundle_package') # Makes pip.log.logger to forward records to the standard logging if not getattr(type(self), 'initialized', False): type(self).initialized = True logger.consumers.extend([ (Logger.FATAL, asuka_logger.critical), (Logger.ERROR, asuka_logger.error), (Logger.WARN, asuka_logger.warn), (Logger.NOTIFY, asuka_logger.info), (Logger.INFO, asuka_logger.info), (Logger.DEBUG, asuka_logger.debug), (Logger.VERBOSE_DEBUG, asuka_logger.debug) ]) vcs.register(Git) load_command('bundle') bundle = command_dict['bundle'] with self.archive_package() as (package_name, filename, filepath): if cache: cache_dir_path = os.path.join( tempfile.gettempdir(), 'asuka-pybundle-cache' ) if not os.path.isdir(cache_dir_path): os.makedirs(cache_dir_path) cache_path = os.path.join(cache_dir_path, filename) if os.path.isfile(cache_path): asuka_logger.info('cache exists: %s, skipping pybundle...', cache_path) yield package_name, filename, cache_path return tempdir = tempfile.gettempdir() bundle_path = os.path.join( os.path.dirname(filepath), package_name + '.pybundle' ) asuka_logger.info('pybundle_path = %r', bundle_path) options = optparse.Values() options.editables = [] options.requirements = [] options.find_links = [] options.index_url = PYPI_INDEX_URLS[0] options.extra_index_urls = PYPI_INDEX_URLS[1:] options.no_index = False options.use_mirrors = False options.mirrors = True options.build_dir = os.path.join( tempdir, 'asuka-dist-build-bundle' ) options.target_dir = None options.download_dir = None options.download_cache = os.path.join( tempdir, 'asuka-dist-download-cache' ) options.src_dir = backup_dir(src_prefix, '-bundle') options.upgrade = False options.force_reinstall = False options.ignore_dependencies = False options.no_install = True options.no_download = False options.install_options = [] options.global_options = [] options.use_user_site = False options.as_egg = False asuka_logger.debug('start: pip bundle %s %s', bundle_path, filepath) retrial = 0 while 1: try: shutil.rmtree(options.build_dir) except (OSError, IOError): pass try: bundle.run(options, [bundle_path, filepath]) except PipError as e: asuka_logger.exception(e) retrial += 1 if retrial < 3: asuka_logger.error( 'retry pip bundle after %d second(s)... (%d)', retrial, retrial ** 2 ) options.index_url = PYPI_INDEX_URLS[retrial] options.extra_index_urls = PYPI_INDEX_URLS[retrial+1:] time.sleep(retrial ** 2) continue raise finally: shutil.rmtree(options.build_dir) break asuka_logger.debug('end: pip bundle %s %s', bundle_path, filepath) if cache: asuka_logger.info('save pybundle cache %s...', cache_path) shutil.copyfile(filepath, cache_path) yield package_name, os.path.basename(bundle_path), bundle_path