From d43385ce00ab7875213a87ebe9fc207563488ddb Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Mon, 9 Dec 2024 08:32:55 +0000 Subject: [PATCH 1/3] fix: drop the use of pkg_resources --- geemap/conversion.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/geemap/conversion.py b/geemap/conversion.py index e5ca2fbbc8..f8af61bef5 100644 --- a/geemap/conversion.py +++ b/geemap/conversion.py @@ -20,8 +20,6 @@ from collections import deque from pathlib import Path -import pkg_resources - from .common import * @@ -913,20 +911,19 @@ def get_js_examples(out_dir=None): Returns: str: The folder containing the JavaScript examples. """ - pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py")) - example_dir = os.path.join(pkg_dir, "data") - js_dir = os.path.join(example_dir, "javascripts") + pkg_dir = Path(__file__).parent + example_dir = pkg_dir / "data" + js_dir = example_dir / "javascripts" - files = list(Path(js_dir).rglob("*.js")) + files = list(js_dir.rglob("*.js")) if out_dir is None: out_dir = js_dir else: - if not os.path.exists(out_dir): - os.makedirs(out_dir) + if not out_dir.exists(): + out_dir.mkdir(parent=True) for file in files: - basename = os.path.basename(file) - out_path = os.path.join(out_dir, basename) + out_path = out_dor / file.name shutil.copyfile(file, out_path) return out_dir @@ -942,20 +939,17 @@ def get_nb_template(download_latest=False, out_file=None): Returns: str: The file path of the template. """ - pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py")) - example_dir = os.path.join(pkg_dir, "data") - template_dir = os.path.join(example_dir, "template") - template_file = os.path.join(template_dir, "template.py") + pkg_dir = Path(__file__).parent + example_dir = pkg_dir / "data" + template_dir = example_dir / "template" + template_file = template_dir / "template.py" if out_file is None: out_file = template_file return out_file - if not out_file.endswith(".py"): - out_file = out_file + ".py" - - if not os.path.exists(os.path.dirname(out_file)): - os.makedirs(os.path.dirname(out_file)) + out_file = out_file.with_suffix(".py") + outfile.parent.mkdir(parents=True, exist_ok=True) if download_latest: template_url = "https://raw.githubusercontent.com/gee-community/geemap/master/examples/template/template.py" From 13ea9e311097f01c8ad9f5034748e9bc5c3de9f4 Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:46:07 +0100 Subject: [PATCH 2/3] refactor: use a 1-liner --- geemap/conversion.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/geemap/conversion.py b/geemap/conversion.py index f8af61bef5..372df8e730 100644 --- a/geemap/conversion.py +++ b/geemap/conversion.py @@ -919,8 +919,7 @@ def get_js_examples(out_dir=None): if out_dir is None: out_dir = js_dir else: - if not out_dir.exists(): - out_dir.mkdir(parent=True) + out_dir.mkdir(parent=True, exist_ok=True) for file in files: out_path = out_dor / file.name From 9840b9445ebadba934a781881ab65e812d87c99d Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:46:20 +0100 Subject: [PATCH 3/3] fix: typo --- geemap/conversion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geemap/conversion.py b/geemap/conversion.py index 372df8e730..889cfed614 100644 --- a/geemap/conversion.py +++ b/geemap/conversion.py @@ -922,7 +922,7 @@ def get_js_examples(out_dir=None): out_dir.mkdir(parent=True, exist_ok=True) for file in files: - out_path = out_dor / file.name + out_path = out_dir / file.name shutil.copyfile(file, out_path) return out_dir