Skip to content

Commit

Permalink
Fix unclosed files (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored Sep 18, 2020
1 parent 7a4930b commit 476ec50
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/fmu/ensemble/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ def manifest(self, manifest):
self._manifest = manifest
elif isinstance(manifest, six.string_types):
if os.path.exists(manifest):
manifest_fromyaml = yaml.safe_load(open(manifest))
with open(manifest) as file_handle:
manifest_fromyaml = yaml.safe_load(file_handle)
if not manifest_fromyaml:
logger.warning("Empty manifest")
self._manifest = {}
Expand Down
6 changes: 4 additions & 2 deletions src/fmu/ensemble/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ def load_status(self):
jsonfilename = os.path.join(self._origpath, "jobs.json")
if jsonfilename and os.path.exists(jsonfilename):
try:
jobsinfo = json.load(open(jsonfilename))
with open(jsonfilename) as file_handle:
jobsinfo = json.load(file_handle)
jobsinfodf = pd.DataFrame(jobsinfo["jobList"])
jobsinfodf["JOBINDEX"] = jobsinfodf.index.astype(int)
# Outer merge means that we will also have jobs from
Expand Down Expand Up @@ -806,7 +807,8 @@ def find_files(self, paths, metadata=None, metayaml=False):
# might be out of luck if you have multiple..
for cand in yaml_candidates:
if os.path.exists(os.path.join(dirname, cand)):
metadict = yaml.full_load(open(os.path.join(dirname, cand)))
with open(os.path.join(dirname, cand)) as file_handle:
metadict = yaml.full_load(file_handle)
continue

# Flatten metadict:
Expand Down
3 changes: 2 additions & 1 deletion src/fmu/ensemble/virtualensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,8 @@ def manifest(self, manifest):
self._manifest = manifest
elif isinstance(manifest, six.string_types):
if os.path.exists(manifest):
manifest_fromyaml = yaml.safe_load(open(manifest))
with open(manifest) as file_handle:
manifest_fromyaml = yaml.safe_load(file_handle)
if not manifest_fromyaml:
logger.warning("Empty manifest")
self._manifest = {}
Expand Down

0 comments on commit 476ec50

Please sign in to comment.