Skip to content
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

files.put() - incompatibility when src is StringIO and dest is a directory #1144

Open
rsyring opened this issue Jul 13, 2024 · 0 comments
Open
Labels
bug Label for all kind of bugs. operations Issues with operations.

Comments

@rsyring
Copy link

rsyring commented Jul 13, 2024

I was using file.put() with a directory destination and switched it to a file.template(). That resulted in the following traceback:

  File "/home/rsyring/.local/pipx/venvs/kilo/lib/python3.11/site-packages/pyinfra/operations/files.py", line 938, in put
    dest = unix_path_join(dest, os.path.basename(src))
                                ^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 142, in basename
TypeError: expected str, bytes or os.PathLike object, not StringIO

Once I figured out what was going on, the fix was to specify the dest as a file path, which makes sense.

Requests:

  1. A better error message indicating the root problem, i.e. "When using IO-like object for src a directory can not be used as the dest."
  2. Maybe not worth the effort, but when using files.template() and the dest is a directory, source the file name from the src file and add that to the dest before calling files.put(). Removing '.j2' or '.jinja' if present on the src filename.
@Fizzadar Fizzadar added bug Label for all kind of bugs. operations Issues with operations. labels Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Label for all kind of bugs. operations Issues with operations.
Projects
None yet
Development

No branches or pull requests

2 participants