Skip to content

Find local WFDB records with an explicit search path - #824

Merged
tompollard merged 3 commits into
mainfrom
feature/find-record-search-path
Dec 1, 2026
Merged

tompollard merged 3 commits into
mainfrom
feature/find-record-search-path

Conversation

@tompollard

@tompollard tompollard commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add wfdb.find_record() to locate a record header or local .wfdb archive in an ordered list of directories and return its absolute path.
  • Add wfdb.wfdb_search_path() so callers can explicitly use simple local directories from the WFDB environment variable.
  • Document the opt-in workflow and add tests for ordering, nested records, archives, path errors, and environment parsing.

This does not change how read_record or other readers resolve a path. The helper only locates a header or archive; signal files must still be readable relative to the header. The C library's URL entries, whitespace separators, and indirect path files are outside this local-only helper's scope.

Addresses #545.

Checks

  • 8 focused tests passed.
  • Ruff lint and formatting passed.
  • Strict Sphinx HTML build passed.

This PR will be included in 5.12.0. Merge it before #823, then update the
5.12.0 release notes to include this change.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Keeping this opt-in fits the "no automatic fallback" rule well. find_record returns absolute stems and archive paths that work directly with read_record, search order and dotted names behave, invalid inputs fail clearly, and the not-found error lists every directory searched. The offline suite, Ruff and the strict docs build pass locally. (The one CI failure is the Python 3.11 job's Install libsndfile step, before tests ran, so a re-run should clear it.)

One thing to fix: the WFDB C tools commonly separate path entries with whitespace (their docs use WFDB=". /usr/local/database"), and wfdb_search_path() treats such a value as a single directory named ". /usr/local/database". find_record then reports "not found", which hides the real cause. @file and URLs already raise a clear ValueError. Could an entry that contains whitespace and isn't an existing directory raise one too, saying that whitespace-separated entries aren't supported and to use os.pathsep or pass directories explicitly? Directories that genuinely contain spaces (like "my records" in the test) would still work, and a test with ". <dir>" would cover it.

Minor: when a directory has both 100.hea and 100.wfdb, the header wins, which is worth a sentence in the docs. search_path=b"/tmp" gives a cryptic not int error; adding bytes to the bare-string check would give the clear message.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks. I addressed these in cc92a60. wfdb_search_path() now raises a clear ValueError for a whitespace-containing component that is not an existing directory, while accepting existing directories whose names contain spaces. I added the ".

" regression test. find_record() also gives a clear TypeError for a bare bytes search_path, and the docs now say that a .hea file wins over a .wfdb archive in the same directory. The 9 focused tests, Ruff, and the strict docs build pass locally. The failed Linux CI job stopped during libsndfile installation, before tests ran; I will rerun it if needed after the workflow finishes.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, cc92a60 covers everything. A C-style WFDB=". <dir>" now raises the clear whitespace message, while an existing directory with a space in its name (my records) still works through os.pathsep. search_path=b"/tmp" and [b"/tmp"] give clear TypeErrors, and the header-before-archive precedence is documented and tested. The full offline suite, Ruff and the strict docs build pass locally.

Ready to merge once CI is green (and after #823, as noted in the description).

@tompollard
tompollard merged commit 7fa86a5 into main Dec 1, 2026
19 checks passed
@tompollard
tompollard deleted the feature/find-record-search-path branch December 1, 2026 05:14
tompollard added a commit that referenced this pull request Dec 1, 2026
## Summary

#824 merged just before the 5.12.0 release PR, so its changelog fragment
is still in `changelog.d/`. Move that entry into the 5.12.0 section and
mention explicit local record search in the release summary. This
ensures the published release notes describe all code in 5.12.0.

## Checks

- Strict Sphinx HTML build passed.
- `git diff --check` passed.

Merge before creating GitHub release `v5.12.0`.
@tompollard tompollard mentioned this pull request Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant