Use context managers to open files

Inspired by d50a6ddc1b.
This commit is contained in:
Luflosi
2019-08-01 13:21:26 -05:00
parent 68f3b6fbeb
commit 5f855ce547
17 changed files with 161 additions and 139 deletions

View File

@@ -315,7 +315,8 @@ def get_vcs_rev_defines():
with open('.git/refs/heads/master') as f:
rev = f.read()
except NotADirectoryError:
gitloc = open('.git').read()
with open('.git') as f:
gitloc = f.read()
with open(os.path.join(gitloc, 'refs/heads/master')) as f:
rev = f.read()
@@ -343,7 +344,8 @@ def newer(dest, *sources):
def dependecies_for(src, obj, all_headers):
dep_file = obj.rpartition('.')[0] + '.d'
try:
deps = open(dep_file).read()
with open(dep_file) as f:
deps = f.read()
except FileNotFoundError:
yield src
yield from iter(all_headers)