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

Convert deprecated ruamel.yaml function calls to method calls #152

Merged
merged 2 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 2 additions & 5 deletions exdir/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,9 @@ def _set_data(self, attrs):
attribute_data_quoted = attrs

with self.filename.open("w", encoding="utf-8") as attribute_file:
yaml.dump(
yaml.YAML(typ="rt", pure=True).dump(
attribute_data_quoted,
attribute_file,
default_flow_style=False,
allow_unicode=True,
Dumper=yaml.RoundTripDumper
)

# TODO only needs filename, make into free function
Expand All @@ -180,7 +177,7 @@ def _open_or_create(self):
attrs = {}
if self.filename.exists(): # NOTE str for Python 3.5 support
with self.filename.open("r", encoding="utf-8") as meta_file:
attrs = yaml.safe_load(meta_file)
attrs = yaml.YAML(typ="safe", pure=True).load(meta_file)
return attrs

def __iter__(self):
Expand Down
9 changes: 6 additions & 3 deletions exdir/core/exdir_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def _create_object_directory(directory, metadata):
version=1
)
else:
metadata_string = yaml.dump(metadata)
from io import StringIO
with StringIO() as buf:
yaml.YAML(typ="safe", pure=True).dump(metadata, buf)
metadata_string = buf.getvalue()

try:
meta_file.write(metadata_string)
Expand Down Expand Up @@ -103,7 +106,7 @@ def is_nonraw_object_directory(directory):
if not meta_filename.exists():
return False
with meta_filename.open("r", encoding="utf-8") as meta_file:
meta_data = yaml.safe_load(meta_file)
meta_data = yaml.YAML(typ="safe", pure=True).load(meta_file)

if not isinstance(meta_data, dict):
return False
Expand Down Expand Up @@ -140,7 +143,7 @@ def root_directory(path):

meta_filename = path / META_FILENAME
with meta_filename.open("r", encoding="utf-8") as meta_file:
meta_data = yaml.safe_load(meta_file)
meta_data = yaml.YAML(typ="safe", pure=True).load(meta_file)
if EXDIR_METANAME not in meta_data:
path = path.parent
continue
Expand Down
2 changes: 1 addition & 1 deletion exdir/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def __getitem__(self, name):

meta_filename = directory / exob.META_FILENAME
with meta_filename.open("r", encoding="utf-8") as meta_file:
meta_data = yaml.safe_load(meta_file)
meta_data = yaml.YAML(typ="safe", pure=True).load(meta_file)
if meta_data[exob.EXDIR_METANAME][exob.TYPE_METANAME] == exob.DATASET_TYPENAME:
return self._dataset(name)
elif meta_data[exob.EXDIR_METANAME][exob.TYPE_METANAME] == exob.GROUP_TYPENAME:
Expand Down
23 changes: 10 additions & 13 deletions tests/test_help_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_create_object_directory(setup_teardown_folder):
}

with file_path.open("r", encoding="utf-8") as meta_file:
metadata = yaml.safe_load(meta_file)
metadata = yaml.YAML(typ="safe", pure=True).load(meta_file)

assert metadata == compare_metadata

Expand All @@ -141,10 +141,9 @@ def test_is_nonraw_object_directory(setup_teardown_folder):
exob.EXDIR_METANAME: {
exob.VERSION_METANAME: 1}
}
yaml.safe_dump(metadata,
meta_file,
default_flow_style=False,
allow_unicode=True)
yaml.YAML(typ="safe", pure=True).dump(
metadata,
meta_file)

result = exob.is_nonraw_object_directory(setup_teardown_folder[2])
assert result is False
Expand All @@ -156,10 +155,9 @@ def test_is_nonraw_object_directory(setup_teardown_folder):
exob.TYPE_METANAME: "wrong_typename",
exob.VERSION_METANAME: 1}
}
yaml.safe_dump(metadata,
meta_file,
default_flow_style=False,
allow_unicode=True)
yaml.YAML(typ="safe", pure=True).dump(
metadata,
meta_file)

result = exob.is_nonraw_object_directory(setup_teardown_folder[2])
assert result is False
Expand All @@ -171,10 +169,9 @@ def test_is_nonraw_object_directory(setup_teardown_folder):
exob.TYPE_METANAME: exob.DATASET_TYPENAME,
exob.VERSION_METANAME: 1}
}
yaml.safe_dump(metadata,
meta_file,
default_flow_style=False,
allow_unicode=True)
yaml.YAML(typ="safe", pure=True).dump(
metadata,
meta_file)

result = exob.is_nonraw_object_directory(setup_teardown_folder[2])
assert result is True
Expand Down
2 changes: 1 addition & 1 deletion tests/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_object_attrs(setup_teardown_file):
obj.attrs = "test value"

with (setup_teardown_file[1] / "test_object" / ATTRIBUTES_FILENAME).open("r", encoding="utf-8") as meta_file:
meta_data = yaml.safe_load(meta_file)
meta_data = yaml.YAML(typ="safe", pure=True).load(meta_file)
assert meta_data == "test value"


Expand Down