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 organization

  • has_db - whether the app has a Rattail DB

  • has_batch_schema - whether the DB needs dynamic ‘batch’ schema

  • db_name - name of the Rattail DB

  • has_datasync - whether the app needs a datasync service

  • has_web - whether the app has tailbone web UI

  • has_web_api - whether the app has tailbone web API

  • beaker_session_secret - secret for Beaker session storage

  • uses_fabric - whether the app is deployed via fabric

generate_project(output, context, **kwargs)[source]

Generate a new project to the given output folder, with the given context data.

Parameters:
  • output – Path to output folder. This path should already exist.

  • context – Dictionary of template context data.

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 call generate_mako()

  • if filename ends with .mako_tmpl then call generate_mako_tmpl()

  • otherwise copy file as-is (do not “generate” output)

Parameters:
  • template – Path to template file.

  • output – Path to output file.

  • context – Data dictionary with template context.

generate_mako(template, output, context)[source]

Generate output from a Mako template.

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.

Parameters:
  • output – Path to output folder. This path should already exist.

  • context – Dictionary of template context data.

get_template_path(template)[source]

Return the full path to a template file.

Parameters:

template – Filename of the template, e.g. 'setup.py'.

classmethod get_templates_path()[source]

Return the path to templates folder for this generator.

This is a class method for sake of inheritance, so templates can more easily be shared by generator subclasses.

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 project

  • folder - 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 environment

  • requires - dict of required dependencies

  • classifiers - set of Python trove classifiers for project

  • entry_points - dict of setuptools entry points for project

generate_project(output, context, **kwargs)[source]

Generate a new project to the given output folder, with the given context data.

Parameters:
  • output – Path to output folder. This path should already exist.

  • context – Dictionary of template context data.

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 config

  • has_cli - whether the app has its own command interface

  • extends_db - whether the app extends DB schema

  • has_model - whether the app provides top-level ORM model

generate_project(output, context, **kwargs)[source]

Generate a new project to the given output folder, with the given context data.

Parameters:
  • output – Path to output folder. This path should already exist.

  • context – Dictionary of template context data.