diff --git a/src/globato/cli/__init__.py b/src/globato/cli/__init__.py index 824e7d2..d329c68 100644 --- a/src/globato/cli/__init__.py +++ b/src/globato/cli/__init__.py @@ -23,7 +23,10 @@ # from .run import run_cmd from .build import build_cmd from .sources import sources_group +from .pointz import dump +from .perspecto import perspecto_hillshade from fetchez.cli.recipes import run_recipe +# from fetchez.cli.pipeline import pipeline_group from fetchez.cli import setup_logging from fetchez.utils import FetchezMainGroup @@ -38,6 +41,9 @@ "run", "build", "sources", + "dump", + "hillshade", + # "pipeline", ], # "Tools": [ # # "cudem", @@ -79,6 +85,9 @@ def cli(verbose, quiet): # cli.add_command(perspecto_group, name="perspecto") cli.add_command(sources_group, name="sources") cli.add_command(run_recipe, name="run") +cli.add_command(dump, name="dump") +cli.add_command(perspecto_hillshade, name="hillshade") +# cli.add_command(pipeline_group, name="pipeline") if __name__ == "__main__": diff --git a/src/globato/cli/build.py b/src/globato/cli/build.py index 8ef093d..2e32f28 100644 --- a/src/globato/cli/build.py +++ b/src/globato/cli/build.py @@ -44,7 +44,8 @@ @click.option( "-D", "--outdir", - type=click.Path(resolve_path=True), + # type=click.Path(resolve_path=True), + type=click.Path(), default=None, help="Base output directory.", ) @@ -77,11 +78,15 @@ ) @click.option( "--shared-cache", - type=click.Path(resolve_path=True), + # type=click.Path(resolve_path=True), + type=click.Path(), help="Centralized cache directory.", ) @click.option("--metadata", help="Global tags to inject.") @click.option("--export", is_flag=True, help="Save the generated YAML recipe to disk.") +@click.option( + "--refresh", is_flag=True, help="Force fresh API fetch, bypassing local cache." +) @click.argument("sources", nargs=-1) def build_cmd( region, @@ -103,6 +108,7 @@ def build_cmd( metadata, export, sources, + refresh, ): """Build a Digital Elevation Model recipe, and execute it.""" @@ -345,7 +351,7 @@ def build_cmd( # --- Export or Execute --- if export: os.makedirs(base_outdir, exist_ok=True) - out_yaml = os.path.join(base_outdir, f"{outname}_recipe.yaml") + out_yaml = os.path.join(os.getcwd(), f"{outname}_recipe.yaml") with open(out_yaml, "w") as f: yaml.dump(config, f, sort_keys=False) click.secho( @@ -358,7 +364,7 @@ def build_cmd( recipe = Recipe.from_dict(config) # Fetchez handles all directory switching, batching, and execution - recipe.run(outdir=base_outdir, shared_cache=shared_cache) + recipe.run(outdir=outdir, shared_cache=shared_cache, refresh=refresh) click.secho( "✨ Successfully completed Globato build pipeline!", fg="green", diff --git a/src/globato/utils.py b/src/globato/utils.py index e9195f5..a6e5eca 100644 --- a/src/globato/utils.py +++ b/src/globato/utils.py @@ -152,7 +152,7 @@ def add_field_to_recarray(rec, name, dtype, default_val): # --- Source and Hook parsing --- def globatize_modules(modules, shared_cache=None, crs=None, res=None): - abs_cache = os.path.abspath(shared_cache) if shared_cache else None + cache_dir = shared_cache ModuleRegistry.load_all() BundleRegistry.load_all() @@ -164,8 +164,8 @@ def globatize_modules(modules, shared_cache=None, crs=None, res=None): hooks = mod.setdefault("hooks", []) # -- Shared Cache Directory -- - if abs_cache and mod.get("module") not in ["file", "local_fs", "stdin"]: - mod.setdefault("args", {})["outdir"] = abs_cache + if cache_dir and mod.get("module") not in ["file", "local_fs", "stdin"]: + mod.setdefault("args", {})["outdir"] = cache_dir # --- Insert the target crs into stream-reproject etc. --- if crs: @@ -177,15 +177,14 @@ def globatize_modules(modules, shared_cache=None, crs=None, res=None): if reproject_hook: reproject_hook.setdefault("args", {})["dst_srs"] = crs - if abs_cache: - reproject_hook.setdefault("args", {})["cache_dir"] = abs_cache + if cache_dir: + reproject_hook.setdefault("args", {})["cache_dir"] = cache_dir else: hooks.insert( 0, { "name": "stream_reproject", - "args": {"dst_srs": crs}, - "cache_dir": abs_cache, + "args": {"dst_srs": crs, "cache_dir": cache_dir}, }, ) else: diff --git a/tests/test_cli.py b/tests/test_cli.py index 927838e..85d42cb 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -32,6 +32,8 @@ def test_cli_base_help(runner): "build", "run", "sources", + "hillshade", + "dump", ] for cmd in expected_commands: assert cmd in result.output, f"Missing '{cmd}' command in CLI help!" @@ -60,10 +62,10 @@ def test_recipe_build_save_only(runner): assert result.exit_code == 0 assert "Globato recipe exported to" in result.output - assert "test_dem/test_dem_recipe.yaml" in result.output - assert os.path.exists("test_dem/test_dem_recipe.yaml") + assert "test_dem_recipe.yaml" in result.output + assert os.path.exists("test_dem_recipe.yaml") - with open("test_dem/test_dem_recipe.yaml", "r") as f: + with open("test_dem_recipe.yaml", "r") as f: config = yaml.safe_load(f) assert config["project"]["name"] == "test_dem"