Commit 2c77f304 authored by Jorn Bruggeman's avatar Jorn Bruggeman
Browse files

pyfabm.complete_yaml: preserve order again; avoid deprecation warning

parent 394b6d20
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
from __future__ import print_function from __future__ import print_function
import sys import sys
import io
import pyfabm import pyfabm
...@@ -17,7 +18,7 @@ try: ...@@ -17,7 +18,7 @@ try:
def dict_constructor(loader, node): def dict_constructor(loader, node):
return collections.OrderedDict(loader.construct_pairs(node)) return collections.OrderedDict(loader.construct_pairs(node))
yaml.add_representer(collections.OrderedDict, dict_representer) yaml.add_representer(collections.OrderedDict, dict_representer)
yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, dict_constructor) yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, dict_constructor, Loader=yaml.SafeLoader)
except ImportError: except ImportError:
pass pass
# ------------------------------------------ # ------------------------------------------
...@@ -27,8 +28,8 @@ def processFile(infile,outfile,subtract_background=False,add_missing=False): ...@@ -27,8 +28,8 @@ def processFile(infile,outfile,subtract_background=False,add_missing=False):
model = pyfabm.Model(infile) model = pyfabm.Model(infile)
# Load the old configuration # Load the old configuration
with open(infile,'rU') as f: with io.open(infile, 'r') as f:
config = yaml.safe_load(f) config = yaml.load(f, Loader=yaml.SafeLoader)
def findMaximumDepth(d): def findMaximumDepth(d):
n = 0 n = 0
...@@ -148,6 +149,6 @@ def processFile(infile,outfile,subtract_background=False,add_missing=False): ...@@ -148,6 +149,6 @@ def processFile(infile,outfile,subtract_background=False,add_missing=False):
f.write('%s: %s' % (key,value)) f.write('%s: %s' % (key,value))
f.write('\n') f.write('\n')
icommentstart = findMaximumDepth(config)+3 icommentstart = findMaximumDepth(config) + 3
with open(outfile,'w') as f: with io.open(outfile, 'w') as f:
processDict(f,config) processDict(f, config)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment