Code Duplication    Length = 53-53 lines in 2 locations

versioneer.py 1 location

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

metpy/_version.py 1 location

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