pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.9k stars 381 forks source link

`files.put()` does not accept `pathlib.Path` #1219

Open NedJWestern opened 3 weeks ago

NedJWestern commented 3 weeks ago

Describe the bug

A clear and concise description of what the bug is.

files.put() breaks when dest is a pathlib.Path instead of a string. I understand that a string is expected here, but this is not explicitly stated in the docs. Adding datatypes to all of the docs would be ideal.

To Reproduce

Steps to reproduce the behavior, please include where possible:

import os
from pathlib import Path
from pyinfra.operations import files

files.put(
    src="foo.txt",
    dest=Path("/data") / "tmp/",
)

Error output:

--> An internal exception occurred:

  File "/data/home/su_nwestern/repos/pkg_pyinfra/pyinfra/pyinfra/operations/util/files.py", line 11, in <listcomp>
    part_list[0:-1] = [part.rstrip("/") for part in part_list[0:-1]]
      ^^^^^^^^^^^^^^^^^
AttributeError: 'PosixPath' object has no attribute 'rstrip'

Expected behavior

A clear and concise description of what you expected to happen.

Behave the same as if dest was a string

Meta

simonhammes commented 1 day ago

I've opened #1227 to address the docs part of this issue.

Accepting pathlib.Path can be handled later on :+1: