Skip to content

Commit

Permalink
fix: change return hints
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau committed Dec 18, 2023
1 parent 863b5e7 commit 7e44f1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pytest_gee/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import uuid
from pathlib import PurePosixPath
from pathlib import Path

import ee
import pytest
Expand All @@ -19,7 +19,7 @@ def gee_hash():
@pytest.fixture(scope="session")
def gee_folder_root():
"""Link to the root folder of the connected account."""
return PurePosixPath(ee.data.getAssetRoots()[0]["id"])
return Path(ee.data.getAssetRoots()[0]["id"])


@pytest.fixture(scope="session")
Expand Down
19 changes: 11 additions & 8 deletions pytest_gee/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_task(task_descripsion: str) -> Optional[ee.batch.Task]:
return task


def get_assets(folder: Union[str, PurePosixPath]) -> List[dict]:
def get_assets(folder: Union[str, Path]) -> List[dict]:
"""Get all the assets from the parameter folder. every nested asset will be displayed.
Args:
Expand All @@ -71,7 +71,7 @@ def get_assets(folder: Union[str, PurePosixPath]) -> List[dict]:
"""
# set the folder and init the list
asset_list: list = []
folder = str(folder)
folder = folder if isinstance(folder, str) else folder.as_posix()

# recursive function to get all the assets
def _recursive_get(folder, asset_list):
Expand All @@ -85,7 +85,7 @@ def _recursive_get(folder, asset_list):


def export_asset(
object: ee.ComputedObject, asset_id: Union[str, PurePosixPath], description: str
object: ee.ComputedObject, asset_id: Union[str, Path], description: str
) -> PurePosixPath:
"""Export assets to the GEE platform, only working for very simple objects.
Expand All @@ -97,18 +97,21 @@ def export_asset(
Returns:
the path of the created asset
"""
# convert the asset_id to a string note that GEE only supports unix style separator
asset_id = asset_id if isinstance(asset_id, str) else asset_id.as_posix()

if isinstance(object, ee.FeatureCollection):
task = ee.batch.Export.table.toAsset(
collection=object,
description=description,
assetId=str(asset_id),
assetId=asset_id,
)
elif isinstance(object, ee.Image):
task = ee.batch.Export.image.toAsset(
region=object.geometry(),
image=object,
description=description,
assetId=str(asset_id),
assetId=asset_id,
)
else:
raise ValueError("Only ee.Image and ee.FeatureCollection are supported")
Expand All @@ -120,7 +123,7 @@ def export_asset(
return PurePosixPath(asset_id)


def init_tree(structure: dict, prefix: str, root: str) -> Path:
def init_tree(structure: dict, prefix: str, root: str) -> PurePosixPath:
"""Create an EarthEngine folder tree from a dictionary.
The input ditionary should described the structure of the folder you want to create.
Expand Down Expand Up @@ -166,7 +169,7 @@ def _recursive_create(structure, prefix, folder):
return PurePosixPath(root_folder)


def delete_assets(asset_id: Union[str, PurePosixPath], dry_run: bool = True) -> list:
def delete_assets(asset_id: Union[str, Path], dry_run: bool = True) -> list:
"""Delete the selected asset and all its content.
This method will delete all the files and folders existing in an asset folder.
Expand All @@ -185,7 +188,7 @@ def delete_assets(asset_id: Union[str, PurePosixPath], dry_run: bool = True) ->
a list of all the files deleted or to be deleted
"""
# convert the asset_id to a string
asset_id = str(asset_id)
asset_id = asset_id if isinstance(asset_id, str) else asset_id.as_posix()

# define a delete function to change the behaviour of the method depending of the mode
# in dry mode, the function only store the assets to be destroyed as a dictionary.
Expand Down

0 comments on commit 7e44f1f

Please sign in to comment.