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

allow ruamel.yaml 0.18 #739

Merged
merged 6 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 5 additions & 4 deletions constructor/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -687,16 +688,16 @@ 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:
from constructor.jinja import render_jinja
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):
Expand Down
14 changes: 12 additions & 2 deletions constructor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, normpath
from shutil import rmtree
from subprocess import check_call

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):
Expand All @@ -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+)__')

Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion dev/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- pillow >=3.1 # [osx or win]
19 changes: 19 additions & 0 deletions news/739-ruamel-yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Add support for `ruamel.yaml` 0.18 API. (#729 via #739)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
2 changes: 1 addition & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
],
Expand Down