mdolab / pygeo

pyGeo provides geometric design variables and constraints suitable for gradient-based optimization.
https://mdolab-pygeo.readthedocs-hosted.com/en/latest/?badge=latest
Apache License 2.0
122 stars 54 forks source link

`readPlot3DSurfFile` never closes file after opening it #246

Closed eytanadler closed 3 months ago

eytanadler commented 3 months ago

Purpose

When initializing a DVGeometry object, one way to specify the FFD file is to provide its filename. The function responsible for reading this file opens it, but never closes it. This can cause file system problems. I changed it to put the code that reads from the file in a with block so that it is closed upon exiting (either a raised error or function return).

Expected time until merged

1 day

Type of change

Testing

Checklist

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 0% with 31 lines in your changes are missing coverage. Please review.

Project coverage is 65.47%. Comparing base (dcf5ff6) to head (c8621ea).

Files Patch % Lines
pygeo/geo_utils/file_io.py 0.00% 31 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #246 +/- ## ======================================= Coverage 65.46% 65.47% ======================================= Files 47 47 Lines 12266 12265 -1 ======================================= Hits 8030 8030 + Misses 4236 4235 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

eytanadler commented 3 months ago

Looks like the previous function getCoordinatesFromFile uses f.open() and f.close(), could you update that and other functions to use with?

Sure thing. I'm pretty sure np.loadtxt() could replace this entire function, but I can't find any examples of this method being used so I have no idea what file type it's meant for.