This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by thopre on Oct 10 2019, 8:45 AM.

Details

Summary

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.

Event Timeline

thopre created this revision.Oct 10 2019, 8:45 AM
cmatthews accepted this revision.Dec 4 2019, 11:37 AM
This revision is now accepted and ready to land.Dec 4 2019, 11:37 AM
PrzemekWirkus added inline comments.Dec 5 2019, 4:00 AM
lnt/util/ImportData.py
341–343

This can be simplified to:

with os.fdopen(fd, "w") as fp:

fp.write(data)

?

PrzemekWirkus added inline comments.Dec 5 2019, 4:31 AM
lnt/util/ImportData.py
341–343

Got that code block wrong last time:

with os.fdopen(fd, "w") as fp:
    fp.write(data)
thopre marked 3 inline comments as done.Dec 5 2019, 5:09 AM
thopre added inline comments.
lnt/util/ImportData.py
341–343

Sorry, only saw that after committing the change. I've created https://reviews.llvm.org/D71058 for it