uwefladrich/scriptengine

shutil does not always accept path-like objects

Closed this issue · 3 comments

When using pathlib to handle files etc in the base file tasks, the objects cannot always be passed to shutil functions. This is, for example, a problem for shutil.move, which does not accept path-like objects. This means that base.move is broken.

The solution is either to use pathlib functions, where possible, or to convert path-like objects to strings before passing them to shutil.*.

shutil.move accepts path-like objects, but only from version 3.9 on.
shutil.copy is documented to accept path-like src and dst.

Turns out that pathlib.Path.rename() does not handle directory destinations in the same way as shutil.move(). Hence, ee38815 does not really solve the problem for this task.