Beispiel #1
0
    def retrieve_package_name(path):
        """Retrieve the package name from the conda package path."""
        path = os.path.basename(path)
        seq = get_bad_seq(path)
        if seq:
            raise PackageError(u'Found invalid sequence "{}" in package in info/index.json' .format(seq))

        if path.endswith('.tar.bz2'):
            return path[:-8]
        elif path.endswith('.tar'):
            return path[:-4]
        else:
            raise PackageError('Found package with invalid extension "{}"' .format(os.path.splitext(path)[1]))
Beispiel #2
0
    def verify_package(path_to_package=None,
                       checks_to_ignore=None,
                       exit_on_error=False,
                       **kw):
        """Run all package checks in order to verify a conda package.
        checks_to_ignore should be a list, tuple, or set of codes, such as ['C1102', 'C1104'].
        Codes are listed in readme.md.  Package codes follow 1xxx, recipe codes follow 2xxx."""
        package_check = CondaPackageCheck(path_to_package)

        if (('ignore_scripts' in kw and kw['ignore_scripts'])
                or ('run_scripts' in kw and kw['run_scripts'])):
            getLogger(__name__).warn(
                'Ignoring legacy ignore_scripts or run_scripts.  These have '
                'been replaced by the checks_to_ignore argument, which takes a'
                'list of codes, documented at https://github.com/conda/conda-verify#checks'
            )

        # collect all CondaPackageCheck methods that start with the word 'check'
        # this should later be a decorator that is placed on each check
        checks_to_display = []
        for method in dir(package_check):
            if method.startswith('check'):
                # runs the check
                #  TODO: should have a way to skip checks if a check's codes are all ignored
                check = getattr(package_check, method)()
                if check is not None and check.code not in ensure_list(
                        checks_to_ignore):
                    checks_to_display.append(check)

        if checks_to_display:
            print("Package verification results:")
            print("-----------------------------")
        for check in sorted(checks_to_display):
            try:
                print(check, file=sys.stderr)
            except UnicodeEncodeError:
                print(
                    "Could not print message for error code {} due to unicode error"
                    .format(check.code),
                    file=sys.stderr)

        if checks_to_display and exit_on_error:
            raise PackageError(check)
Beispiel #3
0
    def verify_package(path_to_package=None,
                       checks_to_ignore=None,
                       exit_on_error=False,
                       **kw):
        """Run all package checks in order to verify a conda package."""
        package_check = CondaPackageCheck(path_to_package)

        if (('ignore_scripts' in kw and kw['ignore_scripts'])
                or ('run_scripts' in kw and kw['run_scripts'])):
            getLogger(__name__).warn(
                'Ignoring legacy ignore_scripts or run_scripts.  These have '
                'been replaced by the checks_to_ignore argument, which takes a'
                'list of codes, documented at https://github.com/conda/conda-verify#checks'
            )

        # collect all CondaPackageCheck methods that start with the word 'check'
        # this should later be a decorator that is placed on each check
        checks_to_display = [
            getattr(package_check, method)() for method in dir(package_check)
            if method.startswith('check') and getattr(package_check, method)
            () is not None
        ]

        return_code = 0

        if len(checks_to_display) > 0:
            for check in sorted(checks_to_display):
                if check.code not in ensure_list(checks_to_ignore):
                    check = u'{}'.format(check)
                    if exit_on_error:
                        raise PackageError(check)
                    else:
                        print(check, file=sys.stderr)

                    return_code = 1

        # by exiting at a return code greater than 0 we can assure failures
        # in logs or continuous integration services
        if return_code > 0:
            sys.exit(return_code)
Beispiel #4
0
    def verify_package(path_to_package=None,
                       checks_to_ignore=None,
                       exit_on_error=False,
                       **kw):
        """Run all package checks in order to verify a conda package.
        checks_to_ignore should be a list, tuple, or set of codes, such as ['C1102', 'C1104'].
        Codes are listed in readme.md.  Package codes follow 1xxx, recipe codes follow 2xxx."""
        package_check = CondaPackageCheck(path_to_package)

        if ("ignore_scripts" in kw
                and kw["ignore_scripts"]) or ("run_scripts" in kw
                                              and kw["run_scripts"]):
            getLogger(__name__).warn(
                "Ignoring legacy ignore_scripts or run_scripts.  These have "
                "been replaced by the checks_to_ignore argument, which takes a"
                "list of codes, documented at https://github.com/conda/conda-verify#checks"
            )

        # collect all CondaPackageCheck methods that start with the word 'check'
        # this should later be a decorator that is placed on each check
        checks_to_display = []
        for method in dir(package_check):
            if method.startswith("check"):
                # runs the check
                #  TODO: should have a way to skip checks if a check's codes are all ignored
                check = getattr(package_check, method)()
                if check is not None and check.code not in ensure_list(
                        checks_to_ignore):
                    checks_to_display.append(check)

        if checks_to_display and exit_on_error:
            raise PackageError(check)
        return (
            path_to_package,
            sorted(["[{}] {}".format(*c[1:]) for c in checks_to_display]),
        )