Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add base classes from rio-tiler-pds #273

Merged
merged 2 commits into from
Oct 2, 2020
Merged

Conversation

vincentsarago
Copy link
Member

This PR moves base classes from rio-tiler-pds to rio-tiler

ref: cogeotiff/rio-tiler-pds#24

def __exit__(self, exc_type, exc_value, traceback):
"""Support using with Context Managers."""
pass

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geospatial-jeff I know we agreed to removes those (done in #271) But after some though I think it's not a great Idea.

The main reason to remove those was to ease the use for Async but I do feel using BaseReader is not the way forward for this and we should create a AsyncBaseReader).

The major problem by not having ctx has a requirement is that a user could create a Reader without them but then it won't be able to use it in most of our other project that use with reader() as ...

Copy link
Member

@geospatial-jeff geospatial-jeff Oct 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a separate AsyncBaseReader here. Thinking through this again I agree that these should be here. Its standard to have post init logic in __init__ and keep context managers simple. But because there is no way to execute asynchronous code within __init__ we have to run post init logic in __aenter__ and __aexit__ for the async base class. Note these methods aren't present on the implementation linked above but they should be.

So if we are requiring the async base to be a context manager the sync base should also be to keep the interfaces consistent. I guess there is one difference; the async base won't be usable outside the context manager, but we could provide a class method which people could call that wraps any post-init logic.

reader = await AsyncBaseReader.open()
await reader.close()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 thanks @geospatial-jeff

@vincentsarago vincentsarago merged commit 1be80a7 into master Oct 2, 2020
@vincentsarago vincentsarago deleted the MultiBandReader branch October 2, 2020 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants