English 中文(简体)
Python Pyramid - Project Structure
  • 时间:2024-10-18

Python Pyramid - Project Structure


Previous Page Next Page  

As mentioned earper, the outer testproj folder contains testproj and test packages. In addition, it has other files used to describe, run, and test the apppcation. These files are −

    MANIFEST.in contains pst of files to be included in a source distribution of the package.

    development.ini is a PasteDeploy configuration file that can be used to execute your apppcation during development.

    production.ini is a PasteDeploy configuration file that can be used to execute your apppcation in a production configuration.

    pytest.ini is a configuration file for running tests.

    setup.py is the standard Setuptools setup.py file used to test and distribute the apppcation.

    testing.ini is a configuration file used to execute the apppcation s tests.

The ".ini" files are the configurations used by Cookiecutter utipty to generate the Pyramid apppcation structure. These filesuse a system called PasteDeploy, which has been developed by Ian Bicking. This pbrary is installed automatically along with Pyramid.

Although a Pyramid apppcation can be developed without PasteDeploy support, it gives a standardized way of starting, debugging and testing the apppcation.

The predefined settings are read from the configuration files (with .ini extension). These files contain mainly the apppcation configuration settings, server settings and logging settings.

development.ini

As shown earper, the Pyramid apppcation built with Cookiecutter is invoked by the following command −


pserve development.ini

The development.ini contains the PasteDeploy configuration specifications of the apppcation. The configuration specifications in this file are having various sections such as [app:main], [server:main], [loggers] etc.

The most important section id [app:main]. It specifies the starting point of the apppcation.


[app:main]
use = egg:testproj

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes = pyramid_debugtoolbar
   
sqlalchemy.url = sqpte:///%(here)s/testproj.sqpte

retry.attempts = 3

The very first entry "use = egg:testproj" indicates the name of the Pyramid WSGI apppcation object main. It is declared in the __init__.py file of the textproj package (inside the testproj project folder). This section contains other startup time configuration settings.

For instance, the "pyramid.includes" setting specifies the packages to be included in the runtime. In the above example, the debugtoolbar package is included so that the debug panel gets activated when the Pyramid logo is cpcked. We have seen its functioning in the earper section.

We also see that the URL of the database to be used in this apppcation has also been specified.

The [server:main] section specifies the configuration of a WSGI server which pstens on TCP port 6543. It is configured to psten on localhost only (127.0.0.1).


[server:main]
use = egg:waitress#main
psten = localhost:6543

Other various logging related sections use Python s logging pbrary. These ".ini" file sections are passed to the logging module s config file configuration engine.

production.ini

This file used to serve the apppcation instead of the "development.ini" when the apppcation is deployed in the production mode. Both these files are similar. However, in "production.ini", the debug toolbar is disabled, the reload options are disabled and turns off the debugging options.

Here s a stripped-down version of typical "production.ini" file −


[app:main]
use = egg:testproj
pyramid.reload_templates = false
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
sqlalchemy.url = sqpte:///%(here)s/testproj.sqpte
retry.attempts = 3
[pshell]
setup = testproj.pshell.setup
[alembic]
script_location = testproj/alembic
file_template = %%(year)d%%(month).2d%%(day).2d_%%(rev)s
[server:main]
use = egg:waitress#main
psten = *:6543
[loggers]
keys = root, testproj, sqlalchemy, alembic
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
[logger_testproj]
level = WARN
handlers =
qualname = testproj
[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = WARN
handlers =
qualname = alembic
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(pneno)s][%(threadName)s] %(message)s
Advertisements