gwforg / gwf

A flexible, pragmatic workflow tool.
https://gwf.app/
GNU General Public License v3.0
31 stars 12 forks source link

Support PathLib paths in targets #410

Open simondrue opened 5 months ago

simondrue commented 5 months ago

When I try to use a Path from pathlib for inputs/outputs in a target I get the following error message:

File "/home/simond/miniconda3/lib/python3.9/site-packages/gwf/workflow.py", line 257, in target_from_template
    new_target = Target(
  File "<attrs generated init gwf.core.Target>", line 17, in __init__
  File "/home/simond/miniconda3/lib/python3.9/site-packages/gwf/core.py", line 197, in _validate_path
    _check_path(path)
  File "/home/simond/miniconda3/lib/python3.9/site-packages/gwf/core.py", line 58, in _check_path
    result = _has_nonprintable_char(path)
  File "/home/simond/miniconda3/lib/python3.9/site-packages/gwf/core.py", line 39, in _has_nonprintable_char
    chars = enumerate((unicodedata.category(char) == "Cc", char) for char in s)
TypeError: 'PosixPath' object is not iterable

The problem is that Path from pathlib do not support iteration as shown here:

>>> from pathlib import Path
>>> a = Path("/foo/bar")
>>> [c for c in a]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'PosixPath' object is not iterable

It would be really nice if GWF was to support pathlib

Thanks for a great tool 😃

dansondergaard commented 3 weeks ago

I'll take a look at this for the next release.