Skip to content

Commit

Permalink
update dependencies and adjust to changes in ruyaml
Browse files Browse the repository at this point in the history
  • Loading branch information
redvox committed Jan 3, 2024
1 parent cbc0910 commit 1cec739
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 11 additions & 3 deletions app/core/files.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import io
import logging
import os
from pathlib import Path

from ruamel import yaml
from ruamel.yaml import YAML
from ruamel.yaml.parser import ParserError, ScannerError

logger = logging.getLogger('logsmith')
Expand All @@ -11,6 +12,11 @@
log_file_name = 'app.log'
active_group_file_name = 'active_group'

yamli = YAML(typ='safe')
yamli.default_flow_style = False
yamli.sort_base_mapping_type_on_output = False
yamli.indent(sequence=4)


def get_app_path() -> str:
return f'{str(Path.home())}/.logsmith'
Expand Down Expand Up @@ -38,13 +44,15 @@ def get_active_group_file_path() -> str:

def parse_yaml(text: str):
try:
return yaml.safe_load(text) or {}
return yamli.load(text) or {}
except (ParserError, ScannerError):
return {}


def dump_yaml(d: dict):
return yaml.round_trip_dump(d, indent=4, default_flow_style=False)
buffer = io.BytesIO()
yamli.dump(d, buffer)
return buffer.getvalue().decode("utf-8")


def _load_file(path):
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
boto3==1.28.62
PyQt6==6.5.0
PyInstaller==6.0.0
ruamel.yaml==0.17.35
boto3==1.34.11
PyQt6==6.6.1
PyInstaller==6.3.0
ruamel.yaml==0.18.5
nose==1.3.7
5 changes: 5 additions & 0 deletions tests/test_core/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def test_dump_yaml__do_not_sort_keys(self):
expected = 'z: dog\na: cat\n'
self.assertEqual(expected, text)

def test_dump_yaml__indentation(self):
text = files.dump_yaml({'a': 'cat', 'b': {'c': 'dog'}})
expected = 'a: cat\nb:\n c: dog\n'
self.assertEqual(expected, text)

def test__load_file(self):
text = files._load_file(self.test_file)
expected = 'this is a test'
Expand Down

0 comments on commit 1cec739

Please sign in to comment.