From ca6c22e621fea9e1fd4c28e2f7589eb6b7608ae4 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Fri, 26 Jun 2020 22:39:29 -0500 Subject: [PATCH 1/3] [Input] Ensure YAML strings are preserved Ensure that a YAML field `some-field: '12345'` is read as a string by the C++ parser --- src/base/AnyMap.cpp | 7 ++++++- test/general/test_containers.cpp | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/base/AnyMap.cpp b/src/base/AnyMap.cpp index af4b215162e..47a81a440c8 100644 --- a/src/base/AnyMap.cpp +++ b/src/base/AnyMap.cpp @@ -190,7 +190,12 @@ struct convert { if (node.IsScalar()) { // Scalar nodes are int, doubles, or strings std::string nodestr = node.as(); - if (isInt(nodestr)) { + if (node.Tag() == "!") { + // Prevent quoted strings from being implicitly converted to + // numeric types, e.g. the quoted YAML string '12345' should not + // be interpreted as an integer + target = nodestr; + } else if (isInt(nodestr)) { try { target = node.as(); } catch (YAML::BadConversion&) { diff --git a/test/general/test_containers.cpp b/test/general/test_containers.cpp index 5b47ab6b5fe..3d6a26b0c1c 100644 --- a/test/general/test_containers.cpp +++ b/test/general/test_containers.cpp @@ -40,6 +40,19 @@ TEST(AnyValue, getMapWhere_initial_list) EXPECT_EQ(m["data"].getMapWhere("a", "baz")["x"].asInt(), 4); } +TEST(AnyValue, numeric_yaml_string) +{ + AnyMap m = AnyMap::fromYamlString( + "data: {a: '12345', b: '123.45', 'c': 12345, 'd': 123.45}"); + + EXPECT_THROW(m["data"]["a"].asInt(), CanteraError); + EXPECT_EQ(m["data"]["a"].asString(), "12345"); + EXPECT_THROW(m["data"]["b"].asDouble(), CanteraError); + EXPECT_EQ(m["data"]["b"].asString(), "123.45"); + EXPECT_EQ(m["data"]["c"].asInt(), 12345); + EXPECT_EQ(m["data"]["d"].asDouble(), 123.45); +} + TEST(AnyValue, getMapWhere_initial_map) { AnyMap m = AnyMap::fromYamlString( From 7c4240230bb6fbd26b592d68b3bba13246a15b33 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Fri, 10 Jul 2020 08:43:35 -0500 Subject: [PATCH 2/3] [test_data] Fix formatting / typo The 'note' indent for the species N2 is not consistent with former CTI/YAML versions; the note is also not identified as string --- test/data/ch4_ion.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/ch4_ion.yaml b/test/data/ch4_ion.yaml index 40f09a57862..617385a5ca0 100644 --- a/test/data/ch4_ion.yaml +++ b/test/data/ch4_ion.yaml @@ -85,7 +85,7 @@ species: rotational-relaxation: 4.00 dispersion-coefficient: 2.995 quadrupole-polarizability: 3.602 - note: 121286 + note: '121286' - name: H3O+ composition: {H: 3, O: 1, E: -1} From 0ef12d6f7437c8315f135e77c3dd2e0f662914ad Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sat, 4 Jul 2020 12:43:22 -0500 Subject: [PATCH 3/3] [scons] Fix formatting / update Python example folders - Make path separators consistent on Windows post-install message - Update list of Python example folders --- SConstruct | 10 +++++++--- interfaces/cython/SConscript | 9 ++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/SConstruct b/SConstruct index 276f9b1e0be..d4bcd59c720 100644 --- a/SConstruct +++ b/SConstruct @@ -1410,6 +1410,7 @@ env['debian'] = any(name.endswith('dist-packages') for name in sys.path) # Directories where things will be after actually being installed. These # variables are the ones that are used to populate header files, scripts, etc. +env['prefix'] = os.path.normpath(env['prefix']) env['ct_installroot'] = env['prefix'] env['ct_libdir'] = pjoin(env['prefix'], env['libdirname']) env['ct_bindir'] = pjoin(env['prefix'], 'bin') @@ -1781,15 +1782,18 @@ def postInstallMessage(target, source, env): """.format(**env_dict)) if os.name != 'nt': + env['setup_cantera'] = pjoin(env['ct_bindir'], 'setup_cantera') + env['setup_cantera_csh'] = pjoin(env['ct_bindir'], 'setup_cantera.csh') install_message += textwrap.dedent(""" + Setup scripts to configure the environment for Cantera are at: - setup script (bash) {ct_bindir!s}/setup_cantera - setup script (csh/tcsh) {ct_bindir!s}/setup_cantera.csh + setup script (bash) {setup_cantera!s} + setup script (csh/tcsh) {setup_cantera_csh!s} It is recommended that you run the script for your shell by typing: - source {ct_bindir!s}/setup_cantera + source {setup_cantera!s} before using Cantera, or else include its contents in your shell login script. """.format(**env_dict)) diff --git a/interfaces/cython/SConscript b/interfaces/cython/SConscript index adcff5c3965..4e8791fa3dc 100644 --- a/interfaces/cython/SConscript +++ b/interfaces/cython/SConscript @@ -83,14 +83,13 @@ localenv.Depends(ext, localenv['cantera_staticlib']) for f in (mglob(localenv, 'cantera', 'py') + mglob(localenv, 'cantera/test', 'py') + - mglob(localenv, 'cantera/examples/tutorial', 'py') + - mglob(localenv, 'cantera/examples/equilibrium', 'py') + mglob(localenv, 'cantera/examples/kinetics', 'py') + - mglob(localenv, 'cantera/examples/transport', 'py') + - mglob(localenv, 'cantera/examples/reactors', 'py') + + mglob(localenv, 'cantera/examples/multiphase', 'py') + mglob(localenv, 'cantera/examples/onedim', 'py') + + mglob(localenv, 'cantera/examples/reactors', 'py') + mglob(localenv, 'cantera/examples/surface_chemistry', 'py') + - mglob(localenv, 'cantera/examples/misc', 'py')): + mglob(localenv, 'cantera/examples/thermo', 'py') + + mglob(localenv, 'cantera/examples/transport', 'py')): localenv.Depends(mod, f) # Determine installation path and install the Python module