From a9ff191a2ed6ea60bad8e26938fb8022054a3c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wiik=20=C3=85nes?= Date: Mon, 1 Feb 2021 10:04:49 +0100 Subject: [PATCH] Correct deletion of temp files in temp dirs in user guide MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Håkon Wiik Ånes --- .gitignore | 3 +++ doc/changelog.rst | 2 ++ doc/geometrical_ebsd_simulations.ipynb | 17 +++++++++-------- doc/load_save_data.ipynb | 13 ++++++++++++- doc/pattern_matching.ipynb | 4 +++- doc/virtual_backscatter_electron_imaging.ipynb | 4 +++- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index b90f1e7c..b2804f35 100644 --- a/.gitignore +++ b/.gitignore @@ -104,3 +104,6 @@ ENV/ #auto changing files build/ src/ + +# Backport +.backportrc.json \ No newline at end of file diff --git a/doc/changelog.rst b/doc/changelog.rst index 4efeab35..9daa6341 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -21,6 +21,8 @@ Contributors Fixed ----- +- Deletion of temporary files saved to temporary directories in user guide + (`#311 `_) - Pattern matching sometimes failing to generate a crystal map due to incorrect creation of spatial arrays (`#307 `_) diff --git a/doc/geometrical_ebsd_simulations.ipynb b/doc/geometrical_ebsd_simulations.ipynb index 66caab53..fb7a1966 100644 --- a/doc/geometrical_ebsd_simulations.ipynb +++ b/doc/geometrical_ebsd_simulations.ipynb @@ -415,8 +415,8 @@ "outputs": [], "source": [ "nav_x, nav_y = s.axes_manager.indices\n", - "temp_dir = tempfile.mkdtemp()\n", - "fname = temp_dir + f\"/geosim_y{nav_y}_x{nav_x}.png\"\n", + "temp_dir = tempfile.mkdtemp() + \"/\"\n", + "fname = temp_dir + f\"geosim_y{nav_y}_x{nav_x}.png\"\n", "s._plot.signal_plot.figure.savefig(fname, bbox_inches=bbox, dpi=150)" ] }, @@ -444,7 +444,7 @@ "outputs": [], "source": [ "nav_x, nav_y = s.axes_manager.indices\n", - "fname = temp_dir + f\"/geosim_y{nav_y}_x{nav_x}.png\"\n", + "fname = temp_dir + f\"geosim_y{nav_y}_x{nav_x}.png\"\n", "s._plot.signal_plot.figure.savefig(fname, bbox_inches=bbox, dpi=150)" ] }, @@ -602,13 +602,14 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "nbsphinx": "hidden" - }, + "metadata": {}, "outputs": [], "source": [ - "from shutil import rmtree\n", - "rmtree(temp_dir) # Remove files written to disk in this user guide" + "# Remove files written to disk in this user guide\n", + "import os\n", + "for file in [\"geosim_y0_x0.png\", \"geosim_y1_x2.png\"]:\n", + " os.remove(temp_dir + file)\n", + "os.rmdir(temp_dir)" ] } ], diff --git a/doc/load_save_data.ipynb b/doc/load_save_data.ipynb index d7a02839..fcf3a715 100644 --- a/doc/load_save_data.ipynb +++ b/doc/load_save_data.ipynb @@ -397,7 +397,7 @@ "metadata": {}, "outputs": [], "source": [ - "temp_dir = tempfile.mkdtemp()\n", + "temp_dir = tempfile.mkdtemp() + \"/\"\n", "s.save(temp_dir + \"patterns\")" ] }, @@ -957,7 +957,18 @@ }, "outputs": [], "source": [ + "# Remove files written to disk in this user guide\n", "import os\n", + "for file in [\n", + " \"patterns.h5\",\n", + " \"patterns_new.h5\",\n", + " \"patterns.dat\",\n", + " \"master_pattern.hspy\",\n", + " \"vbse.tif\",\n", + "]:\n", + " os.remove(temp_dir + file)\n", + "for i in range(25):\n", + " os.remove(temp_dir + f\"vbse{i}.png\")\n", "os.rmdir(temp_dir)" ] } diff --git a/doc/pattern_matching.ipynb b/doc/pattern_matching.ipynb index 180fdc73..11b05320 100644 --- a/doc/pattern_matching.ipynb +++ b/doc/pattern_matching.ipynb @@ -341,7 +341,7 @@ "metadata": {}, "outputs": [], "source": [ - "temp_dir = tempfile.mkdtemp()\n", + "temp_dir = tempfile.mkdtemp() + \"/\"\n", "xmap_file = temp_dir + \"ni.h5\"\n", "io.save(xmap_file, xmap)" ] @@ -449,7 +449,9 @@ }, "outputs": [], "source": [ + "# Remove files written to disk in this user guide\n", "import os\n", + "os.remove(xmap_file)\n", "os.rmdir(temp_dir)" ] } diff --git a/doc/virtual_backscatter_electron_imaging.ipynb b/doc/virtual_backscatter_electron_imaging.ipynb index 495e1c39..400f40f0 100644 --- a/doc/virtual_backscatter_electron_imaging.ipynb +++ b/doc/virtual_backscatter_electron_imaging.ipynb @@ -120,7 +120,7 @@ "metadata": {}, "outputs": [], "source": [ - "temp_dir = tempfile.mkdtemp()\n", + "temp_dir = tempfile.mkdtemp() + \"/\"\n", "plt.imsave(temp_dir + \"vbse1.png\", arr=vbse.data)" ] }, @@ -377,7 +377,9 @@ }, "outputs": [], "source": [ + "# Remove files written to disk in this user guide\n", "import os\n", + "os.remove(temp_dir + \"vbse1.png\")\n", "os.rmdir(temp_dir)" ] }