rustworkx icon indicating copy to clipboard operation
rustworkx copied to clipboard

Avoid using temp files when generating Pillow images

Open IvanIsCoding opened this issue 2 years ago • 2 comments

Closes #660

This PR switches from creating a temporary file to save the output of the dot command to writing it to a BytesIO file in memory.

This fixes the problematic behaviour of copying Pillow images: they keep the original source pointing to the temporary file when copied. And when we run im.show(), because the file is temporary, it might be already deleted. Hence it is generally better to do the processing in-memory.

IvanIsCoding avatar Sep 19 '22 03:09 IvanIsCoding

@LaurentBergeron I didn't meant to steal this issue from, I was going to send you the problematic code and found the fix.

Can you help me review this though?

IvanIsCoding avatar Sep 19 '22 04:09 IvanIsCoding

Pull Request Test Coverage Report for Build 3183792667

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 97.036%

Totals Coverage Status
Change from base Build 3178193623: 0.0%
Covered Lines: 13260
Relevant Lines: 13665

💛 - Coveralls

coveralls avatar Sep 19 '22 04:09 coveralls

For the record, I tested the example from #660 on a Windows machine and the image displayed correctly without issues. I was also able to build the documentation which contains many calls to graphviz_draw, so I believe this is safe to merge.

IvanIsCoding avatar Sep 29 '22 17:09 IvanIsCoding

I couldn't figure out the details of that new error that I'm getting, but one interesting fact is that the error goes away if I move the contents of the graphviz_draw into my __main__ script. Could it be that the temporary paths are relative to where current code is executed, and not the directory from which the code was first executed? I think there's some more issues that I need to figure out in my rustworx dev environment.

Anyways, I am happy with the new changes, it looks good. I don't want to hold out the PR, although I don't think I have permission to approve?

LaurentBergeron avatar Sep 30 '22 22:09 LaurentBergeron