Temple Package

temple.setup

Creates and initializes a project from a template

temple.setup.setup(template, version=None)[source]

Sets up a new project from a template

Note that the temple.constants.TEMPLE_ENV_VAR is set to ‘setup’ during the duration of this function.

Parameters:
  • template (str) – The git SSH path to a template
  • version (str, optional) – The version of the template to use when updating. Defaults to the latest version

temple.update

Updates a temple project with the latest template

temple.update.up_to_date(version=None)[source]

Checks if a temple project is up to date with the repo

Note that the temple.constants.TEMPLE_ENV_VAR is set to ‘update’ for the duration of this function.

Parameters:

version (str, optional) – Update against this git SHA or branch of the template

Returns:

True if up to date with version (or latest version), False otherwise

Return type:

boolean

Raises:
temple.update.update(old_template=None, old_version=None, new_template=None, new_version=None, enter_parameters=False)[source]

Updates the temple project to the latest template

Proceeeds in the following steps:

  1. Ensure we are inside the project repository
  2. Obtain the latest version of the package template
  3. If the package is up to date with the latest template, return
  4. If not, create an empty template branch with a new copy of the old template
  5. Create an update branch from HEAD and merge in the new template copy
  6. Create a new copy of the new template and merge into the empty template branch
  7. Merge the updated empty template branch into the update branch
  8. Ensure temple.yaml reflects what is in the template branch
  9. Remove the empty template branch

Note that the temple.constants.TEMPLE_ENV_VAR is set to ‘update’ for the duration of this function.

Two branches will be created during the update process, one named _temple_update and one named _temple_update_temp. At the end of the process, _temple_update_temp will be removed automatically. The work will be left in _temple_update in an uncommitted state for review. The update will fail early if either of these branches exist before the process starts.

Parameters:
  • old_template (str, default=None) – The old template from which to update. Defaults to the template in temple.yaml
  • old_version (str, default=None) – The old version of the template. Defaults to the version in temple.yaml
  • new_template (str, default=None) – The new template for updating. Defaults to the template in temple.yaml
  • new_version (str, default=None) – The new version of the new template to update. Defaults to the latest version of the new template
  • enter_parameters (bool, default=False) – Force entering template parameters for the project
Raises:
Returns:

True if update was performed or False if template was already up to date

Return type:

boolean

temple.ls

Lists all temple templates and projects spun up with those templates

temple.ls.ls(github_user, template=None)[source]

Lists all temple templates and packages associated with those templates

If template is None, returns the available templates for the configured Github org.

If template is a Github path to a template, returns all projects spun up with that template.

ls uses the github search API to find results.

Note that the temple.constants.TEMPLE_ENV_VAR is set to ‘ls’ for the duration of this function.

Parameters:
  • github_user (str) – The github user or org being searched.
  • template (str, optional) – The template git repo path. If provided, lists all projects that have been created with the provided template. Note that the template path is the SSH path (e.g. git@github.com:CloverHealth/temple.git)
Returns:

A dictionary of repository information keyed on the SSH Github url

Return type:

dict

Raises:

InvalidGithubUserError – When github_user is invalid

temple.constants

Constants for temple

temple.constants.GITHUB_API_TOKEN_ENV_VAR = 'GITHUB_API_TOKEN'

The Github API token environment variable

temple.constants.TEMPLE_CONFIG_FILE = 'temple.yaml'

The temple config file in each repo

temple.constants.TEMPLE_DOCS_URL = 'https://github.com/CloverHealth/temple'

Temple docs URL

temple.constants.TEMPLE_ENV_VAR = '_TEMPLE'

The environment variable set when running any temple command. It is set to the name of the command

temple.constants.UPDATE_BRANCH_NAME = '_temple_update'

The temporary branches used for updates

temple.exceptions

Temple exceptions

exception temple.exceptions.CheckRunError[source]

When running temple update --check errors

exception temple.exceptions.Error[source]

The top-level error for temple

exception temple.exceptions.ExistingBranchError[source]

Thrown when a specifically named branch exists or doesn’t exist as expected.

exception temple.exceptions.InDirtyRepoError[source]

Thrown when running in a dirty git repo

exception temple.exceptions.InGitRepoError[source]

Thrown when running inside of a git repository

exception temple.exceptions.InvalidCurrentBranchError[source]

Thrown when a command cannot run because of the current git branch

exception temple.exceptions.InvalidEnvironmentError[source]

Thrown when required environment variables are not set

exception temple.exceptions.InvalidGithubUserError[source]

An invalid github user was passed to ls.

exception temple.exceptions.InvalidTemplatePathError[source]

Thrown when a template path is not a Github SSH path

exception temple.exceptions.InvalidTempleProjectError[source]

Thrown when the repository was not created with temple

exception temple.exceptions.NotInGitRepoError[source]

Thrown when not running inside of a git repo

exception temple.exceptions.NotUpToDateWithTemplateError[source]

Thrown when a temple project is not up to date with the template