Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
dfguerrerom committed May 29, 2024
2 parents 9dc2bb8 + 8c82bd6 commit 111def9
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Unit testing
# To test with act: gh act --secret-file $ENV_FILE --workflows .github/workflows/unit.yaml

on:
- push
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion component/message/en/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"app": {
"title": "Time series",
"title": "Clip time series",
"drawer_item": {
"point": "Import points",
"viz": "Visualize Points",
Expand Down
6 changes: 2 additions & 4 deletions component/scripts/export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import shutil
from pathlib import Path

import geopandas as gpd
Expand All @@ -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()

Expand Down Expand Up @@ -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")

Expand Down
28 changes: 28 additions & 0 deletions component/scripts/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import shutil
import time
from math import sqrt
from pathlib import Path
from typing import List, Union

import ee
Expand Down Expand Up @@ -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.")
5 changes: 2 additions & 3 deletions component/tile/export_tile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import shutil
import tempfile
from pathlib import Path

Expand All @@ -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):
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
init-notebook = "ui.ipynb"

[project]
version = "0.2.0"
version = "0.3.0"

[tool.ruff]
ignore-init-module-imports = true
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/test_export.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
5 changes: 3 additions & 2 deletions test/test_gee.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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():
Expand Down
6 changes: 3 additions & 3 deletions test/test_planet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import shutil
import sys

import pytest
Expand All @@ -14,6 +13,7 @@
from component.scripts.utils import (
get_buffers,
get_quad_dict,
remove_tmp_dir,
)

# Test different parameters
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 111def9

Please sign in to comment.