Skip to content

Commit

Permalink
settings: Use ruamel.yaml's non-deprecated version of .dump
Browse files Browse the repository at this point in the history
We used .dump by itslef which used to be compatible for both ruamel.yaml
and pyyaml but it has since been deprecated in ruamel.yaml>=0.18.

Since we are only using ruamel.yaml (as part of dynaconf) let's stop
trying to be compatible with pyyaml and just use ruamel's way of doing
it.
  • Loading branch information
dmsimard committed Feb 6, 2024
1 parent 19a38c7 commit c92c3d6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ara/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
from django.utils.crypto import get_random_string
from dynaconf import LazySettings

# dynaconf prefers ruamel.yaml but works with pyyaml
# dynaconf prefers ruamel.yaml but historically we also used pyyaml
# https://github.com/rochacbruno/dynaconf/commit/d5cf87cbbdf54625ccf1138a4e4c210956791e61
try:
from ruamel import yaml as yaml
except ImportError:
import yaml
# ruamel.yaml >= 0.18 deprecated raw use of .dump
# https://github.com/ansible-community/ara/issues/524
from ruamel.yaml import YAML

yaml = YAML(typ="unsafe", pure=True)
yaml.default_flow_style = False

BASE_DIR = os.environ.get("ARA_BASE_DIR", os.path.expanduser("~/.ara/server"))
DEFAULT_SETTINGS = os.path.join(BASE_DIR, "settings.yaml")
Expand Down Expand Up @@ -303,7 +305,7 @@ def get_secret_key():
)
print("[ara] Writing default settings to %s" % DEFAULT_SETTINGS)
settings_file.write(comment.lstrip())
yaml.dump({"default": SETTINGS}, settings_file, default_flow_style=False)
yaml.dump({"default": SETTINGS}, settings_file)

if BASE_PATH:
BASE_PATH = BASE_PATH.rstrip("/")
Expand Down

0 comments on commit c92c3d6

Please sign in to comment.