Skip to content
Merged
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
9 changes: 9 additions & 0 deletions src/globato/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,6 +41,9 @@
"run",
"build",
"sources",
"dump",
"hillshade",
# "pipeline",
],
# "Tools": [
# # "cudem",
Expand Down Expand Up @@ -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__":
Expand Down
14 changes: 10 additions & 4 deletions src/globato/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)
Expand Down Expand Up @@ -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,
Expand All @@ -103,6 +108,7 @@ def build_cmd(
metadata,
export,
sources,
refresh,
):
"""Build a Digital Elevation Model recipe, and execute it."""

Expand Down Expand Up @@ -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(
Expand All @@ -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",
Expand Down
13 changes: 6 additions & 7 deletions src/globato/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand 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:
Expand All @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down Expand Up @@ -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"
Expand Down
Loading