Skip to contentSkip to conversation

gitpkgv: ensure that we close our opened files

PATCH In review Christopher Larson 2 participants 2 messages Jun 3, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gitpkgv: ensure that we close our opened files

From: Christopher Larson <[email protected]>

Avoids warnings like this with python3:

WARNING: .../meta-openembedded/meta-filesystems/recipes-filesystems/smbnetfs/smbnetfs_git.bb: <string>:94: ResourceWarning: unclosed file <_io.TextIOWrapper name='.../build/downloads/git2/smbnetfs.git.sourceforge.net.gitroot.smbnetfs.smbnetfs/oe-gitpkgv_ace1c519d4' mode='r' encoding='UTF-8'>

---
 meta-oe/classes/gitpkgv.bbclass | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
meta-oe/classes/gitpkgv.bbclass +4 -2
index 1cba00c..4866fac 100644
@@ -87,11 +87,13 @@ def get_git_pkgv(d, use_tags):
 
                     if commits != "":
                         oe.path.remove(rev_file, recurse=False)
-                        open(rev_file, "w").write("%d\n" % int(commits))
+                        with open(rev_file, "w") as f:
+                            f.write("%d\n" % int(commits))
                     else:
                         commits = "0"
                 else:
-                    commits = open(rev_file, "r").readline(128).strip()
+                    with open(rev_file, "r") as f:
+                        commits = f.readline(128).strip()
 
                 if use_tags:
                     try:
Signature · 1 line
2.8.0
#1 lore raw

Ignore this, just noticed the fix is already on master-next.

Quoted 41 lines · Christopher Larson

From: Christopher Larson <[email protected]>

Avoids warnings like this with python3:

WARNING:
.../meta-openembedded/meta-filesystems/recipes-filesystems/smbnetfs/
smbnetfs_git.bb: <string>:94: ResourceWarning: unclosed file
<_io.TextIOWrapper name='.../build/downloads/git2/smbnetfs.git.sourceforge.net.gitroot.smbnetfs.smbnetfs/oe-gitpkgv_ace1c519d4' mode='r' encoding='UTF-8'>

---
 meta-oe/classes/gitpkgv.bbclass | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
meta-oe/classes/gitpkgv.bbclass +4 -3
index 1cba00c..4866fac 100644
@@ -87,11 +87,13 @@ def get_git_pkgv(d, use_tags):
 
                     if commits != "":
                         oe.path.remove(rev_file, recurse=False)
-                        open(rev_file, "w").write("%d\n" % int(commits))
+                        with open(rev_file, "w") as f:
+                            f.write("%d\n" % int(commits))
                     else:
                         commits = "0"
                 else:
-                    commits = open(rev_file, "r").readline(128).strip()
+                    with open(rev_file, "r") as f:
+                        commits = f.readline(128).strip()
 
                 if use_tags:
                     try:
--

2.8.0

Signature · 5 lines
Christopher Larson
kergoth at gmail dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics