diff --git a/constructor/construct.py b/constructor/construct.py index 1de1dd1ef..def261269 100644 --- a/constructor/construct.py +++ b/constructor/construct.py @@ -10,9 +10,10 @@ from functools import partial from os.path import dirname -from ruamel import yaml +from ruamel.yaml import YAMLError from constructor.exceptions import UnableToParse, UnableToParseMissingJinja2, YamlParsingError +from constructor.utils import yaml # list of tuples (key name, required, type, description) KEYS = [ @@ -694,8 +695,8 @@ def select_lines(data, namespace): def yamlize(data, directory, content_filter): data = content_filter(data) try: - return yaml.safe_load(data) - except yaml.error.YAMLError as e: + return yaml.load(data) + except YAMLError as e: if ('{{' not in data) and ('{%' not in data): raise UnableToParse(original=e) try: @@ -703,7 +704,7 @@ def yamlize(data, directory, content_filter): except ImportError as ex: raise UnableToParseMissingJinja2(original=ex) data = render_jinja(data, directory, content_filter) - return yaml.load(data, Loader=yaml.SafeLoader) + return yaml.load(data) def parse(path, platform): diff --git a/constructor/utils.py b/constructor/utils.py index 09a96f2eb..395fa0841 100644 --- a/constructor/utils.py +++ b/constructor/utils.py @@ -9,14 +9,18 @@ import math import re import sys +from io import StringIO from os import sep, unlink from os.path import basename, isdir, isfile, islink, join, normpath from shutil import rmtree from subprocess import check_call, check_output -from ruamel import yaml +from ruamel.yaml import YAML logger = logging.getLogger(__name__) +yaml = YAML(typ="rt") +yaml.default_flow_style = False +yaml.indent(mapping=2, sequence=4, offset=2) def explained_check_call(args): @@ -35,6 +39,12 @@ def filename_dist(dist): return dist +def yaml_to_string(data): + blob = StringIO() + yaml.dump(data, blob) + return blob.getvalue() + + def fill_template(data, d, exceptions=[]): pat = re.compile(r'__(\w+)__') @@ -117,7 +127,7 @@ def add_condarc(info): if channel_alias: condarc['channel_alias'] = channel_alias if isinstance(condarc, dict): - condarc = yaml.dump(condarc, default_flow_style=False) + condarc = yaml_to_string(condarc) yield '# ----- add condarc' if info['_platform'].startswith('win'): yield 'Var /Global CONDARC' diff --git a/dev/environment.yml b/dev/environment.yml index ba74a8fd6..50a2b25d1 100644 --- a/dev/environment.yml +++ b/dev/environment.yml @@ -4,6 +4,6 @@ channels: dependencies: - python - conda >=4.6 - - ruamel.yaml >=0.11.14,<0.18 + - ruamel.yaml >=0.11.14,<0.19 - conda-standalone # >=23.11.0 - pillow >=3.1 # [osx or win] diff --git a/news/739-ruamel-yaml b/news/739-ruamel-yaml new file mode 100644 index 000000000..eb7a044f5 --- /dev/null +++ b/news/739-ruamel-yaml @@ -0,0 +1,19 @@ +### Enhancements + +* Add support for `ruamel.yaml` 0.18 API. (#729 via #739) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 77fd8f994..702ca535d 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -22,7 +22,7 @@ requirements: run: - conda >=4.6 - python - - ruamel.yaml >=0.11.14,<0.18 + - ruamel.yaml >=0.11.14,<0.19 - conda-standalone - pillow >=3.1 # [win or osx] - nsis >=3.08 # [win] diff --git a/setup.py b/setup.py index 022ec64c4..9bb529441 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ }, install_requires=[ "conda >=4.6", - "ruamel.yaml >=0.11.14,<0.18", + "ruamel.yaml >=0.11.14,<0.19", "pillow >=3.1 ; platform_system=='Windows' or platform_system=='Darwin'", # non-python dependency: "nsis >=3.08 ; platform_system=='Windows'", ],