Skip to content

Commit

Permalink
Feat #133: add context manager for Reader.open method
Browse files Browse the repository at this point in the history
  • Loading branch information
jteulade committed May 15, 2024
1 parent e89599d commit d05b725
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit d05b725

Please sign in to comment.