Пример #1
0
 def _show_existing_tasks(self):
     """
     A function to display existing tasks.
     """
     warn('No tasks specified.  Available tasks are:', None)
     out()
     self._module_set.print_available_tasks()
     self._rc = 1
Пример #2
0
    def to_local_path(
            self,
            dependency: Dependency,
            name: str,
            signatures: Optional[Dict[str, str]] = None,
            override_resolver: Optional[RemoteResolver] = None
    ) -> Optional[Path]:
        """
        A function that will isolate a path for the given dependency.  If the dependency
        is located remotely, it will be downloaded via the local file cache.  This
        process will include any appropriate signature validation.  If no signature map
        is provided (``signatures`` is ``None``), it is assumed that signature validation
        should use a parallel file of the same name as given but including a signature
        algorithm as the final extension.  To bypass signature processing completely,
        specify an empty map for ``signatures``.

        For remote dependencies to resolve correctly, the ``set_remote_info()`` function
        should have already been called.

        :param dependency: the dependency the file belongs to.
        :param name: the name of the desired file.
        :param signatures: an optional map of signature names to actual signatures.
        :param override_resolver: an optional resolver to override the current remote
        resolver.
        :return: the absolute path to the local file or ``None`` if it doesn't exist.
        """
        set_aside = self._remote_resolver

        if override_resolver:
            self._remote_resolver = override_resolver

        try:
            path = self._fetch_file(dependency, name)
            condition = self._configuration.get_file_condition(name)

            # Handle signature verification, if we need to.
            if not condition.ignore_signature and path and (
                    signatures or signatures is None):
                if not verify_signature(
                        path, signatures,
                        lambda sn: self._fetch_file(dependency, sn)):
                    if condition.warn_on_bad_signature:
                        warn(
                            f'Could not verify the signature of the file {path.name}.'
                        )
                    else:
                        raise ValueError(
                            f'Dependency path:\n{self._resolutions.traceback()}\n'
                            f'Could not verify the signature of the file {path.name}.'
                        )
        finally:
            self._remote_resolver = set_aside

        return path
Пример #3
0
def get_language_module(language: str) -> Optional[Language]:
    """
    A function for loading the support module for a language.  This isn't considered
    fatal since a task error will likely occur.  This gives the end user the most
    information.  Especially since this is most likely to occur when a language is
    added via the ``--language`` command line option.  If a support module cannot
    be loaded, a warning is printed and ``None`` is returned.

    :param language: the language to load the support module for.
    :return: the loaded task module or ``None``.
    """
    try:
        return Language(_import_module(f'builder.{language}'), language)
    except ModuleNotFoundError as exception:
        warn(f'Exception loading module for {language}: {str(exception)}')
        return None
Пример #4
0
    def _handle_version_conflict(self, pending: Dependency,
                                 completed: Dependency) -> bool:
        """
        A function that appropriately handles a version conflict for a dependency.

        :param pending: the current dependency.
        :param completed: the dependency the current one is a near match to.
        :return: ``True`` if the pending dependency should just be skipped or ``False``
        if it should be processed normally.
        """
        pending_version = Version(pending.version)
        completed_version = Version(completed.version)
        conflict = self._configuration.get_conflict(
            pending.id,
            not pending_version.same_major_minor(completed_version))

        if conflict.error_out:
            raise ValueError(
                f'The same library, {pending.id}, is required at two different versions,'
                f' {completed.version} vs. {pending.version}.')

        # If the completed one is the one we want, then we're all good.
        if (conflict.use_newer and completed_version > pending_version) or \
                (conflict.use_older and completed_version < pending_version):
            if conflict.warn:
                warn(
                    f'Favoring {conflict.action} version {completed.version} over {pending.version} of'
                    f' {completed.id}.')
            return True

        if conflict.warn:
            warn(
                f'Favoring {conflict.action} version {pending.version} over {completed.version} of'
                f' {pending.id}.')

        # We need to throw away the completed dependency and allow the pending one to process.
        self._resolutions.abandon(completed)

        return False
Пример #5
0
    def test_warn_out(self):
        with FakeEcho.simple('Warning: testing', fg='yellow') as fe:
            warn('testing')
        assert fe.was_called()

        with FakeEcho.simple('ERROR: testing', fg='yellow') as fe:
            warn('testing', label='ERROR')
        assert fe.was_called()

        with Options(quiet=True):
            with FakeEcho.simple('Warning: testing', fg='yellow') as fe:
                warn('testing')
            assert fe.was_called()