8000 Automatically coerce string/PathLike objects to File/Directory objects when passed to Any-typed fields · Issue #816 · nipype/pydra · GitHub
[go: up one dir, main page]

Skip to content

Automatically coerce string/PathLike objects to File/Directory objects when passed to Any-typed fields #816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tclose opened this issue Apr 29, 2025 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@tclose
Copy link
Contributor
tclose commented Apr 29, 2025

I'm not 100% on this, but think it is probably a good idea. When using properly typed tasks, if you pass a string to a File/Directory-typed field, it will be coerced to a fileformats object and then properly checked for existence/format and have its contents hashed. However, if you don't type your task and just leave the field as typing.Any, the string representing the file path will be just treated as a string and the node won't be rerun if its contents change.

To avoid this, for typing.Any-typed fields, we could check all strings and see if they correspond to an existing file path, and if so implicitly convert it to a File/Directory object before passing it the task, in which its contents will be hashed when building the task checksum.

@tclose tclose converted this from a draft issue Apr 29, 2025
@tclose tclose added the enhancement New feature or request label Apr 29, 2025
@tclose tclose moved this from Proposed to temp in Pydra Roadmap Apr 29, 2025
@tclose tclose moved this from temp to To do (v1.0) in Pydra Roadmap Apr 29, 2025
@tclose tclose moved this from Triage to v1.1-v1.2 in Pydra Roadmap May 28, 2025
@tclose tclose moved this from v1.1-v1.2 to v1.0 in Pydra Roadmap May 28, 2025
@tclose tclose self-assigned this May 28, 2025
@tclose
Copy link
Contributor Author
tclose commented Jun 2, 2025

Probably, we don't want to actually coerce the object, just treat it as a file during the hash and but still pass a string

@tclose
Copy link
Contributor Author
tclose commented Jun 2, 2025

We could list the names of fields with implicitly defined Any types in a _implicitly_typed_fields and then use this during the checksum function to do the implicit conversion to File during the hash calculation.

Alternatively, we could use our own Untyped type to signify fields that haven't been explicitly typed Any

@tclose
Copy link
Contributor Author
tclose commented Jun 2, 2025

Requirements

  • Strings that look like paths (i.e. have path separator or '.' and point to an existing file/directory)
  • Passed to an untyped field
  • Treated as FsObject during hash
  • Still passed as str objects to the function

Nice to have

  • Be fairly simple for compose designers to include for their language

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: v1.0
Development

No branches or pull requests

1 participant
0