grimen / python-config2 Goto Github PK
View Code? Open in Web Editor NEWPython environment configuration simplified - highly inspired by `node-config`.
Home Page: https://pypi.org/project/config2
License: MIT License
Python environment configuration simplified - highly inspired by `node-config`.
Home Page: https://pypi.org/project/config2
License: MIT License
Versions
Issue
Following YAML loading warning is been thrown:
/usr/local/lib/python3.6/site-packages/config2/serializers/yaml_.py:51: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
Hi,
It appears that the default.yml
is overriding the custom-environment-variables.yml
defined configuration.
Python Version: 2.7.8
Project Structure
main.py
from config2.config import config
import os
print(os.environ['APP'])
print('port', config.port)
config/default.yml
port: 3000
config/custom-environment-variables.yml
port: APP
When run with python main.py
config returns the default (3000) as expected
When run with APP=1111 python main.py
config still returns 3000 where I expected 1111 however the APP
environment variable is returning 1111.
Is virtualenv
causing a problem here?
requirements.txt
attributedict==0.1.8
blessings==1.7
Click==7.0
colour-runner==0.1.1
config2==0.1.4
deepdiff==3.3.0
deepmerge==0.0.4
easypackage==0.1.8
filelock==3.0.9
itsdangerous==0.24
Jinja2==2.10
jsonpickle==1.0
MarkupSafe==1.0
pluggy==0.7.1
py==1.6.0
Pygments==2.2.0
PyYAML==3.13
six==1.11.0
toml==0.10.0
tox==3.5.2
virtualenv==16.0.0
Werkzeug==0.14.1
Thanks for your work btw
EDIT:
Just to add to this, defining configuration in another file works fine.
i.e config/foo.yml
and executing ENV=foo python main.py
will return the correct configuration.
As I follow the README, I come across the issue that config.get_env() raises an AttributeError
By looking through config.py, I can't seem to find the function too.
What am I missing here?
Hi,
I still get release 0.2.0 if I run "pip install config2", which contains the bogus custom-environment-variables.yml handling. I need to install from Github directly to get version 0.2.1.
Also, get_env() still does not work.
However, very nice project! Perfectly fits my needs.
Best - André.
I' unable to execute the ENV=development python app.py on windows 10 .
I tried executing the following command
set ENV=development & python app.py
Output:
DEFAULT 1
{'b1': [1, 2, 3], 'b2': ['foo', 'bar'], 'b3': {'c1': 1, 'c2': 'DEFAULT 2'}}
DEFAULT 2
config.some_key_only_for_dev 'some_key_only_for_dev'
config.some_key_only_for_foo 'some_key_only_for_foo'
config.some_key_only_for_foo 'some_key_only_for_prod'
$$$
Excepted result
DEFAULT 1
{'b1': [1, 2, 3], 'b2': ['DEV 1'], 'b3': {'c1': 1, 'c2': 'DEV 2'}}
DEV 2
config.some_key_only_for_dev True
config.some_key_only_for_foo 'some_key_only_for_foo'
config.some_key_only_for_foo 'some_key_only_for_prod'
Sorry, cant find contact to write PM
As i understand the one file for one environment
But is it possible to load multiple file in default enviroment?
if I use:
from config2.config import config
config.values
it return values from all enviroment but this is not able with using dict keys as method
is it possible?
thanks
Hello! Thanks for sharing your work. In a kubernetes env, it's useful to attach multiple (shared) configmaps to a service, etc. An attached configmap gets associated with a local directory. The capabilty to combine/overlay configs from several directories would be useful for python, too. Thank you.
Besides YML , JSON format would be very nice.
Hi Jonas,
I have an issue during the install of the new version of config2 (0.3.2).
It seems that there is an issue with the requirements of the mybad module.
Please find attached the log file (clean install from a docker image).
$ pip install config2
[...]
Collecting mybad>=0.1.4 (from config2)
Downloading https://files.pythonhosted.org/packages/fb/62/5366bda200b009452f4446ade7758f0a18be21a3131ca5e541d4b07e6d4e/mybad-0.2.0.tar.gz
ERROR: Complete output from command python setup.py egg_info:
ERROR: Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-s_jj15d_/mybad/setup.py", line 8, in <module>
import setupextras
ModuleNotFoundError: No module named 'setupextras'
Thank you for your help (and for the package ;))!
Jean-Baptiste
Example:
[2019-01-16 20:54:39 -0500] [11635] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/Users/grimen/.pyenv/versions/3.6.6/envs/3.6.6-default/lib/python3.6/site-packages/attributedict/collections.py", line 223, in __getattr__
return self.__getitem__(key)
File "/Users/grimen/.pyenv/versions/3.6.6/envs/3.6.6-default/lib/python3.6/site-packages/attributedict/collections.py", line 165, in __getitem__
result = self.__dict__.__getitem__(key)
KeyError: 'nn'
Useful for less verbose environment flag parsing.
Example:
config.truthy(None) # => False
config.truthy(False) # => False
config.truthy(0) # => False
config.truthy("0") # => False
config.truthy("false") # => False
config.truthy("False") # => False
config.truthy("FALSE") # => False
config.truthy("no") # => False # e.g. YAML
config.truthy("No") # => False # e.g. YAML
config.truthy("NO") # => False # e.g. YAML
config.truthy("") # => False
config.truthy("nil") # => False
config.truthy("null") # => False
config.truthy(True) # => True
config.truthy(1) # => True
config.truthy("1") # => True
config.truthy("true") # => True
config.truthy("True") # => True
config.truthy("TRUE") # => True
config.truthy("yes") # => True # e.g. YAML
config.truthy("Yes") # => True # e.g. YAML
config.truthy("YES") # => True # e.g. YAML
config.truthy({}) # => True
config.truthy([]) # => True
This utility works fine when I am using it in development env, but when I package my project and install to my local virtual env, it will complain following:
ImportError: cannot import name 'config' from 'config2.config'.
Looks like it cannot find the configuration files, how can I solve this problem?
Thanks
config = Config() # => `detect = False`, but should be `detect = True`
This morning our builds started failing, and it appears that all versions of the codecov package have been yanked from PyPI: https://pypi.org/project/codecov/
So please remove the codecov >= 2.0.15 dependency or implement a alternate solution
First of all, thanks for building this library! I was banging my head against a wall trying to find a simple-yet-powerful application config approach like node-config in the Python ecosystem.
Unfortunately, pip
-installing config2
installs its development dependencies as well. As of 2020, I would suggest to simply replace the setuptools-setupextras-based approach with Poetry to reduce manual boilerplate code. I would be happy to submit a PR if you welcome this.
I also have a few more problems and solutions in mind. Let me know if you welcome contributions, and I will file them in separate issues. Cheers!
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.