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

Feat #133: add context manager for Reader.open method #134

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions eoreader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import importlib
import logging
import re
from contextlib import contextmanager
from enum import unique
from typing import Union
from zipfile import BadZipFile
Expand Down Expand Up @@ -448,6 +449,7 @@ def _compile_(regex_str: str):

return comp

@contextmanager
def open(
self,
product_path: AnyPathStrType,
Expand Down Expand Up @@ -550,8 +552,10 @@ def open(
"There is no existing products in EOReader corresponding to %s",
product_path,
)

return prod
try:
yield prod
finally:
del prod

def _open_stac_item(
self, item: Item, output_path: AnyPathStrType, remove_tmp: bool, **kwargs
Expand Down