From 37a7e2db6db2c264fdbc5c8a11009335860d4276 Mon Sep 17 00:00:00 2001 From: John Mather Date: Mon, 12 Jul 2021 13:14:50 -0400 Subject: [PATCH] Resolved unclosed file ResourceWarnings The original code would emit unclosed file ResourceWarnings when the PYTHONWARNINGS environment variable is active. --- pxr/base/gf/gfGenCode.py | 3 ++- pxr/usd/usd/usdGenSchema.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pxr/base/gf/gfGenCode.py b/pxr/base/gf/gfGenCode.py index 27e23ceb11..425b11e6af 100644 --- a/pxr/base/gf/gfGenCode.py +++ b/pxr/base/gf/gfGenCode.py @@ -49,7 +49,8 @@ def _WriteFile(filePath, content, verbose=True): content = (content + '\n' if content and not content.endswith('\n') else content) if os.path.exists(filePath): - existingContent = open(filePath, 'r').read() + with open(filePath, 'r') as fp: + existingContent = fp.read() if existingContent == content: if verbose: print('\tunchanged %s' % filePath) diff --git a/pxr/usd/usd/usdGenSchema.py b/pxr/usd/usd/usdGenSchema.py index 2eab220965..685de0bc93 100644 --- a/pxr/usd/usd/usdGenSchema.py +++ b/pxr/usd/usd/usdGenSchema.py @@ -762,7 +762,8 @@ def _WriteFile(filePath, content, validate): content = (content + '\n' if content and not content.endswith('\n') else content) if os.path.exists(filePath): - existingContent = open(filePath, 'r').read() + with open(filePath, 'r') as fp: + existingContent = fp.read() if existingContent == content: Print('\tunchanged %s' % filePath) return @@ -1090,7 +1091,8 @@ def GeneratePlugInfo(templatePath, codeGenPath, classes, validate, env): # read existing plugInfo file, strip comments. plugInfoFile = os.path.join(codeGenPath, 'plugInfo.json') if os.path.isfile(plugInfoFile): - infoLines = open(plugInfoFile).readlines() + with open(plugInfoFile, 'r') as fp: + infoLines = fp.readlines() infoLines = [l for l in infoLines if not l.strip().startswith('#')] # parse as json.