martinthoma / cfg_load Goto Github PK
View Code? Open in Web Editor NEWLoad config files the right way
License: MIT License
Load config files the right way
License: MIT License
Currently, _load_remote
does not have the policy
implemented (here). The default is always used.
The load_if_possible
policy should always try to load the remote file. If it fails, the local one is used.
If the string is empty, then convert it to None
I'm new to configuration files and really like your setup.
Can or should a cfg_load file be modified to be opened or run with PyCharm or Docker?
Still learning how this works.
In case the config file is in a git repository, add the hash.
Nice work to streamline config files! What I usually do is load the configuration file, but allow the command line arguments to override the settings. The advantage is that the conf file does not need changing for every small experiment.
The hierarchy stays the same, for example in the (yaml) conf file:
sound:
volume_left: 50
Could be exec'd with modified settings like so:
myfile.py --sound.volume_left 80
If you like the idea, I can implement the feature.
The key config['_META']
should contain the filepath
and the datetime
(in UTC) of the loaded configuration.
Overwriting the configuration during the application is likely to lead to an error. It should be done with caution. Thus it might be desirable to at least log a message if the configuration is changed.
For easy inspection in REPL, a cfg.pprint()
method would be nice.
I have a nested dictionary that i'd like updated to be empty when I update with a user config. Ideally the top level attribute would be set to {}
and then base_cfg.update(user_cfg, recursive=False)
would nuke the whole dict with the user value of {}
With YAML, one can add lists and dictionaries as configuration values.
Environment variables can only contain strings.
I, as a user, want to overwrite all possible values with an environment variable and still have the same type.
Sometimes it is handy to just have a dict. For this reason, the Configuration objects should have a to_dict()
method
Please add support for Tom's Obvious, Minimal Language. Realizing it's much like INI files, support is almost there. TOML is sufficiently different from INI that there are dedicated TOML libraries in Python and ConfigParser does not explicitly represent that is handles TOML.
Please add a CLI tool in this package that allows direct validation of configuration files.
How to specify EOL such as \n or \n\r in ini files?
Hello! A fresh install with poetry (python package manager) is giving an error of ModuleNotFoundError
when the function cfg.load()
is called.
Somehow the module tzlocal
is not getting installed?
Is this with how cfg_load declares its deps? or is it on the mpu dep side?
Trace:
Traceback (most recent call last):
File "/home/martin/Documentos/Programming/Python/Projetos/test-project/test_project/__init__.py", line 6, in <module>
cfg.load("/home/martin/Documentos/Programming/Python/Projetos/steam-api-explore/cfg-template.yaml")
File "/home/martin/Documentos/PythonEnvironments/steam-api-explore-oyX2e_1N-py3.8/lib/python3.8/site-packages/cfg_load/__init__.py", line 66, in load
meta = mpu.io.get_file_meta(filepath)
File "/home/martin/Documentos/PythonEnvironments/steam-api-explore-oyX2e_1N-py3.8/lib/python3.8/site-packages/mpu/io.py", line 366, in get_file_meta
meta["last_access_datetime"] = get_access_datetime(filepath)
File "/home/martin/Documentos/PythonEnvironments/steam-api-explore-oyX2e_1N-py3.8/lib/python3.8/site-packages/mpu/io.py", line 344, in get_access_datetime
import tzlocal
ModuleNotFoundError: No module named 'tzlocal'
I have included a minimal pyproject for you to test.
pyproject.toml
[tool.poetry]
name = "test-project"
version = "0.1.0"
description = ""
authors = ["Martin <[email protected]>"]
[tool.poetry.dependencies]
python = "^3.8"
cfg-load = "*"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Sample file:
__version__ = '0.1.0'
import cfg_load as cfg
if __name__ == '__main__':
cfg.load("/home/martin/Documentos/Programming/Python/Projetos/steam-api-explore/cfg-template.yaml")
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.