Package: djangorecipebook
© 2014-2020 Thomas KhynBuildout recipes for django developmentAboutThe recipes available in djangorecipebook are mostly derived fromdjangorecipe’s functionalities. However, while djangorecipe aims at generating
all scripts in one part, djangorecipebook enables you to define one part per
script (create, manage, wsgi, test, makemigrations), hence allowing the use of
different settings and/or eggs for each part.Through its automatic minimal settings generation, djangorecipebook is
particularly adapted to reusable apps development, e.g. for testing or
maintenance (migrations generation).djangorecipebook works with django 2.2 and 3.0 and relevant python versions
(3.5 to 3.8, depending on django version).If you like djangorecipebook and find it useful, you may want to thank me and
encourage future development by sending a few mBTC / mBCH / mBSV at this address:1EwENyR8RV6tMc1hsLTkPURtn5wJgaBfG9.Available recipesdjangorecipebook:manageCreates a management script for the projectdjangorecipebook:wsgiCreates a wsgi script for the projectdjangorecipebook:gunicornCreates a gunicorn service launcher for the projectdjangorecipebook:testCreates a script that invokesmanage.py test [apps], orpytestdjangorecipebook:makemigrations (new in v1.2)Generates Django migrations
If you need to generatesouthmigrations for Django < 1.7, you need to
use djangorecipe 1.2.x or 1.3.xdjangorecipebook:migrate (new in v1.2)Invokesmanage.py migrate [apps]. For the lazy ones.djangorecipebook:createCreates a django project from a user-defined template or using django’sstartprojectmanagement command. This recipe will not generate any
script. The name of the created project is the name of the section.OptionsCommon optionsproject-dirThe directory where the project files lie, relative to the buildout.cfg
directory.Defaults to'.'(buildout directory).settingsThe settings module to load, imported from the project directory.Defaults to'settings'or a set of minimal settings, depending on the
recipe.extra-pathsPaths to add to sys.path in the generated script.Defaults to[].envvarsAny environment variable that need to be set for the test run, one per line,
under the formVARIABLE = value(spaces are tolerated).Defaults to no environment variable set.initializationSome (basic) python initialization code to insert in the generated script.
Don’t forget that leading whitespaces are stripped.Defaults to''.Manage optionssettingsIf a settings module is not provided, the settings will be a set of minimal
parameters, with the added installed apps below.Defaults to minimal settings.inst_appsThe apps to add to theINSTALLED_APPSsetting if no settings module is
provided. This option should not be used when a settings module is provided.Defaults to''.commandThe management command to run, if any.Defaults to no command (and in that case theargsoption is disabled).argsAny command-line argument you wish to have added to the generated script,
separated by spaces or line-breaks.Defaults to no arguments.WSGI and gunicorn optionssettingsMust be a settings module, no default minimal settings are available for
these recipes.log-fileThe path to a log file where all stdout and/or stderr data should be
redirected to.Defaults to'', which disables logginglog-levelThe level to log errors for. Can be one of INFO (stdout + stderr) or
ERROR (stderr only).Defaults toINFO.virtualenvThe virtualenv that should be used to run the wsgi script. This
requires virtualenvandvirtualenvwrapper, as it relies upon theWORKON_HOMEenvironment variable.Defaults to'', which disables any virtual environment setup.script_pathThe desired output path of the script, as a path to a filename relative to
the buildout directory (= where thebuildout.cfgfile lies).Defaults to buildout’s bin directory with the recipe’s name.application (wsgi and gunicorn only)Used with thewsgirecipe, it is the dotted path to a user-defined wsgi
application, and defaults to the result of django’sget_wsgi_application().Used with thegunicornrecipe, it can be:unspecified (default), which means that thegunicornscript must be
called with an parameter defining the WSGI applicationapath/to/a/wsgi:application. Thegunicornscript will set the
current working directory topath/to/aand usewsgi:applicationas the application parameterauto. The recipe will automatically generate awsgimodule
using the providedsettings,log-fileandlog-level, and
thegunicornscript will refer to that moduleTest optionsWarningWhen usingrunner = pytest, thesettings,inst_apps,appsoptions have no effect. You should instead provide apytest configuration filein the tests working directory.runnerReplaces `nose` option from version 1.3Use this option if you are usingnose(and thereforedjango_nose) to test
your Django app or project. This will simply includedjango_noseandnosein your buildout.Defaults to unset.workingdirThe working directory to launch the tests from.Defaults to the currentargsSeeManage options.settings, inst_appsSeeManage options. Note that thecommandoption is disabled. Not
available when using pytest.appsThe names of the apps that should be tested, separated by spaces or
line-breaks. If using minimal settings, these apps will be added to theINSTALLED_APPS(in addition to those in theinst_appsoption).Defaults to'', all the apps inINSTALLED_APPS. Not available when
usingrunner = pytestMakemigrations optionssettings, inst_apps, argsSeeManage options. Note that thecommandoption is disabled.appsThe names of the apps for which migrations should be generated, separated
by spaces or line-breaks. If using minimal settings, these apps will be
added to theINSTALLED_APPS(in addition to those in theinst_appsoption).Defaults to'', all the apps inINSTALLED_APPSMigrate optionsSame options as inTest options. The only difference is that you cannot use
minimal settings (the default is'settings') nor theinst_appsoption.
Indeed, migrations generally need a database to migrate!Create optionsIn create mode, the following common options are unused:extra-pathsinitializationThe settings import path must be set as it is used to determine whether the
project has already been created or not.The following options are added:template-dirsThe directories in which to search for user-defined project templates. This
option may also be added in a[djangorecipebook]section (for example in
the default.cfg file). See theTemplates discoverysection below.Defaults to the built-in templates directory, containing default django
project templates.templateThe template that should be used.Defaults to the standard django project for the major version of django you
are using.secretTheSECRET_KEYto be used in the created settings file(s).Defaults to a randomly generated alphanumeric key.For more details on templating, see theTemplatessection below.TemplatesIn create mode, a templating engine is available for greater personalisation
of your django project initialization.Templates discoveryIf atemplate-dirsoption is found either in the recipe section or in a
specificdjangorecipebooksection, the recipe searches in these directories
- from the last defined to the first - for a subdirectory name matching thetemplatename provided.If the search is unsuccessful or if none oftemplate-dirsortemplateare
defined, the recipe uses the default template for the major version of django
being used.For example, if in ~/.buildout/default.cfg you have the following lines:[djangorecipebook]
template-dirs =
  /my/project/template/directory
  /my/project/template/directory2And your buildout.cfg contains this section:[mynewproject]
recipe = djangorecipebook:create
template-dirs = /my/other/template/dir
template = mytemplateThe recipe will search for amytemplatedirectory in that order:/my/other/template/dir/my/project/template/directory2/my/project/template/directoryTemplate engineThe template engine is as simple as it can be and relies upon pythons’sstring.Template. A variable can be inserted in any file or directory name or
file content in template directory using the syntax${variable}.The following variables are available:any user-defined recipe option from the configuration filesecret: the secret key for django settingsproject_name: the project name (= the section name)year: the current yearmonth: the current monthday: the current day of the monthFor example, if you have in buildout.cfg:[mynewproject]
recipe = djangorecipebook:create
template = mytemplate
author = Thomas Khynfor a copyright notice in a module docstring, you may use:(c) ${year} ${author}which will produce to the following output in the final file (if we are in
2014):(c) 2014 Thomas Khynor, if you have a directory named${project_name}_parameters, the final name
will bemynewproject_parameters.