Code Duplication    Length = 27-27 lines in 2 locations

versioneer.py 1 location

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

metpy/_version.py 1 location

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