types
Datatypes for templates.
Templates are a representation of source templates used to generate projects.
Classes¶
Template
dataclass
¶
Template(
repo: TemplateRepo,
directory: str = "",
_context: Optional[OrderedDict] = None,
)
TemplateFormat
¶
TemplateRepo
dataclass
¶
TemplateRepo(
source: str,
cached_source: Path,
format: TemplateFormat,
locality: Locality,
checkout: Optional[str] = None,
password: Optional[str] = None,
)
A template repository is a source of one or more templates.
Attributes¶
checkout
class-attribute
instance-attribute
¶
checkout: Optional[str] = None
The branch, tag or commit for the template to track.
current_sha
property
¶
current_sha: Optional[str]
If the template is a git repository, return the current commit hash.
latest_sha
property
¶
latest_sha: Optional[str]
password
class-attribute
instance-attribute
¶
password: Optional[str] = None
The password to use if template is a password-protected Zip archive.
Functions¶
render_source
¶
render_source(
output_dir: Optional[Path] = None,
commit: Optional[str] = None,
) -> Iterator[Path]
A context manager that provides the source from which to render the template.
For git repositories, this will create a temporary working tree of the repository and yield the path to the working tree.
For Zip archives, this will extract the archive to a temporary directory and yield the path
For plain repos, it will yield the path to the directory.
Parameters:
output_dir
-
The directory to extract the template to. If not provided, a temporary directory will be used.
DEFAULT:
None
commit
-
The commit to checkout if the template is a git repository.
DEFAULT:
None
YIELDS | DESCRIPTION |
---|---|
Path
|
The path to the rendered template |
Functions¶
get_template_name
¶
get_template_name(
path_or_url: str,
directory: Optional[str] = None,
checkout: Optional[str] = None,
) -> str
Get the name of the template using the path or URL.
Parameters:
path_or_url
-
The URL or path to the template
TYPE:
str
directory
-
Directory within a git repository template that holds the cookiecutter.json file.
DEFAULT:
None
checkout
-
The branch, tag or commit to use if template is a git repository.
DEFAULT:
None
Raises:
-
ValueError
-
If the path_or_url is not parsable
Returns:
-
str
-
The name of the template without extensions