[PATCH] D68802: [LNT] Python 3 support: fix writing report to tmp file

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 10 08:50:10 PDT 2019


thopre created this revision.
thopre added reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls.
thopre added a parent revision: D68801: [LNT] Python 3 support: print unknown metric with str.
thopre added a child revision: D68803: [LNT] Python 3 support: sort benchmark regressing.

The import_from_string() method in lnt.util.ImportData writes a copy of
the report being imported into a temporary file. That fails under Python
3 because by default tempfile.mkstemp open in binary mode and the data
written is text.

This commit sets the text parameter of mkstemp to True to ensure the
file is opened in text mode. It also write to the file via a file object
since os.write expects binary data.


https://reviews.llvm.org/D68802

Files:
  lnt/util/ImportData.py


Index: lnt/util/ImportData.py
===================================================================
--- lnt/util/ImportData.py
+++ lnt/util/ImportData.py
@@ -337,9 +337,10 @@
     # recovery.
     prefix = utcnow.strftime("data-%Y-%m-%d_%H-%M-%S")
     fd, path = tempfile.mkstemp(prefix=prefix, suffix='.json',
-                                dir=str(tmpdir))
-    os.write(fd, data)
-    os.close(fd)
+                                dir=str(tmpdir), text=True)
+    fp = os.fdopen(fd, "w")
+    fp.write(data)
+    fp.close()
 
     # Import the data.
     #


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68802.224368.patch
Type: text/x-patch
Size: 561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191010/4a5a6a5c/attachment.bin>


More information about the llvm-commits mailing list