Skip to content

Support os.PathLike output from models#2388

Merged
aron merged 1 commit into
mainfrom
path-like-support
Jun 3, 2025
Merged

Support os.PathLike output from models#2388
aron merged 1 commit into
mainfrom
path-like-support

Conversation

@aron

@aron aron commented Jun 3, 2025

Copy link
Copy Markdown
Contributor

This commit updates two pieces of our file handling code to work with os.PathLike objects.

  1. When transforming the output into a data-structure suitable for encoding in make_encodable we convert the PathLike into a pathlib.Path instance.
  2. When reading the file data from disk in upload_files we use open() instead of Path.open().

This provides broader support for path-like objects, particularly the new replicate-python client which will return path-like objects from the new use() helper.

This commit updates two pieces of our file handling code to work
with `os.PathLike` objects.

 1. When transforming the output into a data-structure suitable for
    encoding in `make_encodable` we convert the `PathLike` into a
    `pathlib.Path` instance.
 2. When reading the file data from disk in `upload_files` we use
    `open()` instead of `Path.open()`.

This provides broader support for path-like objects, particularly
the new replicate-python client which will return path-like objects
from the new `use()` helper.
@aron
aron requested a review from 8W9aG June 3, 2025 20:09

@8W9aG 8W9aG left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great change! It seems that this was introduced in python 3.6 so should be well within our compatibility window.

@aron
aron merged commit c754874 into main Jun 3, 2025
26 checks passed
@aron
aron deleted the path-like-support branch June 3, 2025 21:17
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