rattail.projects.base
¶
Project Generators
- class rattail.projects.base.PoserProjectGenerator(config, **kwargs)[source]¶
Base class for Poser project generators.
In addition to normal context for “Rattail-adjacent” projects, all Poser projects are assumed to have the following context:
organization
- human-friendly name for the organizationhas_db
- whether the app has a Rattail DBhas_batch_schema
- whether the DB needs dynamic ‘batch’ schemadb_name
- name of the Rattail DBhas_datasync
- whether the app needs a datasync servicehas_web
- whether the app has tailbone web UIhas_web_api
- whether the app has tailbone web APIbeaker_session_secret
- secret for Beaker session storageuses_fabric
- whether the app is deployed via fabric
- class rattail.projects.base.ProjectGenerator(config, **kwargs)[source]¶
Base class for project generators.
- key¶
Unique key for the project type.
- generate(template, output, context=None, **kwargs)[source]¶
Generate a file from the given template, and save the result to the given output path.
This will do one of 3 things based on the specified template:
if filename ends with
.mako
then callgenerate_mako()
if filename ends with
.mako_tmpl
then callgenerate_mako_tmpl()
otherwise copy file as-is (do not “generate” output)
- generate_mako_tmpl(template, output, context)[source]¶
Generate output (which is itself a Mako template) from a “simple” original template.
Sometimes you want the final output to be a Mako template, but your original template also must be dynamic, based on context. It’s problematic (confusing at the very least) for an original Mako template to produce output which is also a Mako template. So instead..
If you give your original template file a
.mako_tmpl
extension, then the output will still be dynamic, but instead of running the original template through the Mako engine, we leverage Python strings’ printf-style formatting.A small example template might be
rattail.conf.mako_tmpl
:<%%text>##############################</%%text> # example config <%%text>##############################</%%text> [rattail] app_title = ${app_title} [alembic] script_location = rattail.db:alembic version_locations = %(alembic_version_locations)s # -- LOGGING SECTION -- [formatter_generic] format = %%(asctime)s %%(levelname)-5.5s [%%(name)s][%%(threadName)s] %%(funcName)s: %%(message)s datefmt = %%Y-%%m-%%d %%H:%%M:%%S
Note the Mako syntax which is ignored (passed through as-is) by this method when generating output.
Note also this template expects
alembic_version_locations
to be provided via the context.Finally also note the doubled-up
%
chars, both in<%%text>
as well as in the logging section. Since printf-style formatting uses the%
char, we must escape those by doubling-up; the formatter will convert each back to single chars for the output.For more info on the formatting specifics see printf-style String Formatting.
So with context like:
{'alembic_version_locations': 'rattail.db:alembic/versions'}
The above example would produce output
rattail.conf.mako
:<%text>##############################</%text> # example config <%text>##############################</%text> [rattail] app_title = ${app_title} [alembic] script_location = rattail.db:alembic version_locations = rattail.db:alembic/versions # -- LOGGING SECTION -- [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(funcName)s: %(message)s datefmt = %Y-%m-%d %H:%M:%S
- generate_project(output, context, **kwargs)[source]¶
Generate a new project to the given output folder, with the given context data.
- class rattail.projects.base.PythonProjectGenerator(config, **kwargs)[source]¶
Base class for Python project generators.
All projects generated are assumed to have the following context:
name
- human-friendly name for the project, e.g."Poser Plus"
description
- brief (one-line) description of the projectfolder
- folder name for the project, e.g."poser-plus"
pkg_name
- package name for use in Python, e.g."poser_plus"
pypi_name
- package name for use with PyPI, e.g."Poser-Plus"
egg_name
- package name used with egg files, e.g."Poser_Plus"
studly_prefix
- prefix for class names, e.g.PoserPlus
env_name
- name of the Python virtual environmentrequires
- dict of required dependenciesclassifiers
- set of Python trove classifiers for projectentry_points
- dict of setuptools entry points for project
- class rattail.projects.base.RattailAdjacentProjectGenerator(config, **kwargs)[source]¶
Base class for “Rattail-adjacent” project generators, i.e. for projects which are based on Rattail, but may or may not be full “Poser” type apps.
In addition to normal context for Python projects, all Rattail-adjacent projects are assumed to have the following context:
extends_config
- whether the app extends Rattail confighas_cli
- whether the app has its own command interfaceextends_db
- whether the app extends DB schemahas_model
- whether the app provides top-level ORM model