From 0d67c74616d5312f56e3a05afe4350a5418549b6 Mon Sep 17 00:00:00 2001 From: dfguerrerom <dfgm2006@gmail.com> Date: Wed, 29 May 2024 16:33:29 +0200 Subject: [PATCH 1/2] =?UTF-8?q?bump:=20version=200.2.0=20=E2=86=92=200.3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 15 +++++++++++++++ component/message/en/en.json | 2 +- pyproject.toml | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b279268..c416b62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +## 0.3.0 (2024-05-29) + +### Feat + +- give sepal_template name and set mdoule name in appbar +- typos +- fix gee sources +- improve export visualization methods +- Add authentication cell + +### Refactor + +- adapt to planet_model +- **ui.ipynb**: update sepal entrypoint + ## 0.2.0 (2023-12-11) ### Feat diff --git a/component/message/en/en.json b/component/message/en/en.json index a4c6144..82a73c0 100644 --- a/component/message/en/en.json +++ b/component/message/en/en.json @@ -1,6 +1,6 @@ { "app": { - "title": "Time series", + "title": "Clip time series", "drawer_item": { "point": "Import points", "viz": "Visualize Points", diff --git a/pyproject.toml b/pyproject.toml index fba5351..640fa43 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ init-notebook = "ui.ipynb" [project] -version = "0.2.0" +version = "0.3.0" [tool.ruff] ignore-init-module-imports = true @@ -29,7 +29,7 @@ convention = "google" "*/__init__.py" = ["F403"] # unable to detect undefined names | hide internal strcuture [tool.commitizen] -version = "0.2.0" +version = "0.3.0" update_changelog_on_bump = true changelog_file = "CHANGELOG.md" changelog_incremental = true From 8c82bd6ae1c02d0eee531b63360b7a7fe05c03b4 Mon Sep 17 00:00:00 2001 From: dfguerrerom <dfgm2006@gmail.com> Date: Wed, 29 May 2024 17:48:35 +0200 Subject: [PATCH 2/2] refactor: remove tmp folder if it fails --- .github/workflows/unit.yaml | 1 + component/scripts/export.py | 6 ++---- component/scripts/utils.py | 28 ++++++++++++++++++++++++++++ component/tile/export_tile.py | 5 ++--- test/test_export.py | 6 +++--- test/test_gee.py | 5 +++-- test/test_planet.py | 6 +++--- 7 files changed, 42 insertions(+), 15 deletions(-) diff --git a/.github/workflows/unit.yaml b/.github/workflows/unit.yaml index bc437d7..4208e86 100644 --- a/.github/workflows/unit.yaml +++ b/.github/workflows/unit.yaml @@ -1,4 +1,5 @@ name: Unit testing +# To test with act: gh act --secret-file $ENV_FILE --workflows .github/workflows/unit.yaml on: - push diff --git a/component/scripts/export.py b/component/scripts/export.py index 816614d..4c86d52 100644 --- a/component/scripts/export.py +++ b/component/scripts/export.py @@ -1,5 +1,4 @@ import re -import shutil from pathlib import Path import geopandas as gpd @@ -13,7 +12,7 @@ from component import parameter as cp from component import widget as cw -from .utils import enhance_band, get_buffers, get_pdf_path, reproject +from .utils import enhance_band, get_buffers, get_pdf_path, remove_tmp_dir, reproject init_ee() @@ -178,8 +177,7 @@ def get_pdf( merger.write(str(pdf_filepath)) # flush the tmp repository - shutil.rmtree(cp.tmp_dir) - cp.tmp_dir.mkdir() + remove_tmp_dir(tmp_dir) output.add_live_msg(f"PDF output finished: {pdf_filepath}", "success") diff --git a/component/scripts/utils.py b/component/scripts/utils.py index d95d9a0..e7dc519 100644 --- a/component/scripts/utils.py +++ b/component/scripts/utils.py @@ -1,4 +1,7 @@ +import shutil +import time from math import sqrt +from pathlib import Path from typing import List, Union import ee @@ -195,3 +198,28 @@ def get_quad_dict(planet_model, mosaics: list, quad_ids: list) -> dict: ) return quads_dict + + +def remove_tmp_dir(tmp_dir: str): + """Remove the temporary directory if it exists.""" + + if Path(tmp_dir).exists(): + max_retries = 3 + retries = 0 + + while retries < max_retries: + try: + shutil.rmtree(tmp_dir) + break + except OSError as e: + if e.errno == 39: # Directory not empty + print("Directory not empty, retrying...") + time.sleep(1) # wait a bit for files to be released + retries += 1 + else: + # I don't want to raise errors if there's a problem + print("Failed to remove directory.") + raise + + if retries == max_retries: + print("Failed to remove directory after several attempts.") diff --git a/component/tile/export_tile.py b/component/tile/export_tile.py index cc8b8f1..61dcfa6 100644 --- a/component/tile/export_tile.py +++ b/component/tile/export_tile.py @@ -1,4 +1,3 @@ -import shutil import tempfile from pathlib import Path @@ -13,7 +12,7 @@ from component import scripts as cs from component import widget as cw from component.message import cm -from component.scripts.utils import get_pdf_path +from component.scripts.utils import get_pdf_path, remove_tmp_dir class ExportResult(sw.Tile): @@ -155,6 +154,6 @@ def _export_data(self, widget, event, data): finally: # remove the temporary folder in any case - shutil.rmtree(tmp_dir) + remove_tmp_dir(tmp_dir) return diff --git a/test/test_export.py b/test/test_export.py index 098662c..8f165cb 100644 --- a/test/test_export.py +++ b/test/test_export.py @@ -1,10 +1,10 @@ -import shutil import tempfile from pathlib import Path from component.scripts.export import get_pdf from component.scripts.gee import get_gee_vrt from component.scripts.planet import get_planet_vrt +from component.scripts.utils import remove_tmp_dir def test_get_gee_pdf(geometries, alert): @@ -47,7 +47,7 @@ def test_get_gee_pdf(geometries, alert): except Exception as e: raise e finally: - shutil.rmtree(tmp_dir) + remove_tmp_dir(tmp_dir) def test_get_planet_pdf(geometries, alert, planet_model): @@ -96,4 +96,4 @@ def test_get_planet_pdf(geometries, alert, planet_model): except Exception as e: raise e finally: - shutil.rmtree(tmp_dir) + remove_tmp_dir(tmp_dir) diff --git a/test/test_gee.py b/test/test_gee.py index 4cf0b8b..b58c5f1 100644 --- a/test/test_gee.py +++ b/test/test_gee.py @@ -1,11 +1,12 @@ import os -import shutil import sys import ee import pytest import rasterio +from component.scripts.utils import remove_tmp_dir + sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) import tempfile @@ -60,7 +61,7 @@ def test_get_gee_vrt( except Exception as e: raise e finally: - shutil.rmtree(tmp_dir) + remove_tmp_dir(tmp_dir) def test_get_ee_image(): diff --git a/test/test_planet.py b/test/test_planet.py index 8356772..43e8fbe 100644 --- a/test/test_planet.py +++ b/test/test_planet.py @@ -1,5 +1,4 @@ import os -import shutil import sys import pytest @@ -14,6 +13,7 @@ from component.scripts.utils import ( get_buffers, get_quad_dict, + remove_tmp_dir, ) # Test different parameters @@ -63,7 +63,7 @@ def test_get_planet_vrt( except Exception as e: raise e finally: - shutil.rmtree(tmp_dir) + remove_tmp_dir(tmp_dir) def test_get_planet_grid(geometries, alert): @@ -131,4 +131,4 @@ def test_get_planet_quad(planet_model, alert): except Exception as e: raise e finally: - shutil.rmtree(tmp_dir) + remove_tmp_dir(tmp_dir)