wireviz / WireViz

Easily document cables and wiring harnesses.
GNU General Public License v3.0
4.42k stars 226 forks source link

Avoid ResourceWarning: unclosed file #395

Closed kvid closed 4 months ago

kvid commented 4 months ago

A number of such warnings showed up when running (with wireviz v0.4) e.g.

PYTHONWARNINGS=always python build_examples.py
PYTHONWARNINGS=always wireviz ../../examples/demo0?.yml

See https://github.com/wireviz/WireViz/pull/309#issuecomment-2170988381

Fix: All open() calls should be in a "with open() as x" statement to ensure closing the file when exiting the block in any way. Otherwise, use the new file_read_text() or file_write_text() thin wrapper functions to read or write the whole utf-8 text file and closing it.