calamari.catalog.find_files#

calamari.catalog.find_files(root, *, skip_dirs=('.git',), path_filter=None)#

Walk root recursively and return files recognised by a registered calamari.io loader, in sorted path order.

The signature check (sniff_format()) is cheap (reads only the first ~40 lines) so this is safe to run over large trees; it also never raises on an unreadable file (permission or encoding errors are treated as “not a match” by the loader registry).

Open the root before walking it, so a missing or unreadable root raises the operating system’s OSError rather than resembling an empty directory. Filesystem exceptions retain their original types (IO-5).

A subdirectory that cannot be listed does not abort the walk: one locked folder deep in a shared tree should not cost the inventory of everything else. It is not skipped silently either – files inside it are missing from the result, and a catalog quietly short of a whole run folder is exactly the failure nobody notices – so a single UserWarning after the walk names every such directory and the skip_dirs= that leaves it out knowingly.

Parameters:
  • root (Path | str) – Root directory to scan. Relative paths resolve against the current working directory, as for any file operation.

  • skip_dirs (tuple[str, ...]) – Directory names pruned from the walk wherever encountered (not just at the top level) – e.g. version-control metadata directories that may themselves contain look-alike files. Defaults to ('.git',). A pruned directory is never listed, so naming an unreadable one here also silences its warning.

  • path_filter (Callable[[Path], bool] | None) – Predicate receiving each file’s path relative to root. False excludes the file before any content probe or read. Use only path information for cheap filtering; a filename rule cannot establish scientific file role. Directories are still listed (use skip_dirs to prune them). Exceptions from the predicate propagate to the caller. Default None: probe every candidate.

Return type:

list[Path]

Returns:

list[Path] – Paths of files whose content matches a registered loader’s signature, sorted by path component (each component compared as a plain, case-sensitive string). The order is a property of the names alone, so it is the same on every machine: os.walk() yields directory-listing order, which the filesystem chooses and which is not alphabetical even on one machine, and a result indexed by position – paths[0] – would otherwise mean a different file on each. Comparing component by component keeps each directory’s contents together (run/b.dat sorts before run-2/a.dat, although '-' < '/' in a flat string sort). The sort is deliberately not “natural”: chi_10K.dat sorts before chi_2K.dat, because reading physics into a filename is a guess. Sort the measurements themselves (the *_family plot helpers order curves by their measured fixed value) when order matters.

Raises:
Warns:

UserWarning – If one or more subdirectories below root cannot be listed; they are left out and the walk continues.