Code Duplication    Length = 27-27 lines in 2 locations

versioneer.py 1 location

@@ 944-970 (lines=27) @@
941
'''
942
943
944
@register_vcs_handler("git", "get_keywords")
945
def git_get_keywords(versionfile_abs):
946
    """Extract version information from the given file."""
947
    # the code embedded in _version.py can just fetch the value of these
948
    # keywords. When used from setup.py, we don't want to import _version.py,
949
    # so we do it with a regexp instead. This function is not used from
950
    # _version.py.
951
    keywords = {}
952
    try:
953
        f = open(versionfile_abs, "r")
954
        for line in f.readlines():
955
            if line.strip().startswith("git_refnames ="):
956
                mo = re.search(r'=\s*"(.*)"', line)
957
                if mo:
958
                    keywords["refnames"] = mo.group(1)
959
            if line.strip().startswith("git_full ="):
960
                mo = re.search(r'=\s*"(.*)"', line)
961
                if mo:
962
                    keywords["full"] = mo.group(1)
963
            if line.strip().startswith("git_date ="):
964
                mo = re.search(r'=\s*"(.*)"', line)
965
                if mo:
966
                    keywords["date"] = mo.group(1)
967
        f.close()
968
    except EnvironmentError:
969
        pass
970
    return keywords
971
972
973
@register_vcs_handler("git", "keywords")

loghub/_version.py 1 location

@@ 132-158 (lines=27) @@
129
                "dirty": False,
130
                "error": None,
131
                "date": None
132
            }
133
        else:
134
            rootdirs.append(root)
135
            root = os.path.dirname(root)  # up a level
136
137
    if verbose:
138
        print("Tried directories %s but none started with prefix %s" %
139
              (str(rootdirs), parentdir_prefix))
140
    raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
141
142
143
@register_vcs_handler("git", "get_keywords")
144
def git_get_keywords(versionfile_abs):
145
    """Extract version information from the given file."""
146
    # the code embedded in _version.py can just fetch the value of these
147
    # keywords. When used from setup.py, we don't want to import _version.py,
148
    # so we do it with a regexp instead. This function is not used from
149
    # _version.py.
150
    keywords = {}
151
    try:
152
        f = open(versionfile_abs, "r")
153
        for line in f.readlines():
154
            if line.strip().startswith("git_refnames ="):
155
                mo = re.search(r'=\s*"(.*)"', line)
156
                if mo:
157
                    keywords["refnames"] = mo.group(1)
158
            if line.strip().startswith("git_full ="):
159
                mo = re.search(r'=\s*"(.*)"', line)
160
                if mo:
161
                    keywords["full"] = mo.group(1)