Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Commit 5e06ce5

Browse files
committed
Fix ResourceWarning: unclosed file
Using `open()` without explicitly closing the handle is not a best practice. Use `open()` as a context manager so that handles will be closed immediately after their contents are read. This silences a warning that appears when running with `PYTHONWARNINGS=always` (or `python -Wd ...`)
1 parent b62c77e commit 5e06ce5

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

clrenv/lazy_env.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ def get_env(*mode):
7676
global _env
7777

7878
if not mode in _env:
79-
y = (_load_current_environment(),)
80-
upaths = find_user_environment_paths()
81-
y = tuple(safe_load(open(p).read()) for p in upaths if os.path.isfile(p)) + y
79+
y = []
80+
for path in find_user_environment_paths():
81+
if os.path.isfile(path):
82+
with open(path) as handle:
83+
y.append(safe_load(handle.read()))
84+
y.append(_load_current_environment())
8285

8386
assignments = tuple(m for m in mode if m.find('=') != -1)
8487
mode = tuple(m for m in mode if m.find('=') == -1)

setup.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import os
2-
31
try:
4-
from setuptools import setup
2+
from setuptools import setup
53
except:
6-
from distutils.core import setup
4+
from distutils.core import setup
75

86

97
setup(name = "clrenv",
10-
version = "0.1.8",
8+
version = "0.1.9",
119
description = "A tool to give easy access to environment yaml file to python.",
1210
author = "Color Genomics",
1311
author_email = "[email protected]",

0 commit comments

Comments
 (0)