diff options
author | jakobjakobson13 <43045863+jakobjakobson13@users.noreply.github.com> | 2021-07-09 15:19:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-09 15:19:24 +0200 |
commit | aaa9214bd463d5e06064fd95316399f4f00340b8 (patch) | |
tree | bda309d2b8fd23f8eba779f52cb6e612be4d0296 /versioneer.py | |
parent | 702c5f5c5fcb0e96e3a3429abf21e3f2c9bd2170 (diff) | |
download | numpy-aaa9214bd463d5e06064fd95316399f4f00340b8.tar.gz |
Update versioneer.py
Diffstat (limited to 'versioneer.py')
-rw-r--r-- | versioneer.py | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/versioneer.py b/versioneer.py index 7a77c5ef7..7aa415ac8 100644 --- a/versioneer.py +++ b/versioneer.py @@ -946,21 +946,20 @@ def git_get_keywords(versionfile_abs): # _version.py. keywords = {} try: - f = open(versionfile_abs, "r") - for line in f.readlines(): - if line.strip().startswith("git_refnames ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["refnames"] = mo.group(1) - if line.strip().startswith("git_full ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["full"] = mo.group(1) - if line.strip().startswith("git_date ="): - mo = re.search(r'=\s*"(.*)"', line) - if mo: - keywords["date"] = mo.group(1) - f.close() + with open(versionfile_abs, "r") as f: + for line in f.readlines(): + if line.strip().startswith("git_refnames ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["refnames"] = mo.group(1) + if line.strip().startswith("git_full ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["full"] = mo.group(1) + if line.strip().startswith("git_date ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["date"] = mo.group(1) except EnvironmentError: pass return keywords @@ -1142,18 +1141,16 @@ def do_vcs_install(manifest_in, versionfile_source, ipy): files.append(versioneer_file) present = False try: - f = open(".gitattributes", "r") - for line in f.readlines(): - if line.strip().startswith(versionfile_source): - if "export-subst" in line.strip().split()[1:]: - present = True - f.close() + with open(".gitattributes", "r") as f: + for line in f.readlines(): + if line.strip().startswith(versionfile_source): + if "export-subst" in line.strip().split()[1:]: + present = True except EnvironmentError: pass if not present: - f = open(".gitattributes", "a+") - f.write("%s export-subst\n" % versionfile_source) - f.close() + with open(".gitattributes", "a+") as f: + f.write("%s export-subst\n" % versionfile_source) files.append(".gitattributes") run_command(GITS, ["add", "--"] + files) |