diff --git a/.gitignore b/.gitignore index 60e98db..4a393b8 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ geotessera_vis.png .venv build/ repomix-* +*.err +.pytest_cache/ \ No newline at end of file diff --git a/geotessera/tiles.py b/geotessera/tiles.py index c7ebaab..c40ad82 100644 --- a/geotessera/tiles.py +++ b/geotessera/tiles.py @@ -327,6 +327,7 @@ def discover_tiles(directory: Path) -> List[Tile]: embeddings_dir = directory / EMBEDDINGS_DIR_NAME if embeddings_dir.exists() and embeddings_dir.is_dir(): # Check if there are any .npy files (not just _scales.npy) + # The actual pattern validation happens in discover_npy_tiles() npy_files = [ f for f in embeddings_dir.rglob("*.npy") @@ -374,6 +375,10 @@ def discover_npy_tiles(base_dir: Path) -> List[Tile]: tiles.append(tile) else: logging.warning(f"Skipping incomplete tile: {npy_file}") + except ValueError: + # Skip files that don't match expected filename pattern + # ValueError is raised by _parse_npy_filename when pattern doesn't match + continue except Exception as e: logging.warning(f"Failed to load tile {npy_file}: {e}") @@ -402,6 +407,10 @@ def discover_geotiff_tiles(directory: Path) -> List[Tile]: try: tile = Tile.from_geotiff(geotiff_file) tiles.append(tile) + except ValueError: + # Skip files that don't match expected filename pattern + # ValueError is raised by _parse_geotiff_filename when pattern doesn't match + continue except Exception as e: logging.warning(f"Failed to load tile {geotiff_file}: {e}") @@ -427,6 +436,10 @@ def discover_zarr_tiles(directory: Path) -> List[Tile]: try: tile = Tile.from_zarr(zarr_file) tiles.append(tile) + except ValueError: + # Skip files that don't match expected filename pattern + # ValueError is raised by _parse_zarr_filename when pattern doesn't match + continue except Exception as e: logging.warning(f"Failed to load tile {zarr_file}: {e}") diff --git a/tests/cli.t b/tests/cli.t index 5d257aa..dcf8f8f 100644 --- a/tests/cli.t +++ b/tests/cli.t @@ -185,3 +185,19 @@ Test that re-running the NPY download skips existing files: > --dataset-version v1 2>&1 | grep -E '(Skipped|existing files)' Skipped 48 existing files (resume capability) +Test: Tile Discovery Ignores Temporary Files +--------------------------------------------- + +Test that temporary files left from interrupted downloads are silently ignored. +Create temporary files manually in the NPY tiles directory to simulate interrupted downloads: + + $ touch "$TESTDIR/uk_tiles_npy/global_0.1_degree_representation/2024/.grid_0.05_51.25.npy_tmp_abc123" + $ touch "$TESTDIR/uk_tiles_npy/global_0.1_degree_representation/2024/.grid_0.05_51.35_tmp_xyz789.npy" + $ touch "$TESTDIR/uk_tiles_npy/global_0.1_degree_representation/2024/invalid_file.npy" + +Verify that the info command still works correctly and doesn't show warnings about temp files. +The tile count should remain 16 (unchanged) and no warnings should appear in stderr: + + $ uv run -m geotessera.cli info --tiles "$TESTDIR/uk_tiles_npy" 2>&1 | grep -E '(Total tiles|WARNING|Failed to load|Cannot parse)' + Total tiles: 16 +