hoedt / upsilonconf Goto Github PK
View Code? Open in Web Editor NEWA simple configuration library
License: MIT License
A simple configuration library
License: MIT License
Thanks for your wonderful upsilonconf
!
I noticed, that it is neither possible to load a configuration file, where the keys have spaces or hyphens (periods simply adds a new level). This requires to convert all hyphens and spaces to underscores in the config file. This is not a very big problem, but often the files are more readable, if these characters are allowed in the keys.
I could think of the following approach how to tackle this drawback:
load(…, space='_', hyphen='_', period='_')
function (with the three keyword parameters defaulting to None
resulting in the current behaviour).save(…, space='_')
would replace underscores with spaces. If the load function uses different replacements for space/hyphen/period, it would be even possible to use something like save(…, space='__', hyphen='_')
. Again the three keyword parameters would default to None
resulting in the current behaviour.What do you think? If you want, I could make a PR with these changes.
Currently from_dict
works to recursively go down through lists to get sub FrozenConfiguration
objects. By example:
>>> conf = FrozenConfiguration.from_dict({"things": [ {"a": 0, "b": 1}, {"a": 2, "b": 3}, ]})
FrozenConfiguration(things=(FrozenConfiguration(a=0, b=1), FrozenConfiguration(a=2, b=3)))
>>> conf.to_dict()
{'things': (FrozenConfiguration(a=0, b=1), FrozenConfiguration(a=2, b=3))}
And then I cannot serialize this to e.g. YAML simply.
In my case I use YAML files for configuration. Would it be possible to reorganize the code, so that neither json
nor argparser
are imported, if they are not used?
Since both modules are include in the standard Python, these imports should be ok. But they take time and use up memory, so it would be preferable to only import them, if needed!
I'm not sure what would be the best way to handle it when trying to save a configuration to a directory.
The main problem is that a user might have several goals when trying to read from/write to a directory:
Each of these options requires choices to be made about the file type. Also, it is unclear what the name of a non-default config file should be if it does not yet exist.
I had the following ideas in mind, but I am not sure what would make more sense:
try:
import yaml
DEFAULT_FILENAME = "config.yaml"
except ImportError:
DEFAULT_FILENAME = "config.json"
data = {file.stem: _load(file) for file in path.glob("*.yaml")}
I am probably missing a lot of things in my considerations, therefore I leave this here for more intelligent people to leave their thoughts.
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.