Giter Site home page Giter Site logo

osantana / prettyconf Goto Github PK

View Code? Open in Web Editor NEW
178.0 14.0 8.0 145 KB

A extensible library for Settings/Code separation

Home Page: https://pypi.python.org/pypi/prettyconf

License: MIT License

Python 99.21% Makefile 0.78% Shell 0.02%
python python-3 python-2 configuration twelve-factor mit

prettyconf's Introduction

prettyconf

Build Status Coverage Status Docs Codacy Landscape

Pretty Conf is a Python library created to make easy the separation of configuration and code following the recomendations of 12 Factor's topic about configs.

It is strongly inspired in python-decouple and both provides a similar API.

Documentation

You can find prettyconf documentation at Read the Docs website.

prettyconf's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prettyconf's Issues

Flaky test

tests/test_commandline.py::test_ignores_not_set_values can fail when running with pytest --randomly-seed=123.

ImportError: No module named configparser

Since January, I've noticed pip keeps on warning me about the end of Python 2.7 support and I've been getting some weird buildout and instance errors.

As mentioned by @jaroel on the Plone Community forum, there might be an issue with prettyconf, which causes the following error:

  File "/home/ubuntu/workspace/eggs/z3c.autoinclude-0.3.7-py2.7.egg/z3c/autoinclude/zcml.py", line 101, in includePluginsDirective
    info = PluginFinder(dotted_name).includableInfo(zcml_to_look_for)
  File "/home/ubuntu/workspace/eggs/z3c.autoinclude-0.3.7-py2.7.egg/z3c/autoinclude/plugin.py", line 18, in includableInfo
    groups = zcml_to_include(plugin_dottedname, zcml_to_look_for)
  File "/home/ubuntu/workspace/eggs/z3c.autoinclude-0.3.7-py2.7.egg/z3c/autoinclude/plugin.py", line 36, in zcml_to_include
    filename = resource_filename(dotted_name, zcmlgroup)
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1142, in resource_filename
    return get_provider(package_or_requirement).get_resource_filename(
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 359, in get_provider
    __import__(moduleOrReq)
  File "/home/ubuntu/workspace/eggs/contentrules.slack-1.0.0a1-py2.7.egg/contentrules/slack/__init__.py", line 3, in <module>
    from prettyconf import config
  File "/home/ubuntu/workspace/eggs/prettyconf-2.0.1-py2.7.egg/prettyconf/__init__.py", line 1, in <module>
    from .configuration import Configuration
  File "/home/ubuntu/workspace/eggs/prettyconf-2.0.1-py2.7.egg/prettyconf/configuration.py", line 7, in <module>
    from .loaders import Environment, RecursiveSearch
  File "/home/ubuntu/workspace/eggs/prettyconf-2.0.1-py2.7.egg/prettyconf/loaders.py", line 2, in <module>
    from configparser import ConfigParser, MissingSectionHeaderError, NoOptionError
zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "/home/ubuntu/workspace/parts/instance/etc/site.zcml", line 12.2-12.39
    ZopeXMLConfigurationError: File "/home/ubuntu/workspace/eggs/Products.CMFPlone-5.1.4-py2.7.egg/Products/CMFPlone/meta.zcml", line 37.4-41.10
    ImportError: No module named configparser

See collective/contentrules.slack#2 for more details

Add a config.str cast that "eval" shell strings (e.g. strip double/single quote)

Useful to make .env more "compatible" with a sourceable shell file. And avoid problems with things like silently fail on parsing this kind of URLs:

  • DATABASE_URL="postgresql://user:pass@host/db"

Optional (depending on security concerns):

  • User expand like ~ -> ${HOME} or ~user -> /home/user|/Users/user
  • Expand at least environment variables (how useful this feature could be?)

A new configuration discovery strategy.

If I write an app which has code in /opt/app and I would like users to optionally put a config.ini in /etc/app/, there is no way to do it through prettyconf's current discovery strategy.
It would be nice to be able to configure this behavior.
I imagine something like:

from prettyconf.configuration import env_vars, dirs, recursive

config.strategies = [
     env_vars, 
     dirs('/etc/app', '~/.configs/app'], 
     recursive(root_dir='/', starting_path='./')
]

The above snippet means that a config variable would be first checked within the environment variables,
if it is not found there, it would look at /etc/app, etc.

What do you think? I'm currently facing this issue and I'm willing to work on this.

Provide a configuration class

Just sharing my thoughts here. This is inspired by GoodConf, and the idea is to allow encapsulating settings inside a structure other than a python module.

from prettyconf import PrettyConf, Value

class AppConfig(PrettyConf):
    "Configuration for My App"
    class Meta:
        loaders = [EnvLoader(), IniFile('/etc/conf.ini/')]
    
    DEBUG = Value(default=False, help="Toggle debugging.")
    DATABASE_URL = Value(
        default='postgres://localhost:5432/mydb',
        help="Database connection.")

Later this object can be used to print settings

>>> conf = AppConfig()
>>> print(conf)
DEBUG=True
DATABASE_URL=postgres://localhost:5432/mydb

Or with __repl__()

>>> conf = AppConfig()
>>> conf
DEBUG=True - Toggle debugging
DATABASE_URL=postgres://localhost:5432/mydb - Database connection.

extended

from base_config import AppConfig

class DevConfig(AppConfig):
    LOG_LEVEL=Value(default='debug')

or passed around

def do_something(cfg):
    if cfg.DEBUG:   # this is evaluated lazily
         return

We would use the existing plumbing to expose this class, which would be another option to use prettyconf.

I don't like that the config('debug') call isn't lazy, so putting it into a class isn't enough:

class MyConfig():
    debug = config('debug')   # this is evaluated when this module is loaded

Printing the current project's config settings is not easy, since there is a lot of garbage in any python module or class.

Any thoughts?

prettyconf crashes when a .env directory exists somewhere in the path

When somewhere in the parent path there is a valid .env directory, prettyconf refuses to load and crashes:

File "/home/name/some/folder/.direnv/lib/python3.7/site-packages/prettyconf/loaders.py", line 253, in check
self._parse()
File "/home/name/some/folder/.direnv/lib/python3.7/site-packages/prettyconf/loaders.py", line 242, in _parse
with open(self.filename) as envfile:
IsADirectoryError
:[Errno 21] Is a directory: '/home/name/.env'

Affected Version: 2.0.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.