heinzk1x / pylibconfig2 Goto Github PK
View Code? Open in Web Editor NEWPure python library for libconfig syntax.
License: GNU General Public License v3.0
Pure python library for libconfig syntax.
License: GNU General Public License v3.0
I just installed pylibconfig2 and ran the tests. For python2.7 everything is fine, but the tests fail with python3.3. Assuming the 2 in the package name determines the support python version, the question is if there are any plans to support python3 in future.
I tried running this on a file with @include directives and got errors.
I'm assuming this is not supported yet. I'd be grateful if you included support for it.
I have difficulties to parse this string due to the coma between each setting.
libconfig manual (page 33) says:
expt_ids:
(
{ title: "10- or 30-year run initialized in year XXXX", id: "decadalXXXX"},
{ title: "volcano-free hindcast initialized in year XXXX", id: "noVolcXXXX" },
{ title: "prediction with 2010 volcano", id: "volcIn2010" },
{ title: "pre-industrial control", id: "piControl" },
{ title: "historical", id: "historical" },
{ title: "historical extension", id: "historicalExt" },
{ title: "other historical forcing", id: "historicalMisc" },
{ title: "mid-Holocene", id: "midHolocene" },
{ title: "last glacial maximum", id: "lgm" },
{ title: "last millennium", id: "past1000" },
{ title: "RCP4.5", id: "rcp45" },
{ title: "RCP8.5", id: "rcp85" },
{ title: "RCP2.6", id: "rcp26" },
{ title: "RCP6", id: "rcp60" },
{ title: "ESM pre-industrial control", id: "esmControl" },
{ title: "ESM historical", id: "esmHistorical" },
{ title: "ESM RCP8.5", id: "esmrcp85" },
{ title: "ESM fixed climate 1", id: "esmFixClim1" },
{ title: "ESM fixed climate 2", id: "esmFixClim2" },
{ title: "ESM feedback 1", id: "esmFdbk1" },
{ title: "ESM feedback 2", id: "esmFdbk2" },
{ title: "1 percent per year CO2", id: "1pctCO2" },
{ title: "abrupt 4XCO2", id: "abrupt4xCO2" },
{ title: "natural-only", id: "historicalNat" },
{ title: "GHG-only", id: "historicalGHG" },
{ title: "AMIP", id: "amip" },
{ title: "2030 time-slice", id: "sst2030" },
{ title: "control SST climatology", id: "sstClim" },
{ title: "CO2 forcing", id: "sstClim4xCO2" },
{ title: "all aerosol forcing", id: "sstClimAerosol" },
{ title: "sulfate aerosol forcing", id: "sstClimSulfate" },
{ title: "4xCO2 AMIP", id: "amip4xCO2" },
{ title: "AMIP plus patterned anomaly", id: "amipFuture" },
{ title: "aqua planet control", id: "aquaControl" },
{ title: "4xCO2 aqua planet", id: "aqua4xCO2" },
{ title: "aqua planet plus 4K anomaly", id: "aqua4K" },
{ title: "AMIP plus 4K anomaly", id: "amip4K" }
)
_ListType seems to be derived from list, but list indexes definitely start with 0, it could work some other way with the original libconfig library
Try your own example with zero index for array:
>> c = cfg.Config("my_array = [1, 2, 3];")
>> c.lookup('my_array.[0]')
For current right-now usage I just fixed the _lookup as follows:
def _lookup(self, keys):
k = self.array_index.parseString(keys.pop(0))[0]
if k < len(self):
But you could recalculate indexes, so that they would start with 1, but work correct still
The README.rst tells that "IO works via strings only. Thus, include directives are not supported.". Anyway, I found a function read_file
in https://github.com/heinzK1X/pylibconfig2/blob/master/pylibconfig2/conf_types.py#L321. Since the README.rst is older than the conf_types.py
this information might be deprecated.
It seems that c.lookup
fails on booleans set to false
. I wrote a small example to demonstrate the issue.
import pylibconfig2 as cfg
from pylibconfig2 import conf_types
test = """
simulation =
{
bool_false = false
bool_true = true
}
"""
c = cfg.Config(test)
print(c)
print('')
print(c.lookup('simulation.bool_true'))
print(c.lookup('simulation.bool_false'))
print('')
print(c.simulation.bool_true)
print(c.simulation.bool_false)
The out is:
simulation = {
bool_false = False;
bool_true = True;
};
True
None
True
False
Also None
belongs to falsy values, I think it should be False
instead of None
.
Trying:
c = Config(" foo = 'bar'; ")
c.set("val", 1.23e-20)
b = Config(str(c))
leads to gettin parse error "1.23e is not a number" or something similar.
Can be easily fixed in pyparsing.py like the following:
val_num = Combine( Optional(oneOf("+ -")) + Optional("0x") + Word(hexnums + ".eEL" + "-" + nums) )\ .setParseAction(convert_num)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.