mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Fix several ResourceWarning: unclosed file
This commit is contained in:
parent
abee146199
commit
67d6fcb0f6
10 changed files with 78 additions and 34 deletions
|
|
@ -72,7 +72,8 @@ REV_LINE_FMT = '{}rev:{}{}{}'
|
|||
|
||||
|
||||
def _write_new_config_file(path, output):
|
||||
original_contents = open(path).read()
|
||||
with open(path) as f:
|
||||
original_contents = f.read()
|
||||
output = remove_defaults(output, CONFIG_SCHEMA)
|
||||
new_contents = ordered_dump(output, **C.YAML_DUMP_KWARGS)
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ def _hook_paths(git_root, hook_type):
|
|||
def is_our_script(filename):
|
||||
if not os.path.exists(filename):
|
||||
return False
|
||||
contents = io.open(filename).read()
|
||||
with io.open(filename) as f:
|
||||
contents = f.read()
|
||||
return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,8 @@ def get_conflicted_files():
|
|||
logger.info('Checking merge-conflict files only.')
|
||||
# Need to get the conflicted files from the MERGE_MSG because they could
|
||||
# have resolved the conflict by choosing one side or the other
|
||||
merge_msg = open(os.path.join(get_git_dir('.'), 'MERGE_MSG'), 'rb').read()
|
||||
with open(os.path.join(get_git_dir('.'), 'MERGE_MSG'), 'rb') as f:
|
||||
merge_msg = f.read()
|
||||
merge_conflict_filenames = parse_merge_msg_for_conflicts(merge_msg)
|
||||
|
||||
# This will get the rest of the changes made after the merge.
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ def _read_state(prefix, venv):
|
|||
if not os.path.exists(filename):
|
||||
return None
|
||||
else:
|
||||
return json.loads(io.open(filename).read())
|
||||
with io.open(filename) as f:
|
||||
return json.loads(f.read())
|
||||
|
||||
|
||||
def _write_state(prefix, venv, state):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue