Skip to content

template_name

CLASS DESCRIPTION
TemplateName

Handling the "name" of "a" "template".

TemplateName(repo_name: str, template_name: str)

Handling the "name" of "a" "template".

There are a number of conventions the tooling follows based on the "name" of a template. Most of the time a single repo == a single template and the "name" of the template is just the name of the repo. Easy.

Some times, notably navapbc/template-infra, there are multiple "templates" (a distinct collection of templated files that are handled together) in the same repo, though the repo itself is also referred to as a "template" in conversation. These multiple templates are not necessarily hierarchical, though generally related/interdependent. So both when outputting info to a user and for internal operations at different times we need refer to just the repo name (e.g., for state directory location), just the template name (e.g., for state file location, context variables), and both (e.g., to uniquely identify the template in some user messaging).

This class papers over those differences.

METHOD DESCRIPTION
is_singular_instance

Check if this app_name implies the template only exists once for project.

is_singular_instance(app_name: str) -> bool

Check if this app_name implies the template only exists once for project.

Effectively, when the app name is the same name as the template itself (barring some special cases), assume the template is something which only has one instance in a given project.

Source code in nava/platform/templates/template_name.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def is_singular_instance(self, app_name: str) -> bool:
    """Check if this app_name implies the template only exists once for project.

    Effectively, when the app name is the same name as the template itself
    (barring some special cases), assume the template is something which
    only has one instance in a given project.
    """
    # special case templates with the name "app", which by convention
    # shouldn't be unique and if someone wants to install an instance of the
    # template as "app" instead of "example-app"/a name that corresponds to
    # its purpose, well...let them
    if self.template_name == "app":
        return False

    return app_name == self.template_name