Skip to content

Harden path-handling after pathlib migration - #3421

Merged
deruyter92 merged 9 commits into
mainfrom
jaap/pathlib-hardening
Jul 21, 2026
Merged

Harden path-handling after pathlib migration#3421
deruyter92 merged 9 commits into
mainfrom
jaap/pathlib-hardening

Conversation

@deruyter92

Copy link
Copy Markdown
Collaborator

Summary

Follow-up of #3350 (migration to pathlib Path), after auditing for remaining fragile patterns. This PR hardens the codebase against Path/str type confusion. Catches fragile patterns that work today but could silently break if types shift.

Changes

  • Fixed Path + str TypeErrorproject_path + "_bak" at a live call
    site (was in dead code, but now safe regardless).
  • Hardened cfg["init_weights"] usage — the two places that concatenated
    strings onto it now use Path.with_suffix() instead.
  • Eliminated _robust_path_split (trainingsetmanipulation) and
    robust_split_path (conversioncode) — both were pre-pathlib relics that
    split strings on / or \ only to immediately re-join via Path(*). All
    callers now use Path().stem or Path() directly.
  • Simplified guarantee_multiindex_rows — dropped the fragile
    single-row heuristic ("/" in path[0]) for a consistent
    normalize-then-split approach.
  • Deprecated grab_files_in_folder — replaced all internal callers with
    collect_video_paths, added @deprecated decorator.
  • Migrated save_data, check_if_not_analyzed, _convert_h5_files_to
    from string-path operations to pathlib (.stem, .with_suffix,
    .with_name, .removeprefix).
  • Removed redundant Path() wraps where variables were already Path,
    and removed str() conversions where Path is accepted natively.

@deruyter92 deruyter92 changed the title Address remaining Path / Harden path-handling after pathlib migration Jul 20, 2026
@deruyter92
deruyter92 changed the base branch from main to cy/config-gui-error-handler July 20, 2026 15:57
@deruyter92
deruyter92 force-pushed the jaap/pathlib-hardening branch from 7be1695 to 16c9c18 Compare July 20, 2026 15:58
@deruyter92 deruyter92 mentioned this pull request Jul 20, 2026
9 tasks
@MMathisLab
MMathisLab self-requested a review July 21, 2026 02:13
Base automatically changed from cy/config-gui-error-handler to main July 21, 2026 06:42
The old code checks only the first row (df.index[0]) to decide whether to split on / or \, then applies that one separator to the entire DataFrame.

The new approach normalizes all backslashes to forward slashes first, then splits. So mixed-separator DataFrames (e.g. cross platform merges) work correctly.
…athlib `Path`

- Deprecate `grab_files_in_folder` (replaced by `collect_video_paths`)
- Replace all internal callers with `collect_video_paths`
- Migrate `check_if_not_analyzed`, `save_data`, `_convert_h5_files_to`,
  and `find_analyzed_data` from `str`-based path ops to pathlib (.stem,
  .with_suffix, .with_name, .removeprefix)
- Remove redundant `Path()` wraps and `str()` conversions at call sites
@deruyter92
deruyter92 force-pushed the jaap/pathlib-hardening branch from 92cdc1a to 0a9bbbc Compare July 21, 2026 06:48
@deruyter92
deruyter92 force-pushed the jaap/pathlib-hardening branch from 5f81296 to ece7c7d Compare July 21, 2026 10:15
@deruyter92
deruyter92 force-pushed the jaap/pathlib-hardening branch from ece7c7d to 849644a Compare July 21, 2026 10:51
@deruyter92
deruyter92 merged commit f6b0eff into main Jul 21, 2026
31 checks passed
@deruyter92
deruyter92 deleted the jaap/pathlib-hardening branch July 21, 2026 15:54
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.

2 participants