Code Duplication    Length = 90-90 lines in 2 locations

versioneer.py 1 location

@@ 1028-1117 (lines=90) @@
1025
            "dirty": False, "error": "no suitable tags", "date": None}
1026
1027
1028
@register_vcs_handler("git", "pieces_from_vcs")
1029
def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
1030
    """Get version from 'git describe' in the root of the source tree.
1031
1032
    This only gets called if the git-archive 'subst' keywords were *not*
1033
    expanded, and _version.py hasn't already been rewritten with a short
1034
    version string, meaning we're inside a checked out source tree.
1035
    """
1036
    GITS = ["git"]
1037
    if sys.platform == "win32":
1038
        GITS = ["git.cmd", "git.exe"]
1039
1040
    out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root,
1041
                          hide_stderr=True)
1042
    if rc != 0:
1043
        if verbose:
1044
            print("Directory %s not under git control" % root)
1045
        raise NotThisMethod("'git rev-parse --git-dir' returned error")
1046
1047
    # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
1048
    # if there isn't one, this yields HEX[-dirty] (no NUM)
1049
    describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty",
1050
                                          "--always", "--long",
1051
                                          "--match", "%s*" % tag_prefix],
1052
                                   cwd=root)
1053
    # --long was added in git-1.5.5
1054
    if describe_out is None:
1055
        raise NotThisMethod("'git describe' failed")
1056
    describe_out = describe_out.strip()
1057
    full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
1058
    if full_out is None:
1059
        raise NotThisMethod("'git rev-parse' failed")
1060
    full_out = full_out.strip()
1061
1062
    pieces = {}
1063
    pieces["long"] = full_out
1064
    pieces["short"] = full_out[:7]  # maybe improved later
1065
    pieces["error"] = None
1066
1067
    # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
1068
    # TAG might have hyphens.
1069
    git_describe = describe_out
1070
1071
    # look for -dirty suffix
1072
    dirty = git_describe.endswith("-dirty")
1073
    pieces["dirty"] = dirty
1074
    if dirty:
1075
        git_describe = git_describe[:git_describe.rindex("-dirty")]
1076
1077
    # now we have TAG-NUM-gHEX or HEX
1078
1079
    if "-" in git_describe:
1080
        # TAG-NUM-gHEX
1081
        mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
1082
        if not mo:
1083
            # unparseable. Maybe git-describe is misbehaving?
1084
            pieces["error"] = ("unable to parse git-describe output: '%s'"
1085
                               % describe_out)
1086
            return pieces
1087
1088
        # tag
1089
        full_tag = mo.group(1)
1090
        if not full_tag.startswith(tag_prefix):
1091
            if verbose:
1092
                fmt = "tag '%s' doesn't start with prefix '%s'"
1093
                print(fmt % (full_tag, tag_prefix))
1094
            pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
1095
                               % (full_tag, tag_prefix))
1096
            return pieces
1097
        pieces["closest-tag"] = full_tag[len(tag_prefix):]
1098
1099
        # distance: number of commits since tag
1100
        pieces["distance"] = int(mo.group(2))
1101
1102
        # commit: short hex revision ID
1103
        pieces["short"] = mo.group(3)
1104
1105
    else:
1106
        # HEX: no tags
1107
        pieces["closest-tag"] = None
1108
        count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
1109
                                    cwd=root)
1110
        pieces["distance"] = int(count_out)  # total number of commits
1111
1112
    # commit date: see ISO-8601 comment in git_versions_from_keywords()
1113
    date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
1114
                       cwd=root)[0].strip()
1115
    pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
1116
1117
    return pieces
1118
1119
1120
def do_vcs_install(manifest_in, versionfile_source, ipy):

rna_tools/_version.py 1 location

@@ 216-305 (lines=90) @@
213
            "dirty": False, "error": "no suitable tags", "date": None}
214
215
216
@register_vcs_handler("git", "pieces_from_vcs")
217
def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
218
    """Get version from 'git describe' in the root of the source tree.
219
220
    This only gets called if the git-archive 'subst' keywords were *not*
221
    expanded, and _version.py hasn't already been rewritten with a short
222
    version string, meaning we're inside a checked out source tree.
223
    """
224
    GITS = ["git"]
225
    if sys.platform == "win32":
226
        GITS = ["git.cmd", "git.exe"]
227
228
    out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root,
229
                          hide_stderr=True)
230
    if rc != 0:
231
        if verbose:
232
            print("Directory %s not under git control" % root)
233
        raise NotThisMethod("'git rev-parse --git-dir' returned error")
234
235
    # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
236
    # if there isn't one, this yields HEX[-dirty] (no NUM)
237
    describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty",
238
                                          "--always", "--long",
239
                                          "--match", "%s*" % tag_prefix],
240
                                   cwd=root)
241
    # --long was added in git-1.5.5
242
    if describe_out is None:
243
        raise NotThisMethod("'git describe' failed")
244
    describe_out = describe_out.strip()
245
    full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
246
    if full_out is None:
247
        raise NotThisMethod("'git rev-parse' failed")
248
    full_out = full_out.strip()
249
250
    pieces = {}
251
    pieces["long"] = full_out
252
    pieces["short"] = full_out[:7]  # maybe improved later
253
    pieces["error"] = None
254
255
    # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
256
    # TAG might have hyphens.
257
    git_describe = describe_out
258
259
    # look for -dirty suffix
260
    dirty = git_describe.endswith("-dirty")
261
    pieces["dirty"] = dirty
262
    if dirty:
263
        git_describe = git_describe[:git_describe.rindex("-dirty")]
264
265
    # now we have TAG-NUM-gHEX or HEX
266
267
    if "-" in git_describe:
268
        # TAG-NUM-gHEX
269
        mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
270
        if not mo:
271
            # unparseable. Maybe git-describe is misbehaving?
272
            pieces["error"] = ("unable to parse git-describe output: '%s'"
273
                               % describe_out)
274
            return pieces
275
276
        # tag
277
        full_tag = mo.group(1)
278
        if not full_tag.startswith(tag_prefix):
279
            if verbose:
280
                fmt = "tag '%s' doesn't start with prefix '%s'"
281
                print(fmt % (full_tag, tag_prefix))
282
            pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
283
                               % (full_tag, tag_prefix))
284
            return pieces
285
        pieces["closest-tag"] = full_tag[len(tag_prefix):]
286
287
        # distance: number of commits since tag
288
        pieces["distance"] = int(mo.group(2))
289
290
        # commit: short hex revision ID
291
        pieces["short"] = mo.group(3)
292
293
    else:
294
        # HEX: no tags
295
        pieces["closest-tag"] = None
296
        count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
297
                                    cwd=root)
298
        pieces["distance"] = int(count_out)  # total number of commits
299
300
    # commit date: see ISO-8601 comment in git_versions_from_keywords()
301
    date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
302
                       cwd=root)[0].strip()
303
    pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
304
305
    return pieces
306
307
308
def plus_or_dot(pieces):