def get_report(self) -> str:
        """Get verbose report.

        :return: Report why the part is dirty.
        :rtype: str
        """
        messages = []  # type: List[str]

        if self.dirty_properties:
            humanized_properties = formatting_utils.humanize_list(
                self.dirty_properties, "and")
            pluralized_connection = formatting_utils.pluralize(
                self.dirty_properties, "property appears", "properties appear")
            messages.append("The {} part {} to have changed.\n".format(
                humanized_properties, pluralized_connection))

        if self.dirty_project_options:
            humanized_options = formatting_utils.humanize_list(
                self.dirty_project_options, "and")
            pluralized_connection = formatting_utils.pluralize(
                self.dirty_project_options, "option appears", "options appear")
            messages.append("The {} project {} to have changed.\n".format(
                humanized_options, pluralized_connection))

        if self.changed_dependencies:
            dependencies = [d.part_name for d in self.changed_dependencies]
            messages.append("{} changed: {}\n".format(
                formatting_utils.pluralize(dependencies, "A dependency has",
                                           "Some dependencies have"),
                formatting_utils.humanize_list(dependencies, "and"),
            ))

        return "".join(messages)
Exemple #2
0
 def __init__(self, *, base: str, version: str,
              valid_versions: Sequence[str]) -> None:
     super().__init__(
         base=base,
         version=version,
         valid_versions=formatting_utils.humanize_list(valid_versions,
                                                       conjunction="or"),
     )
Exemple #3
0
def _determine_cause(error):
    messages = []

    # error.validator_value may contain a custom validation error message.
    # If so, use it instead of the garbage message jsonschema gives us.
    with contextlib.suppress(TypeError, KeyError):
        messages.append(
            error.validator_value["validation-failure"].format(error))

    # The schema itself may have a custom validation error message. If so,
    # use it as well.
    with contextlib.suppress(AttributeError, TypeError, KeyError):
        key = error
        if (error.schema.get("type") == "object"
                and error.validator == "additionalProperties"):
            key = list(error.instance.keys())[0]

        messages.append(error.schema["validation-failure"].format(key))

    # anyOf failures might have usable context... try to improve them a bit
    if error.validator == "anyOf":
        contextual_messages: Dict[str, str] = collections.OrderedDict()
        for contextual_error in error.context:
            key = contextual_error.schema_path.popleft()
            if key not in contextual_messages:
                contextual_messages[key] = []
            message = contextual_error.message
            if message:
                # Sure it starts lower-case (not all messages do)
                contextual_messages[key].append(message[0].lower() +
                                                message[1:])

        oneOf_messages: List[str] = []
        for key, value in contextual_messages.items():
            oneOf_messages.append(
                formatting_utils.humanize_list(value, "and", "{}"))

        messages.append(
            formatting_utils.humanize_list(oneOf_messages, "or", "{}"))

    return " ".join(messages)
    def get_summary(self) -> str:
        """Get summarized report.

        :return: Short summary of why the step is dirty.
        :rtype: str
        """
        reasons = []

        if self.previous_step_modified:
            reasons.append("{!r} step".format(
                self.previous_step_modified.name))

        if self.source_updated:
            reasons.append("source")

        return "{} changed".format(
            formatting_utils.humanize_list(reasons, "and", "{}"))
    def summary(self) -> str:
        """Get summarized report.

        :return: Short summary of why the part is dirty.
        :rtype: str
        """
        reasons = []

        reasons_count = 0
        if self.dirty_properties:
            reasons_count += 1
        if self.dirty_project_options:
            reasons_count += 1
        if self.changed_dependencies:
            reasons_count += 1

        if self.dirty_properties:
            # Be specific only if this is the only reason
            if reasons_count > 1 or len(self.dirty_properties) > 1:
                reasons.append("properties")
            else:
                reasons.append("{!r} property".format(
                    next(iter(self.dirty_properties))))

        if self.dirty_project_options:
            # Be specific only if this is the only reason
            if reasons_count > 1 or len(self.dirty_project_options) > 1:
                reasons.append("options")
            else:
                reasons.append("{!r} option".format(
                    next(iter(self.dirty_project_options))))

        if self.changed_dependencies:
            # Be specific only if this is the only reason
            if reasons_count > 1 or len(self.changed_dependencies) > 1:
                reasons.append("dependencies")
            else:
                reasons.append("{!r}".format(
                    next(iter(self.changed_dependencies)).part_name))

        return "{} changed".format(
            formatting_utils.humanize_list(reasons, "and", "{}"))
Exemple #6
0
def _clean_parts(part_names, step, config, staged_state, primed_state):
    if not step:
        step = steps.next_step(None)

    for part_name in part_names:
        dirty_parts = _clean_part(part_name, step, config, staged_state,
                                  primed_state)
        dirty_part_names = {p.name for p in dirty_parts}

        parts_not_being_cleaned = dirty_part_names.difference(part_names)
        if parts_not_being_cleaned:
            logger.warning(
                "Cleaned {!r}, which makes the following {} out of date: "
                "{}".format(
                    part_name,
                    formatting_utils.pluralize(parts_not_being_cleaned, "part",
                                               "parts"),
                    formatting_utils.humanize_list(parts_not_being_cleaned,
                                                   "and"),
                ))
 def __init__(self, *, architecture: str, supported: List[str]) -> None:
     super().__init__(
         architecture=architecture,
         supported=formatting_utils.humanize_list(supported, "and"),
     )
 def __init__(self, source_type: str, options: List[str]) -> None:
     self.options = options
     super().__init__(
         source_type=source_type,
         humanized_options=formatting_utils.humanize_list(options, "and"),
     )