Skip to content

Commit

Permalink
create utility function instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed Dec 18, 2023
1 parent c3bc41e commit 4cad73c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions constructor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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
Expand All @@ -17,7 +18,7 @@
from ruamel.yaml import YAML

logger = logging.getLogger(__name__)
yaml = YAML(typ=["rt", "string"])
yaml = YAML(typ="rt")
yaml.default_flow_style = False
yaml.indent(mapping=2, sequence=4, offset=2)

Expand All @@ -38,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 @@ -120,7 +127,7 @@ def add_condarc(info):
if channel_alias:
condarc['channel_alias'] = channel_alias
if isinstance(condarc, dict):
condarc = yaml.dump_to_string(condarc)
condarc = yaml_to_string(condarc)
yield '# ----- add condarc'
if info['_platform'].startswith('win'):
yield 'Var /Global CONDARC'
Expand Down

0 comments on commit 4cad73c

Please sign in to comment.