Ejemplo n.º 1
0
    def _update_defaults(self, defaults):
        """Updates the given defaults with values from the config files and
        the environ. Does a little special handling for certain types of
        options (lists)."""

        # Accumulate complex default state.
        self.values = optparse.Values(self.defaults)
        late_eval = set()
        # Then set the options with those values
        for key, val in self._get_ordered_configuration_items():
            # '--' because configuration supports only long names
            option = self.get_option("--" + key)

            # Ignore options not present in this parser. E.g. non-globals put
            # in [global] by users that want them to apply to all applicable
            # commands.
            if option is None:
                continue

            if option.action in ("store_true", "store_false"):
                try:
                    val = strtobool(val)
                except ValueError:
                    self.error(
                        "{} is not a valid value for {} option, "  # noqa
                        "please specify a boolean value like yes/no, "
                        "true/false or 1/0 instead.".format(val, key)
                    )
            elif option.action == "count":
                with suppress(ValueError):
                    val = strtobool(val)
                with suppress(ValueError):
                    val = int(val)
                if not isinstance(val, int) or val < 0:
                    self.error(
                        "{} is not a valid value for {} option, "  # noqa
                        "please instead specify either a non-negative integer "
                        "or a boolean value like yes/no or false/true "
                        "which is equivalent to 1/0.".format(val, key)
                    )
            elif option.action == "append":
                val = val.split()
                val = [self.check_default(option, key, v) for v in val]
            elif option.action == "callback":
                late_eval.add(option.dest)
                opt_str = option.get_opt_string()
                val = option.convert_value(opt_str, val)
                # From take_action
                args = option.callback_args or ()
                kwargs = option.callback_kwargs or {}
                option.callback(option, opt_str, val, self, *args, **kwargs)
            else:
                val = self.check_default(option, key, val)

            defaults[option.dest] = val

        for key in late_eval:
            defaults[key] = getattr(self.values, key)
        self.values = None
        return defaults
Ejemplo n.º 2
0
 def _fetch_metadata(preparer, link):
     # type: (Link) -> Optional[Distribution]
     """Fetch metadata, using lazy wheel if possible."""
     use_lazy_wheel = preparer.use_lazy_wheel
     remote_wheel = link.is_wheel and not link.is_file
     if use_lazy_wheel and remote_wheel and not preparer.require_hashes:
         wheel = Wheel(link.filename)
         name = canonicalize_name(wheel.name)
         # If HTTPRangeRequestUnsupported is raised, fallback silently.
         with indent_log(), suppress(HTTPRangeRequestUnsupported):
             logger.info(
                 'Obtaining dependency information from %s %s',
                 name, wheel.version,
             )
             url = link.url.split('#', 1)[0]
             session = preparer.downloader._session
             return dist_from_wheel_url(name, url, session)
     return None
Ejemplo n.º 3
0
 def _fetch_metadata(self):
     # type: () -> None
     """Fetch metadata, using lazy wheel if possible."""
     preparer = self._factory.preparer
     use_lazy_wheel = self._factory.use_lazy_wheel
     remote_wheel = self._link.is_wheel and not self._link.is_file
     if use_lazy_wheel and remote_wheel and not preparer.require_hashes:
         assert self._name is not None
         logger.info('Collecting %s', self._ireq.req or self._ireq)
         # If HTTPRangeRequestUnsupported is raised, fallback silently.
         with indent_log(), suppress(HTTPRangeRequestUnsupported):
             logger.info(
                 'Obtaining dependency information from %s %s',
                 self._name, self._version,
             )
             url = self._link.url.split('#', 1)[0]
             session = preparer.downloader._session
             self._dist = dist_from_wheel_url(self._name, url, session)
             self._check_metadata_consistency()
     if self._dist is None:
         self._prepare()