Skip to content

Support PathLib paths in targets #410

Open
@simondrue

Description

@simondrue

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 😃

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions