예제 #1
0
    def get_version(self, lines, filename):
        # we will try to find python3+ as well as python2+

        # currently regex will probably find a single string "lib/python3.6"
        # where 3.6 is the version similarly "lib/python2.7" where 2.7 is the version
        version_info = super().get_version(lines, filename)

        # we will check if the guess returned some version probably 3.6 or 2.7 in our example
        # return version_info
        if "version" in version_info and version_info["version"] != "UNKNOWN":

            # we will update our regex to something more precise 3.6.d
            # where d is unknown and we will find d. which will return 3.6.9 or some other version
            version_pattern = [
                rf"([{version_info['version'][0]}]+\.[{version_info['version'][2]}]+\.[0-9])"
            ]
            version_regex = list(map(re.compile, version_pattern))
            new_version = regex_find(lines, version_regex)

            # we will return this result
            version_info["version"] = new_version

        # else guess was unknown so we update our regex
        elif version_info:
            version_pattern = [
                r"Version: ([23]+\.[0-9]+\.[0-9])+",
                r"version: ([23]+\.[0-9]+\.[0-9])+",
                r"Python ([23]+\.[0-9]+\.[0-9])+",
            ]
            version_regex = list(map(re.compile, version_pattern))
            new_version = regex_find(lines, version_regex)

            version_info["version"] = new_version
        return version_info
예제 #2
0
    def get_version(self, lines, filename):
        version_info = dict()

        if any(pattern.search(filename) for pattern in self.FILENAME_PATTERNS):
            version_info["is_or_contains"] = "is"

        if "is_or_contains" not in version_info and self.guess_contains(lines):
            version_info["is_or_contains"] = "contains"

        if "is_or_contains" in version_info:
            version_info["version"] = regex_find(lines, self.VERSION_PATTERNS)

        return version_info