# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['df_config',
 'df_config.apps',
 'df_config.config',
 'df_config.extra',
 'df_config.guesses',
 'df_config.management',
 'df_config.management.commands']

package_data = \
{'': ['*'], 'df_config': ['static/favicon/*', 'static/js/*']}

install_requires = \
['django>=2.1']

setup_kwargs = {
    'name': 'df-config',
    'version': '1.1.22',
    'description': 'Smart default settings for Django websites',
    'long_description': 'df_config\n=========\n\nDjango, *the web framework for perfectionists with deadlines*, is based on a single settings Python module defined in a environment variable.\nHowever, these settings could be organized into three categories:\n\n  * settings that are very common and that can be kept as-is for most projects (`USE_TZ = True` or `MEDIA_URL = \'/media/\'`),\n  * settings that are specific to your project but common to all instances of your project (like `INSTALLED_APPS`),\n  * settings that are installation-dependent (`DATABASE_PASSWORD`, …)\n\n\nMoreover, there are dependencies between settings. For example, `ADMIN_EMAIL`, `ALLOWED_HOSTS` and `CSRF_COOKIE_DOMAIN` depend\n on the same domain name of your site,  and `SESSION_COOKIE_SECURE` and `CSRF_COOKIE_SECURE` can be set only when you use TLS.\ndf_config allows to use functions to dynamically define these settings using some other settings as parameters.\n\n\nFinally, df_config dynamically merges several sources to define the final settings:\n\n  * :mod:`df_config.config.defaults` that aims at providing good default values,\n  * `yourproject.defaults` for your project-specific settings,\n  * `/etc/yourproject/settings(.py|.ini)` for installation-dependent settings,\n  * environment variables are also read if you prefer to use them.\n\ndf_config also defines settings that should be valid for most sites, based on common installed Django apps.\n\nYou can define a list of settings that are read from a traditionnal text configuration file (`.ini format <https://docs.python.org/3/library/configparser.html>`_).\nFinally, df_config also searches for environment variables, or `local_settings.py` and `local_settings.ini` setting files in the working directory.\n\n\nRequirements and installation\n-----------------------------\n\ndf_config works with:\n\n  * Python 3.6+,\n  * Django 2.0+.\n  \n```bash\npython -m pip install df_config\n```\n  \nHow to use it?\n--------------\n\ndf_config assumes that your project has a main module `yourproject`.\nThen you just have two steps to do:\n\n- update your `manage.py` file: \n\n```python\n#!/usr/bin/env python\nfrom df_config.manage import manage, set_env\n\nset_env(module_name="yourproject")\nif __name__ == "__main__":\n    manage()\n\n```\n\n- copy your current settings (as-is) into `yourproject/defaults.py`,\n\n\nYou can take a look to the resulting settings and from which source they are read:\n```bash\npython3 manage.py config python -v 2\n```\n\nIf you want a single settings file, you can also create it:\n\n```bash\npython3 manage.py config python --filename settings.py\n```\n\n\nupdate your setup.py\n--------------------\n\nYou should the entry point in your `setup.py` file:\n\n```python\nentry_points = {"console_scripts": ["yourproject-ctl = df_config.manage:manage"]}\n``` \n\nOnce installed, the command `yourproject-ctl` (in fact, you can change `ctl` by anything without hyphen) executes the standard `maanage` command. \n\n\ndynamize your settings!\n-----------------------\n\nFirst, you can provide sensible defaults settings in `yourproject.py` and overwrite the dev settings in `local_settings.py`.\nThen real things can begin:\nFor example, imagine that you currently have the following settings:\n\n```python\nLOG_DIRECTORY = \'/var/myproject/logs\'\nSTATIC_ROOT = \'/var/myproject/static\'\nMEDIA_ROOT = \'/var/myproject/media\'\nFILE_UPLOAD_TEMP_DIR = \'/var/myproject/tmp\'\n```\n\nIf you change the base directory `/var/myproject`, four variables needs to be changed (and you will forget to change at least one).\nNow, you can write:\n\n```python\nLOCAL_PATH = \'/var/myproject\'\nLOG_DIRECTORY = \'{LOCAL_PATH}/logs\'\nSTATIC_ROOT = \'{LOCAL_PATH}/static\'\nMEDIA_ROOT = \'{LOCAL_PATH}/media\'\nFILE_UPLOAD_TEMP_DIR = \'{LOCAL_PATH}/tmp\'\n```\n\nNow, you just have to redefine `LOCAL_PATH`; but you can even go slightly further:\n\n```python\nfrom df_config.config.dynamic_settings import Directory\nLOCAL_PATH = Directory(\'/var/myproject\')\nLOG_DIRECTORY = Directory(\'{LOCAL_PATH}/logs\')\nSTATIC_ROOT = Directory(\'{LOCAL_PATH}/static\')\nMEDIA_ROOT = Directory(\'{LOCAL_PATH}/media\')\nFILE_UPLOAD_TEMP_DIR = Directory(\'{LOCAL_PATH}/tmp\')\n```\n\nIf you run the `check` command, you will be warned for missing directories, and the `collectstatic` and `migrate` commands\nwill attempt to create them.\nOf course, you still have `settings.MEDIA_ROOT == \'/var/myproject/media\'` in your code, when settings are loaded.\n\n\nYou can use more complex things, instead of:\n\n```python\nSERVER_BASE_URL = \'http://www.example.com\'\nSERVER_NAME = \'www.example.com\'\nUSE_SSL = False\nALLOWED_HOSTS = [\'www.example.com\']\nCSRF_COOKIE_DOMAIN = \'www.example.com\'\n```\n\nYou could just write:\n\n```python\nfrom urllib.parse import urlparse\nfrom df_config.config.dynamic_settings import CallableSetting\n\nSERVER_BASE_URL = \'http://www.example.com\'\nSERVER_NAME = CallableSetting(lambda x: urlparse(x[\'SERVER_BASE_URL\']).hostname, \'SERVER_BASE_URL\')\nUSE_SSL = CallableSetting(lambda x: urlparse(x[\'SERVER_BASE_URL\']).scheme == \'https\', \'SERVER_BASE_URL\')\nALLOWED_HOSTS = CallableSetting(lambda x: [urlparse(x[\'SERVER_BASE_URL\']).hostname], \'SERVER_BASE_URL\')\nCSRF_COOKIE_DOMAIN = CallableSetting(lambda x: urlparse(x[\'SERVER_BASE_URL\']).hostname, \'SERVER_BASE_URL\')\n```\n\nConfiguration files and environment variables\n---------------------------------------------\n\nYour user probably prefer use .ini files instead of Python ones.\nBy default, df_config searches for a list `INI_MAPPING` into the module `yourproject.iniconf` or uses `df_config.iniconf.INI_MAPPING`.\n\n```python\nfrom df_config.config.fields import ConfigField\nINI_MAPPING = [ConfigField("global.server_url", "SERVER_BASE_URL", help_str="Public URL of your website.", env_name="SERVER_BASE_URL")]\n```\n\nSome specialized classes are available in `df_config.config.fields`: `CharConfigField`, `IntegerConfigField`, `FloatConfigField`, `ListConfigField`, `BooleanConfigField`, `ChoiceConfigFile`.\nYou can also pickup some predefined list in `df_config.iniconf`.\n\nYou can also use environment variables instead of an .ini file (only for values in the INI_MAPPING list):\n```bash\nexport SERVER_URL=http://www.example-2.com\npython3 manage.py config python -v 2 | grep SERVER_BASE_URL\n```\n\nYou can check the current config as a .ini file or as environment variables: \n```bash\nexport SERVER_URL=http://www.example-2.com\npython3 manage.py config env\npython3 manage.py config ini\n```\n\ndynamic settings\n----------------\n\nBy default, any `str` is assumed to be a template string: for example, `LOG_DIRECTORY = \'{LOCAL_PATH}/logs\'` needs `LOCAL_PATH` to be defined.\nSo, if one of your setting include such values, it need to be encapsulated:\n\n```python\nfrom df_config.config.dynamic_settings import RawValue\nLOG_DIRECTORY = RawValue(\'{LOCAL_PATH}/logs\')\n```\n\nOther dynamic classes are:\n```python\nfrom df_config.config.dynamic_settings import Directory, AutocreateFileContent, SettingReference, CallableSetting, ExpandIterable\nfrom df_config.guesses.misc import generate_secret_key, secure_hsts_seconds\nDIRNAME = Directory("/tmp/directory")\n# creates /tmp/directory with collectstatic/migrate commands, otherwise you have a warning \nSECRET_KEY = AutocreateFileContent("{LOCAL_PATH}/secret_key.txt", generate_secret_key, mode=0o600, use_collectstatic=False,use_migrate=True)\n# if the file does not exist, SECRET_KEY = generate_secret_key()\n# if the file does exist, SECRET_KEY is equal to its content\n# if the migrate command is called and the file does not exist, it is created and the result of generate_secret_key() is written to it\nTEMPLATE_DEBUG = SettingReference(\'DEBUG\')\n# TEMPLATE_DEBUG is always equal to DEBUG, even if DEBUG is defined in another file\nSECURE_HSTS_SECONDS = CallableSetting(secure_hsts_seconds, "USE_SSL")\n# the secure_hsts_seconds is called with a dict that contains the currently resolved settings\n# at least USE_SSL is present in this dict (maybe some other values are also defined)\n# the list of required settings can be directly set as an attribute of the callable:\n# secure_hsts_seconds.required_settings = ["USE_SSL"]\n# SECURE_HSTS_SECONDS = CallableSetting(secure_hsts_seconds)\nINSTALLED_APPS = ["django.contrib.admin", ..., ExpandIterable("EXTRA_APPS"), "django.contrib.auth"]\n# EXTRA_APPS must be a list, whose values are inserted in the final valaues\n\n```\n\nserver command\n--------------\n\nYou can choose the application server used in production:\n```python\nDF_SERVER = "gunicorn"  # "gunicorn" or "daphne"\n```\nA new Django command `server` is available and launches `gunicorn` or `daphne`. The application and the listen address/port are specified so you do no have to set them. \n\n\nHeroku\n------\n\nEnvironment variable names have been chosen to be compatible with the Heroku default environment: \n\n  * `SECRET_KEY`: should set it in your `app.json` file\n  * `DATABASE_URL`: automatically set by the "heroku-postgresql" addon\n  * `PORT`: set by default\n  * `HEROKU_APP_NAME`: you should set it in your `app.json` file\n  \nDjango app detection\n--------------------\n\nA few well-known Django applications are automatically detected and added to the list of `INSTALLED_APPS`:\n\n  * `django-redis_sessions`\n  * `django-pipeline`\n  * `django-debug-toolbar`\n  * `django-allauth`\n  * `whitenoise`\n  * `django-csp`\n  \nDefaults settings are also proposed so these applications should be working out of the box.\n\n',
    'author': 'Matthieu Gallet',
    'author_email': 'github@19pouces.net',
    'maintainer': 'Matthieu Gallet',
    'maintainer_email': 'github@19pouces.net',
    'url': 'https://github.com/d9pouces/df_config',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.9,<4.0',
}


setup(**setup_kwargs)
