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

Minor fixes in AnyValue and scons #899

Merged
merged 3 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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))
Expand Down
9 changes: 4 additions & 5 deletions interfaces/cython/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/base/AnyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ struct convert<Cantera::AnyValue> {
if (node.IsScalar()) {
// Scalar nodes are int, doubles, or strings
std::string nodestr = node.as<std::string>();
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<long int>();
} catch (YAML::BadConversion&) {
Expand Down
2 changes: 1 addition & 1 deletion test/data/ch4_ion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
13 changes: 13 additions & 0 deletions test/general/test_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down