Skip to content

Commit f50c712

Browse files
committed
Merge remote-tracking branch 'origin/copilot/fix-tmp-tiles-discovery' into fix-tmp-tiles
2 parents 8ddd708 + e955f72 commit f50c712

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ geotessera_vis.png
2828
.venv
2929
build/
3030
repomix-*
31+
*.err
32+
.pytest_cache/

geotessera/tiles.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def discover_tiles(directory: Path) -> List[Tile]:
327327
embeddings_dir = directory / EMBEDDINGS_DIR_NAME
328328
if embeddings_dir.exists() and embeddings_dir.is_dir():
329329
# Check if there are any .npy files (not just _scales.npy)
330+
# The actual pattern validation happens in discover_npy_tiles()
330331
npy_files = [
331332
f
332333
for f in embeddings_dir.rglob("*.npy")
@@ -374,6 +375,10 @@ def discover_npy_tiles(base_dir: Path) -> List[Tile]:
374375
tiles.append(tile)
375376
else:
376377
logging.warning(f"Skipping incomplete tile: {npy_file}")
378+
except ValueError:
379+
# Skip files that don't match expected filename pattern
380+
# ValueError is raised by _parse_npy_filename when pattern doesn't match
381+
continue
377382
except Exception as e:
378383
logging.warning(f"Failed to load tile {npy_file}: {e}")
379384

@@ -402,6 +407,10 @@ def discover_geotiff_tiles(directory: Path) -> List[Tile]:
402407
try:
403408
tile = Tile.from_geotiff(geotiff_file)
404409
tiles.append(tile)
410+
except ValueError:
411+
# Skip files that don't match expected filename pattern
412+
# ValueError is raised by _parse_geotiff_filename when pattern doesn't match
413+
continue
405414
except Exception as e:
406415
logging.warning(f"Failed to load tile {geotiff_file}: {e}")
407416

@@ -427,6 +436,10 @@ def discover_zarr_tiles(directory: Path) -> List[Tile]:
427436
try:
428437
tile = Tile.from_zarr(zarr_file)
429438
tiles.append(tile)
439+
except ValueError:
440+
# Skip files that don't match expected filename pattern
441+
# ValueError is raised by _parse_zarr_filename when pattern doesn't match
442+
continue
430443
except Exception as e:
431444
logging.warning(f"Failed to load tile {zarr_file}: {e}")
432445

tests/cli.t

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,19 @@ Test that re-running the NPY download skips existing files:
185185
> --dataset-version v1 2>&1 | grep -E '(Skipped|existing files)'
186186
Skipped 48 existing files (resume capability)
187187

188+
Test: Tile Discovery Ignores Temporary Files
189+
---------------------------------------------
190+
191+
Test that temporary files left from interrupted downloads are silently ignored.
192+
Create temporary files manually in the NPY tiles directory to simulate interrupted downloads:
193+
194+
$ touch "$TESTDIR/uk_tiles_npy/global_0.1_degree_representation/2024/.grid_0.05_51.25.npy_tmp_abc123"
195+
$ touch "$TESTDIR/uk_tiles_npy/global_0.1_degree_representation/2024/.grid_0.05_51.35_tmp_xyz789.npy"
196+
$ touch "$TESTDIR/uk_tiles_npy/global_0.1_degree_representation/2024/invalid_file.npy"
197+
198+
Verify that the info command still works correctly and doesn't show warnings about temp files.
199+
The tile count should remain 16 (unchanged) and no warnings should appear in stderr:
200+
201+
$ uv run -m geotessera.cli info --tiles "$TESTDIR/uk_tiles_npy" 2>&1 | grep -E '(Total tiles|WARNING|Failed to load|Cannot parse)'
202+
Total tiles: 16
203+

0 commit comments

Comments
 (0)