Skip to content

Support pathlike objects in read_file, from_file #469

@TomAugspurger

Description

@TomAugspurger

https://www.python.org/dev/peps/pep-0519/ describes the file system path protocol. Objects like pathlib.Path implement __fspath__() to get their string representation of the path. It's nice for libraries to accept pathlike objects anywhere they accept a path.

We can do this by calling os.fspath(href) on the argument passed to read_file / from_file.

In [1]: import pathlib

In [2]: import pystac

In [3]: p = pathlib.Path("tests/data-files/examples/1.0.0/catalog.json")

In [4]: pystac.read_file(p)  # this currently raises.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions