diff options
author | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2016-08-24 19:29:11 -0400 |
---|---|---|
committer | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2016-08-27 18:29:55 -0400 |
commit | 4c71695e41a50dda3199d26ed7aedbaaf3150768 (patch) | |
tree | 8bd499a2a113c3da5c1dee8ed29f4b3c69d27dd7 /mesonbuild/mconf.py | |
parent | 7830cb61c39fbaf57933ac403dcdf5007667d87d (diff) | |
download | meson-4c71695e41a50dda3199d26ed7aedbaaf3150768.zip meson-4c71695e41a50dda3199d26ed7aedbaaf3150768.tar.gz meson-4c71695e41a50dda3199d26ed7aedbaaf3150768.tar.bz2 |
Use context manager for file I/O.
There are a few cases where a context manager cannot be used, such as
the logger.
Diffstat (limited to 'mesonbuild/mconf.py')
-rw-r--r-- | mesonbuild/mconf.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py index 4b11c10..afabc62 100644 --- a/mesonbuild/mconf.py +++ b/mesonbuild/mconf.py @@ -36,15 +36,18 @@ class Conf: self.build_file = os.path.join(build_dir, 'meson-private/build.dat') if not os.path.isfile(self.coredata_file) or not os.path.isfile(self.build_file): raise ConfException('Directory %s does not seem to be a Meson build directory.' % build_dir) - self.coredata = pickle.load(open(self.coredata_file, 'rb')) - self.build = pickle.load(open(self.build_file, 'rb')) + with open(self.coredata_file, 'rb') as f: + self.coredata = pickle.load(f) + with open(self.build_file, 'rb') as f: + self.build = pickle.load(f) if self.coredata.version != coredata.version: raise ConfException('Version mismatch (%s vs %s)' % (coredata.version, self.coredata.version)) def save(self): # Only called if something has changed so overwrite unconditionally. - pickle.dump(self.coredata, open(self.coredata_file, 'wb')) + with open(self.coredata_file, 'wb') as f: + pickle.dump(self.coredata, f) # We don't write the build file because any changes to it # are erased when Meson is executed the nex time, i.e. the next # time Ninja is run. |