Changeset 5649

Show
Ignore:
Timestamp:
11/02/08 22:34:37 (2 months ago)
Author:
mramm
Message:

A few updates to the config docs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • docs/2.0/docs/main/Config.rst

    r5151 r5649  
    11TurboGears 2 Configuration 
    22=================================== 
     3 
     4TurboGears 2 provides a configuration system that attempts to be both extremely flexible for power users and very simple to use for standard projects.  
     5 
     6Overview 
     7-------------------------- 
    38 
    49Like TurboGears 1, the application configuration is separated from the  
    510deployment specific information.  In TG2 there is a config module, containing  
    611several configuration specific python files -- these are done in python not 
    7 as INI files, because they actually setup the TG2 application, it's associated 
    8 WSGI middleware.  Besides which, these files are not intended to be edited by 
    9 application end-users. 
    10     
    11 All of this is similar to Pylons, but we've tried to make the configuration 
    12 as declarative as possible, and to move some of the code into the framework 
    13 to make end-user updates easier to process.  
     12as INI files, because they actually setup the TG2 application and it's associated WSGI middleware.  And these files are intended to be edited only by application developers, not by those deploying the application. 
     13 
     14At the same time the deployment level configuration is done in simple .ini files.  
     15 
     16All of this is similar to Pylons and to TurboGears 1, but slightly different from both.   
     17 
     18Differences from TurboGears 1 
     19~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     20 
     21Differences from Pylons 
     22~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     23 
     24TG2 has done quite a bit of work to simplify the config module in a standard pylons quickstart, and to make the configuration in those files  
     25as declarative as possible.  This makes it easier to make small updates to the config, and allows us to move some of the code into the framework.  This is particularly is important, as it allows the framework to evolve and change the middleware stack without forcing developers to constantly update their code with every release.  
     26 
     27 
    1428 
    1529The config module 
     
    2337    it belongs in the ini files. 
    2438 
    25 Our hope is that 90% of applications don't need to edit any of the config module 
    26 files, but for those who do, the most common file to change is  
     39Our hope is that 90% of applications don't need to edit any of the config module files, but for those who do, the most common file to change is  
    2740``app_config.py``  
    2841 
    29 .. code:: Wiki-20/wiki20/config/app_cfg.py 
    30     :revision: 4842 
     42.. code:: wiki_root/trunk/wiki20/config/app_cfg.py 
    3143    :language: python 
    3244     
    33 app_cfg.py exists primarily so that middleware.py and environment'py can import  
    34 and use the ``base_config`` object.   
     45app_cfg.py exists primarily so that middleware.py and environment'py can import and use the ``base_config`` object.   
    3546 
    36 The ``base_config`` object is an ``AppConfig()`` instance which acts either like a  
    37 normal object, or like a dictorary.  ``AppConfig()`` profides some sane defaults 
    38 in it's ``__init__``, but more than that it provides us with several methods that  
    39 work on the config values to produce the two functions that setup your  
    40 TurboGears app.   Since this is all done in your code, you can subclass or  
    41 overide ``AppConfig`` to get exactly the setup you want.   
     47The ``base_config`` object is an ``AppConfig()`` instance which allows you to  
     48access it's attributes like a normal object, or like a standard python dictorary.  One of the reasons for this is that ``AppConfig()`` provides some defaults in it's ``__init__``.  But equally important it provides us with several methods that work on the config values to produce the two functions that setup your TurboGears app.   Since this is all done in your code, you can subclass or overide ``AppConfig`` to get exactly the setup you want.   
    4249 
    43 The ``base_config`` object is special in that it transparently maps all  
    44 attribute access to an underlying dictionary. So, any attributes you add or  
    45 update will be automatically changed in the underlying dictionary.   
     50The ``base_config`` object that's created in app_cfg.py should be used to set whatever configuration values that belong to the application itself and are required for all instances of this app, as distinct from the configuration values that you set in the development.ini or production.ini files that are intended to be editable by those who deploy the app.  
    4651 
    47 If you'd prefer not t use this feature, you can just  
    48 treat it like a dictionary.   As part of the app loading process the  
    49 ``base_config`` object will be merged in with the config values from the .ini file you're using 
    50 to launch your app, and placed in in ``pylons.config``.  
     52As part of the app loading process the ``base_config`` object will be merged in with the config values from the .ini file you're using to launch your app, and placed in in ``pylons.config``.  
    5153 
    52 In addition to the attributes on the ``base_config`` object there are a number of  
    53 methods which are used to setup the environment for you application, and to  
    54 create the actual Turbogears WSGI application, and all the middleware you need. 
     54As we said, in  addition to the attributes on the ``base_config`` object there are a number of methods which are used to setup the environment for you application, and tocreate the actual Turbogears WSGI application, and all the middleware you need. 
    5555 
    56 You can override these methods to further customize you application, for various 
    57 advanced use cases, like adding custom middleware at arbitrary points in the  
    58 WSGI stack, or doing some unanticipated (by us) application environment  
    59 manipulation.  
     56You can override base_config's methods to further customize you application's WSGI stack, for various advanced use cases, like adding custom middleware at arbitrary points in the WSGI pipeline, or doing some unanticipated (by us) application environment manipulation.  And we'll look at the details of how that all works in the advanced configuration section of this document.  
    6057 
    6158Setting up the base configuration for your app 
     
    9289Let's take a closer look at the development.ini file: 
    9390 
    94 .. code:: Wiki-20/development.ini 
    95     :revision: 4842 
    96     :language: ini 
    9791 
    9892These files are standard INI files, as used by Paste Deploy.  The individual  
    9993sections are marked of with ``[]``'s.   
    10094 
     95There's complete Paste Deploy documentation available at: 
     96 
     97http://pythonpaste.org/deploy/ 
     98 
     99 
     100 
     101.. code:: wiki_root/trunk/development.ini 
     102    :language: ini 
     103    :section: default 
    101104 
    102105.. seealso:: 
     
    105108        <http://pythonpaste.org/deploy/>`_. 
    106109 
     110 
     111Advanced Configuration 
     112=================================== 
     113 
     114 
     115Modifying the environment loader and middleware stack 
     116-------------------------------------------------------- 
     117 
     118We've created a number of methods that you can use to override the way that particular pieces of the TG2 stack are configured.   
     119 
     120.. automodule:: tg.configuration 
     121.. autoclass::  AppConfig 
     122   :members: 
    107123 
    108124Embedding a TG app inside another TG app