Open rsyring opened 3 months ago
An assert
statement was added as part of #1082:
The following code now causes an AssertionError:
from pyinfra.operations import files
files.template(name='Template', src='template.j2', dest='/tmp')
However, the error message could (or should, imho) certainly be improved.
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 What is your take on that? Makes sense or is that a bit too much "magic"?
I was using
file.put()
with a directory destination and switched it to afile.template()
. That resulted in the following traceback:Once I figured out what was going on, the fix was to specify the dest as a file path, which makes sense.
Requests:
src
a directory can not be used as thedest
."files.template()
and the dest is a directory, source the file name from the src file and add that to the dest before callingfiles.put()
. Removing '.j2' or '.jinja' if present on the src filename.