mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-19 15:16:33 +00:00
Switch from ruamel.yaml to pyyaml (#4555)
* Switch from ruamel.yaml to pyyaml * Use CLoader and CDumper when available
This commit is contained in:
parent
0225f574be
commit
2c8e6ca0cd
2
.github/workflows/builder.yml
vendored
2
.github/workflows/builder.yml
vendored
@ -112,7 +112,7 @@ jobs:
|
|||||||
tag: musllinux_1_2
|
tag: musllinux_1_2
|
||||||
arch: ${{ matrix.arch }}
|
arch: ${{ matrix.arch }}
|
||||||
wheels-key: ${{ secrets.WHEELS_KEY }}
|
wheels-key: ${{ secrets.WHEELS_KEY }}
|
||||||
apk: "libffi-dev;openssl-dev"
|
apk: "libffi-dev;openssl-dev;yaml-dev"
|
||||||
skip-binary: aiohttp
|
skip-binary: aiohttp
|
||||||
env-file: true
|
env-file: true
|
||||||
requirements: "requirements.txt"
|
requirements: "requirements.txt"
|
||||||
|
@ -22,6 +22,7 @@ RUN \
|
|||||||
libpulse \
|
libpulse \
|
||||||
musl \
|
musl \
|
||||||
openssl \
|
openssl \
|
||||||
|
yaml \
|
||||||
\
|
\
|
||||||
&& curl -Lso /usr/bin/cosign "https://github.com/home-assistant/cosign/releases/download/${COSIGN_VERSION}/cosign_${BUILD_ARCH}" \
|
&& curl -Lso /usr/bin/cosign "https://github.com/home-assistant/cosign/releases/download/${COSIGN_VERSION}/cosign_${BUILD_ARCH}" \
|
||||||
&& chmod a+x /usr/bin/cosign
|
&& chmod a+x /usr/bin/cosign
|
||||||
|
@ -18,7 +18,7 @@ gitpython==3.1.36
|
|||||||
jinja2==3.1.2
|
jinja2==3.1.2
|
||||||
pulsectl==23.5.2
|
pulsectl==23.5.2
|
||||||
pyudev==0.24.1
|
pyudev==0.24.1
|
||||||
ruamel.yaml==0.17.21
|
PyYAML==6.0.1
|
||||||
securetar==2023.3.0
|
securetar==2023.3.0
|
||||||
sentry-sdk==1.30.0
|
sentry-sdk==1.30.0
|
||||||
voluptuous==0.13.1
|
voluptuous==0.13.1
|
||||||
|
@ -3,20 +3,23 @@ import logging
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from atomicwrites import atomic_write
|
from atomicwrites import atomic_write
|
||||||
from ruamel.yaml import YAML, YAMLError
|
from yaml import YAMLError, dump, load
|
||||||
|
|
||||||
|
try:
|
||||||
|
from yaml import CDumper as Dumper, CSafeLoader as SafeLoader
|
||||||
|
except ImportError:
|
||||||
|
from yaml import SafeLoader, Dumper
|
||||||
|
|
||||||
from ..exceptions import YamlFileError
|
from ..exceptions import YamlFileError
|
||||||
|
|
||||||
_YAML = YAML(typ="safe")
|
|
||||||
_YAML.allow_duplicate_keys = True
|
|
||||||
|
|
||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def read_yaml_file(path: Path) -> dict:
|
def read_yaml_file(path: Path) -> dict:
|
||||||
"""Read YAML file from path."""
|
"""Read YAML file from path."""
|
||||||
try:
|
try:
|
||||||
return _YAML.load(path) or {}
|
with open(path, encoding="utf-8") as yaml_file:
|
||||||
|
return load(yaml_file, Loader=SafeLoader) or {}
|
||||||
|
|
||||||
except (YAMLError, AttributeError, OSError) as err:
|
except (YAMLError, AttributeError, OSError) as err:
|
||||||
raise YamlFileError(
|
raise YamlFileError(
|
||||||
@ -28,7 +31,7 @@ def write_yaml_file(path: Path, data: dict) -> None:
|
|||||||
"""Write a YAML file."""
|
"""Write a YAML file."""
|
||||||
try:
|
try:
|
||||||
with atomic_write(path, overwrite=True) as fp:
|
with atomic_write(path, overwrite=True) as fp:
|
||||||
_YAML.dump(data, fp)
|
dump(data, fp, Dumper=Dumper)
|
||||||
path.chmod(0o600)
|
path.chmod(0o600)
|
||||||
except (YAMLError, OSError, ValueError, TypeError) as err:
|
except (YAMLError, OSError, ValueError, TypeError) as err:
|
||||||
raise YamlFileError(f"Can't write {path!s}: {err!s}", _LOGGER.error) from err
|
raise YamlFileError(f"Can't write {path!s}: {err!s}", _LOGGER.error) from err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user