From 27bf4282d3d5879f0f4f7492400675ba93a3db1b Mon Sep 17 00:00:00 2001 From: Ayman Saleh <30412615+ayman-saleh@users.noreply.github.com> Date: Wed, 10 Nov 2021 06:51:30 -0500 Subject: [PATCH] Fix `check_requirements()` resource warning allocation open file (#5602) * Fix to resource warning allocation; utilize file.open within a context manager * rename fh to f in keeping with naming convention Co-authored-by: Ayman Saleh Co-authored-by: Glenn Jocher --- utils/general.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index a6fe603850c8..8f59d487edfb 100755 --- a/utils/general.py +++ b/utils/general.py @@ -264,7 +264,8 @@ def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), insta if isinstance(requirements, (str, Path)): # requirements.txt file file = Path(requirements) assert file.exists(), f"{prefix} {file.resolve()} not found, check failed." - requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(file.open()) if x.name not in exclude] + with file.open() as f: + requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(f) if x.name not in exclude] else: # list or tuple of packages requirements = [x for x in requirements if x not in exclude]