From 7398c854ae80527a574595b4b5548b6353eddc94 Mon Sep 17 00:00:00 2001 From: "Jan C. Rivenaes" Date: Wed, 18 Dec 2019 14:24:15 +0100 Subject: [PATCH 1/4] Added SMALLFLOAT examples From 6be0b983b1e0778ef0f241763bc5d57c816bc9f9 Mon Sep 17 00:00:00 2001 From: "Jan C. Rivenaes" Date: Wed, 18 Dec 2019 14:27:16 +0100 Subject: [PATCH 2/4] Added SMALLFLOAT examples From 589177e8b39debda8648d5759ed536ac2224da82 Mon Sep 17 00:00:00 2001 From: "Jan C. Rivenaes" Date: Wed, 18 Dec 2019 14:31:51 +0100 Subject: [PATCH 3/4] Added black settings for flake8 --- setup.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup.cfg b/setup.cfg index 785ad25..f5c57cf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,6 +3,10 @@ universal = 1 [flake8] exclude = docs +max-line-length = 88 +extend-ignore = + # See https://github.com/PyCQA/pycodestyle/issues/373 + E203, [aliases] test = pytest From e6705dd0b5f55350c332723c88500dd9c45d524c Mon Sep 17 00:00:00 2001 From: "Jan C. Rivenaes" Date: Thu, 19 Dec 2019 10:28:24 +0100 Subject: [PATCH 4/4] Fix IPL float issue when using e syntax --- src/fmu/config/_configparserfmu_ipl.py | 9 ++++++++- src/fmu/config/configparserfmu.py | 14 +++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/fmu/config/_configparserfmu_ipl.py b/src/fmu/config/_configparserfmu_ipl.py index 721809e..66833a3 100644 --- a/src/fmu/config/_configparserfmu_ipl.py +++ b/src/fmu/config/_configparserfmu_ipl.py @@ -398,7 +398,7 @@ def _freeform_handle_entry(variable, myvalue, myvalues, dtype, template): # inner function def _fixtheentry(variable, myval, subtype, count=None, template=False): - logger.info("Fix freeform entry %s", variable) + logger.info("Fix freeform entry %s (subtype %s)", variable, subtype) tmpvalue = str(myval) if "~" in tmpvalue: val, var = tmpvalue.split("~") @@ -414,6 +414,13 @@ def _fixtheentry(variable, myval, subtype, count=None, template=False): if val in ("False", "no", "NO", "No", "false", "FALSE"): val = "FALSE" + if subtype == "Float": + logger.info("Input float value is %s (%s)", val, variable) + if "e" in str(val).lower(): + val = "{0:E}".format(float(val)) + + logger.info("Updated float value is %s (%s)", val, variable) + if subtype == "String": val = '"{}"'.format(val) if var: diff --git a/src/fmu/config/configparserfmu.py b/src/fmu/config/configparserfmu.py index 1f52242..c2253c8 100644 --- a/src/fmu/config/configparserfmu.py +++ b/src/fmu/config/configparserfmu.py @@ -19,6 +19,8 @@ import datetime import json +import pdb + # for ordered dicts! from collections import OrderedDict, Counter @@ -208,7 +210,7 @@ def to_yaml( >>> config.to_yaml('global_variables', destination='../') """ - + logger.info("To YAML") if not destination and not template: raise ValueError( "Both destination and template are None." @@ -233,6 +235,8 @@ def to_yaml( mystream = re.sub(r"\s+~", "~", mystream) mystream = re.sub(r"~\s+", "~", mystream) + # pdb.set_trace() + cfg1 = self._get_dest_form(mystream) cfg2 = self._get_tmpl_form(mystream) @@ -622,7 +626,9 @@ def _get_required_form(stream, template=False, ipl=False): def _get_tmpl_form(stream): """Get template form (<...> if present, not numbers).""" - pattern = "-*[a-zA-Z0-9.]+~" + pattern = "\\-*[\\-a-zA-Z0-9.]+~" + + # pdb.set_trace() if isinstance(stream, list): logger.info("STREAM is a list object") @@ -646,7 +652,8 @@ def _get_tmpl_form(stream): def _get_dest_form(stream): """Get destination form (numbers, not <...>)""" - pattern = "~<.+?>" + logger.info("TRY DEST %s", stream) + pattern = "~.*<.+?>" if isinstance(stream, list): logger.info("STREAM is a list object") @@ -662,4 +669,5 @@ def _get_dest_form(stream): else: raise ValueError("Input for templateconversion neither string " "or list") + logger.info("DEST %s", result) return result