Skip to content

V2: setting custom global reader/writer fails #1716

@tylanderson

Description

@tylanderson

In pystac v1, StacIO was used for reading and writing, and users could define a custom StacIO class and set it as the default to be used. This was used in stactools, e.g. use_fsspec(), which inside the function would set a new default reader.

In v2, there are functions, set_default_reader()/set_default_writer() which are to be used to achieve a similar objective, but it looks like what happens is usage of this fails as functions bind to the standard DEFAULT_READER even after updating the global via set_default_reader()

Small Example:

import pystac

from pystac.reader import set_default_reader, StandardLibraryReader

class CustomReader(StandardLibraryReader):
    def get_json(self, href, **kwargs):
        print("Using CustomReader to read:", href)
        return super().get_json(href, **kwargs)

set_default_reader(reader=CustomReader())
stac_item = pystac.read_file('tests/data-files/examples/v1.1.0/collection.json')
print(stac_item.reader)
items = list(stac_item.get_items())
print(items[0].reader)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions