Skip to content

Remove temporary directories in cull() and convert() - #771

Merged
xylar merged 1 commit into
MPAS-Dev:masterfrom
xylar:fix-cull-convert-tempdir
Oct 23, 2026
Merged

xylar merged 1 commit into
MPAS-Dev:masterfrom
xylar:fix-cull-convert-tempdir

Conversation

@xylar

@xylar xylar commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

cull() and convert() in mpas_tools.mesh.conversion created their working directory with mkdtemp() and never removed it, so every call left copies of the input mesh, masks and output mesh behind (in the current directory when dir='.' is passed, as Polaris does). This PR uses TemporaryDirectory, as mask() already does, closing the loaded output dataset and copying any graph.info file before the directory is removed. It also adds a test that only the requested graph files remain in dir after culling and converting a planar mesh.

Fixes #764


Posted by Claude Code on @xylar's behalf. The testing, analysis and wording above are AI-authored; please check them accordingly.

🤖 Generated with Claude Code

Both functions created a working directory with mkdtemp() and never
removed it, leaving copies of the input mesh, masks and output mesh
behind on every call, despite their docstrings saying temporary files
are deleted.  Use TemporaryDirectory, as mask() already does, closing
the loaded output dataset and copying any graph file before the
directory is removed.

Add a test that the working directory only contains the requested
graph files after culling and converting a mesh.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@xylar

xylar commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator Author

Testing

mpas_tools 2.2.0 isn't on conda-forge yet, so I tested in a conda environment with the mpas_tools 2.1.0 package (for the compiled executables) and this branch installed in editable mode on top.

  • The new test_cull_convert_remove_temp_dir fails on master: a tmpXXXXXXXX directory is left behind next to the graph files. It passes with this branch.
  • From the repo root, pytest conda_package/tests/test_conversion.py conda_package/tests/test_mesh_mask.py conda_package/tests/test_sort_mesh.py gives 11 passed and 1 failed. The failure is test_conversion_triangle_angle_quality, which is expected with the 2.1.0 executables: that test needs the triangleAngleQuality output from the 2.2.0 converter (Fix law-of-cosines typo in triangleAngleQuality #763).
  • No tmp* directories are left in the working directory after the test run.
  • pre-commit passes.

Posted by Claude Code on @xylar's behalf. The testing, analysis and wording above are AI-authored; please check them accordingly.

@xylar
xylar merged commit 4abeec3 into MPAS-Dev:master Oct 23, 2026
5 checks passed
@xylar
xylar deleted the fix-cull-convert-tempdir branch October 23, 2026 18:44
@xylar xylar mentioned this pull request Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cull() and convert() leave their temporary directory behind

1 participant