Code Duplication    Length = 53-53 lines in 2 locations

versioneer.py 1 location

@@ 973-1025 (lines=53) @@
970
    return keywords
971
972
973
@register_vcs_handler("git", "keywords")
974
def git_versions_from_keywords(keywords, tag_prefix, verbose):
975
    """Get version information from git keywords."""
976
    if not keywords:
977
        raise NotThisMethod("no keywords at all, weird")
978
    date = keywords.get("date")
979
    if date is not None:
980
        # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
981
        # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
982
        # -like" string, which we must then edit to make compliant), because
983
        # it's been around since git-1.5.3, and it's too difficult to
984
        # discover which version we're using, or to work around using an
985
        # older one.
986
        date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
987
    refnames = keywords["refnames"].strip()
988
    if refnames.startswith("$Format"):
989
        if verbose:
990
            print("keywords are unexpanded, not using")
991
        raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
992
    refs = set([r.strip() for r in refnames.strip("()").split(",")])
993
    # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
994
    # just "foo-1.0". If we see a "tag: " prefix, prefer those.
995
    TAG = "tag: "
996
    tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
997
    if not tags:
998
        # Either we're using git < 1.8.3, or there really are no tags. We use
999
        # a heuristic: assume all version tags have a digit. The old git %d
1000
        # expansion behaves like git log --decorate=short and strips out the
1001
        # refs/heads/ and refs/tags/ prefixes that would let us distinguish
1002
        # between branches and tags. By ignoring refnames without digits, we
1003
        # filter out many common branch names like "release" and
1004
        # "stabilization", as well as "HEAD" and "master".
1005
        tags = set([r for r in refs if re.search(r'\d', r)])
1006
        if verbose:
1007
            print("discarding '%s', no digits" % ",".join(refs - tags))
1008
    if verbose:
1009
        print("likely tags: %s" % ",".join(sorted(tags)))
1010
    for ref in sorted(tags):
1011
        # sorting will prefer e.g. "2.0" over "2.0rc1"
1012
        if ref.startswith(tag_prefix):
1013
            r = ref[len(tag_prefix):]
1014
            if verbose:
1015
                print("picking %s" % r)
1016
            return {"version": r,
1017
                    "full-revisionid": keywords["full"].strip(),
1018
                    "dirty": False, "error": None,
1019
                    "date": date}
1020
    # no suitable tags, so version is "0+unknown", but full hex is still there
1021
    if verbose:
1022
        print("no suitable tags, using unknown + full revision id")
1023
    return {"version": "0+unknown",
1024
            "full-revisionid": keywords["full"].strip(),
1025
            "dirty": False, "error": "no suitable tags", "date": None}
1026
1027
1028
@register_vcs_handler("git", "pieces_from_vcs")

loghub/_version.py 1 location

@@ 161-213 (lines=53) @@
158
            if line.strip().startswith("git_full ="):
159
                mo = re.search(r'=\s*"(.*)"', line)
160
                if mo:
161
                    keywords["full"] = mo.group(1)
162
            if line.strip().startswith("git_date ="):
163
                mo = re.search(r'=\s*"(.*)"', line)
164
                if mo:
165
                    keywords["date"] = mo.group(1)
166
        f.close()
167
    except EnvironmentError:
168
        pass
169
    return keywords
170
171
172
@register_vcs_handler("git", "keywords")
173
def git_versions_from_keywords(keywords, tag_prefix, verbose):
174
    """Get version information from git keywords."""
175
    if not keywords:
176
        raise NotThisMethod("no keywords at all, weird")
177
    date = keywords.get("date")
178
    if date is not None:
179
        # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
180
        # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
181
        # -like" string, which we must then edit to make compliant), because
182
        # it's been around since git-1.5.3, and it's too difficult to
183
        # discover which version we're using, or to work around using an
184
        # older one.
185
        date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
186
    refnames = keywords["refnames"].strip()
187
    if refnames.startswith("$Format"):
188
        if verbose:
189
            print("keywords are unexpanded, not using")
190
        raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
191
    refs = set([r.strip() for r in refnames.strip("()").split(",")])
192
    # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
193
    # just "foo-1.0". If we see a "tag: " prefix, prefer those.
194
    TAG = "tag: "
195
    tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
196
    if not tags:
197
        # Either we're using git < 1.8.3, or there really are no tags. We use
198
        # a heuristic: assume all version tags have a digit. The old git %d
199
        # expansion behaves like git log --decorate=short and strips out the
200
        # refs/heads/ and refs/tags/ prefixes that would let us distinguish
201
        # between branches and tags. By ignoring refnames without digits, we
202
        # filter out many common branch names like "release" and
203
        # "stabilization", as well as "HEAD" and "master".
204
        tags = set([r for r in refs if re.search(r'\d', r)])
205
        if verbose:
206
            print("discarding '%s', no digits" % ",".join(refs - tags))
207
    if verbose:
208
        print("likely tags: %s" % ",".join(sorted(tags)))
209
    for ref in sorted(tags):
210
        # sorting will prefer e.g. "2.0" over "2.0rc1"
211
        if ref.startswith(tag_prefix):
212
            r = ref[len(tag_prefix):]
213
            if verbose:
214
                print("picking %s" % r)
215
            return {
216
                "version": r,