示例#1
0
    def check_source(self):
        """Check the source field in meta.yaml for proper formatting."""
        sources = ensure_list(self.meta.get('source', {}))
        for source in sources:
            url = source.get('url')
            if url is not None:
                if self.url_pat.match(url):

                    for hash_algorithm in ['md5', 'sha1', 'sha256']:
                        hexdigest = source.get(hash_algorithm)
                        if hexdigest is not None and not self.hash_pat[
                                hash_algorithm].match(hexdigest):
                            return Error(
                                self.recipe_dir, 'C2119',
                                u'Found invalid hash "{}" in meta.yaml'.format(
                                    hexdigest))

                else:
                    return Error(
                        self.recipe_dir, 'C2120',
                        u'Found invalid URL "{}" in meta.yaml'.format(url))

            git_url = source.get('git_url')
            if git_url and (source.get('git_tag')
                            and source.get('git_branch')):
                return Error(
                    self.recipe_dir, 'C2121',
                    'Found both git_branch and git_tag in meta.yaml source field'
                )
示例#2
0
    def verify_recipe(rendered_meta=None,
                      recipe_dir=None,
                      checks_to_ignore=None,
                      exit_on_error=False,
                      **kw):
        """Run all recipe checks in order to verify a conda recipe.
        checks_to_ignore should be a list, tuple, or set of codes, such as ['C2102', 'C2104'].
        Codes are listed in readme.md.  Package codes follow 1xxx, recipe codes follow 2xxx."""
        recipe_check = CondaRecipeCheck(rendered_meta, recipe_dir)

        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'
            )

        checks_to_display = []
        for method in dir(recipe_check):
            if method.startswith('check'):
                check = getattr(recipe_check, method)()
                if check is not None and check.code not in ensure_list(
                        checks_to_ignore):
                    checks_to_display.append(check)

        for check in sorted(checks_to_display):
            try:
                print(check, file=sys.stderr)
            except UnicodeEncodeError:
                print(str(check).encode('utf-8', 'ignore'), file=sys.stderr)

        if checks_to_display and exit_on_error:
            raise RecipeError(check)
示例#3
0
    def verify_recipe(rendered_meta=None,
                      recipe_dir=None,
                      checks_to_ignore=None,
                      exit_on_error=False,
                      **kw):
        """Run all recipe checks in order to verify a conda recipe.
        checks_to_ignore should be a list, tuple, or set of codes, such as ['C2102', 'C2104'].
        Codes are listed in readme.md.  Package codes follow 1xxx, recipe codes follow 2xxx."""
        recipe_check = CondaRecipeCheck(rendered_meta, recipe_dir)

        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"
            )

        checks_to_display = []
        for method in (_ for _ in dir(recipe_check) if _.startswith("check_")):
            check = getattr(recipe_check, method)()
            if check and check.code not in ensure_list(checks_to_ignore):
                checks_to_display.append(check)

        if checks_to_display and exit_on_error:
            raise RecipeError(checks_to_display[0])
        return (
            recipe_dir,
            sorted(["[{}] {}".format(*c[1:]) for c in checks_to_display]),
        )
示例#4
0
    def check_for_valid_files(self):
        """Check that the files listed in meta.yaml exist."""
        test_files = self.meta.get("test", {}).get("files", [])
        test_source_files = self.meta.get("test", {}).get("source_files", [])
        sources = ensure_list(self.meta.get("source", {}))
        source_patches = []
        for source in sources:
            source_patches.extend(source.get("patches", []))

        for filename in test_files + test_source_files + source_patches:
            filepath = os.path.join(self.recipe_dir, filename)
            if filename.startswith(".."):
                return Error(
                    self.recipe_dir,
                    "C2123",
                    u'Found file "{}" listed outside recipe directory'.format(
                        filename),
                )

            if not os.path.exists(filepath):
                return Error(
                    self.recipe_dir,
                    "C2124",
                    u'Found file "{}" in meta.yaml that doesn\'t exist'.format(
                        filename),
                )
示例#5
0
    def check_source(self):
        """Check the source field in meta.yaml for proper formatting."""
        sources = ensure_list(self.meta.get("source", {}))
        for source in sources:
            url = source.get("url")
            if url is not None:
                if self.url_pat.match(url):

                    for hash_algorithm in ["md5", "sha1", "sha256"]:
                        hexdigest = source.get(hash_algorithm)
                        if hexdigest is not None and not self.hash_pat[
                                hash_algorithm].match(hexdigest):
                            return Error(
                                self.recipe_dir,
                                "C2119",
                                u'Found invalid hash "{}" in meta.yaml'.format(
                                    hexdigest),
                            )

                else:
                    return Error(
                        self.recipe_dir,
                        "C2120",
                        u'Found invalid URL "{}" in meta.yaml'.format(url),
                    )

            git_url = source.get("git_url")
            if git_url and (source.get("git_tag")
                            and source.get("git_branch")):
                return Error(
                    self.recipe_dir,
                    "C2121",
                    "Found both git_branch and git_tag in meta.yaml source field",
                )
示例#6
0
 def check_index_dependencies_specs(self):
     """Check that the dependencies in info/index.json are properly formatted."""
     dependencies = ensure_list(self.info.get('depends'))
     if dependencies != [None]:
         for dependency in dependencies:
             dependency_parts = dependency.split()
             if len(dependency_parts) == 0:
                 return Error(self.path, 'C1113', 'Found empty dependencies in info/index.json')
             elif len(dependency_parts) == 2 and not self.ver_spec_pat.match(dependency_parts[1]) or len(dependency_parts) > 3:
                 return Error(self.path, 'C1114', 'Found invalid dependency "{}" in info/index.json' .format(dependency))
示例#7
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)
示例#8
0
    def verify_recipe(rendered_meta=None,
                      recipe_dir=None,
                      checks_to_ignore=None,
                      exit_on_error=False,
                      **kw):
        """Run all recipe checks in order to verify a conda recipe.
        checks_to_ignore should be a list, tuple, or set of codes, such as ['C2102', 'C2104'].
        Codes are listed in readme.md"""
        recipe_check = CondaRecipeCheck(rendered_meta, recipe_dir)

        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 CondaRecipeCheck methods that start with the word 'check'
        # this should later be a decorator that is placed on each check
        checks_to_display = [
            getattr(recipe_check, method)() for method in dir(recipe_check)
            if method.startswith('check') and getattr(recipe_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):
                    if exit_on_error:
                        raise RecipeError(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)
示例#9
0
 def check_index_dependencies_specs(self):
     """Check that the dependencies in info/index.json are properly formatted."""
     dependencies = ensure_list(self.info.get("depends"))
     if dependencies != [None]:
         for dependency in dependencies:
             dependency_parts = dependency.split()
             if len(dependency_parts) == 0:
                 return Error(
                     self.path,
                     "C1113",
                     "Found empty dependencies in info/index.json",
                 )
             elif (len(dependency_parts) == 2
                   and not fullmatch(ver_spec_pat, dependency_parts[1])
                   or len(dependency_parts) > 3):
                 return Error(
                     self.path,
                     "C1114",
                     'Found invalid dependency "{}" in info/index.json'.
                     format(dependency),
                 )
示例#10
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)
示例#11
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]),
        )