Skip to content

Commit

Permalink
Use import_resources.files instead of the legacy open_text (OSOce…
Browse files Browse the repository at this point in the history
…anAcoustics#1434)

* use import_resources.files to open yaml files

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* import from importlib.resources

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and oftfrfbf committed Feb 5, 2025
1 parent a4f0681 commit f8af1f3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions echopype/convert/set_groups_ad2cp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum, auto, unique
from importlib import resources
from importlib.resources import files
from typing import Dict, List, Optional, Set, Tuple, Union

import numpy as np
Expand Down Expand Up @@ -35,7 +35,7 @@ def __init__(self, *args, **kwargs):
# resulting in index error in setting ds["pulse_compressed"]
self.pulse_compressed = self.parser_obj.get_pulse_compressed()
self._make_time_coords()
with resources.open_text(convert, "ad2cp_fields.yaml") as f:
with files(convert).joinpath("ad2cp_fields.yaml").open("r") as f:
self.field_attrs: Dict[str, Dict[str, Dict[str, str]]] = yaml.safe_load(f) # type: ignore # noqa

def _make_time_coords(self):
Expand Down
4 changes: 2 additions & 2 deletions echopype/echodata/convention/conv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from importlib import resources
from importlib.resources import files
from typing import Optional

import yaml
Expand All @@ -21,7 +21,7 @@ def yaml_dict(self):
if self._yaml_dict: # Data has already been read, return it directly
return self._yaml_dict

with resources.open_text(package=convention, resource=f"{self.version}.yml") as fid:
with files(convention).joinpath(f"{self.version}.yml").open("r") as fid:
convention_yaml = yaml.load(fid, Loader=yaml.SafeLoader)

self._yaml_dict = convention_yaml
Expand Down

0 comments on commit f8af1f3

Please sign in to comment.