Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions ee_extra/JavaScript/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
a JavaScript Earth Enginemodule.
"""

import pathlib
from pathlib import Path
import re
import urllib.request

from importlib.resources import files


def _convert_path_to_ee_sources(path: str) -> str:
"""Get the remote module path from the 'ee-sources' GCS bucket.
Expand All @@ -32,7 +30,7 @@ def _get_ee_sources_path() -> str:
Returns:
The ee-sources folder path.
"""
pkgdir = files("ee_extra").parent
pkgdir = Path(__file__).parents[1]
return str(pkgdir / "ee-sources")


Expand All @@ -46,16 +44,16 @@ def _convert_path_to_ee_extra(path: str) -> str:
An ee_extra modules path.
"""
if path.startswith("http"):
ee_extra_path = pathlib.Path(_get_ee_sources_path()).joinpath(
"EXTERNAL_" + pathlib.Path(path).stem + "/" + pathlib.Path(path).name
ee_extra_path = Path(_get_ee_sources_path()).joinpath(
"EXTERNAL_" + Path(path).stem + "/" + Path(path).name
)
else:
if path.endswith(".js"):
ee_extra_path = pathlib.Path(_get_ee_sources_path()).joinpath(
ee_extra_path = Path(_get_ee_sources_path()).joinpath(
path.replace(":", "/")
)
else:
ee_extra_path = pathlib.Path(_get_ee_sources_path()).joinpath(
ee_extra_path = Path(_get_ee_sources_path()).joinpath(
path.replace(":", "/") + ".js"
)
return ee_extra_path
Expand All @@ -70,7 +68,7 @@ def _check_if_module_exists(path: str) -> bool:
Returns:
Whether the module has been installed.
"""
return pathlib.Path(_convert_path_to_ee_extra(path)).exists()
return Path(_convert_path_to_ee_extra(path)).exists()


def _open_module_as_str(path: str) -> str:
Expand Down Expand Up @@ -138,11 +136,11 @@ def _install(x: str, update: bool, quiet: bool = False):

# Local path
if x.startswith("http"):
module_folder = pathlib.Path(ee_sources).joinpath(
"EXTERNAL/" + pathlib.Path(x).stem
module_folder = Path(ee_sources).joinpath(
"EXTERNAL/" + Path(x).stem
)
else:
module_folder = pathlib.Path(ee_sources).joinpath(
module_folder = Path(ee_sources).joinpath(
"/".join(x.replace(":", "/").split("/")[:-1])
)

Expand Down
5 changes: 2 additions & 3 deletions ee_extra/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import difflib
import json
from typing import Any, Optional, List, Sequence

from importlib.resources import files
from pathlib import Path

import ee

Expand All @@ -16,7 +15,7 @@ def _load_JSON(x: Optional[str] = "ee-catalog-ids.json") -> Any:
Returns:
JSON file.
"""
data_file = files("ee_extra.data") / x
data_file = Path(__file__).parent / "data" / x
with data_file.open("r", encoding="utf-8") as f:
return json.load(f)

Expand Down
Loading