Template reference¶
- class nusex.api.Template(name: str)¶
A class representing a template.
- Parameters
name (
str) – The name of the template.
- build(files: set[Path], project_name: str, *, project_slug: str | None = None, blueprint: type[blueprints.Blueprint] | str | None = None, profile: Profile | None = None, store_profile: bool = False, only_replace_profile_data: bool = False) None¶
Build this template.
- Parameters
files (
set[pathlib.Path]) – The files to include in the template. This should generally obtained usingfind_filesandprocess_excludes.project_name (
str) – The name of the project.
- Keyword Arguments
project_slug (
str|None) – The name to use as the project slug. If this isNone, a project slug is automatically created. In the vast majority of cases, it’s best to leave this alone.blueprint (
type[blueprints.Blueprint]) – The blueprint class to use when building this template. This must be eithertype[Blueprint] or a subclass thereof. If no blueprint is passed, nusex will build a static template.profile (
Profile) – A profile instance.store_profile (
bool) – Whether to store the given profile’s attributes within the template. This effectively provides a series of default profile attributes that can be used if a profile is not provided during deployment, or if the profile is missing some attributes. A profile must be passed to use this.only_replace_profile_data (
bool) – Whether to only replace variables explicitly set as attributes in the given profile. If this isTrue, profile attributes set toNonewill not be replaced with placeholder variables when building. This is only really useful when storing the profile in the template itself. A profile must be passed to use this.
- copy(*, name: str | None = None) Template¶
Create a new instance of this template with the same data.
- property dependencies: list[str]¶
The list of dependencies stored in this template. If there are none, this is an empty list.
- deploy(to_dir: Path | str, *, project_name: str | None = None, project_slug: str | None = None, profile: Profile | None = None, force: bool = False) None¶
Deploy this template.
- Parameters
to_dir (
pathlib.Path|str) – The directory to deploy this template into.- Keyword Arguments
project_name (
str|None) – The name of the project. If this isNone, the project name is set to the name of the directory the template is being deployed to.project_slug (
str|None) – The name to use as the project slug. If this isNone, a project slug is automatically created. In the vast majority of cases, it’s best to leave this alone.profile (
Profile|None) – The profile to use when deploying this template. Attributes in this profile will override any profile attributes stored within the template.force (
bool) – Whether to forcibly deploy this template, overwriting any existing files.
- property files: dict[str, bytes]¶
The files stored in this template. If there are none, this is an empty dict.
- find_files(in_dir: Path | str) set[Path]¶
Recursively search the given directory for files.
- Parameters
in_dir (
pathlib.Path|str) – The directory to search through.- Returns
The set of all files found.
- Return type
- classmethod from_disk(name: str, *, from_dir: Path | str) Template¶
Load a saved template.
- Parameters
name (
str) – The name of the template to load.- Keyword Arguments
from_dir (
pathlib.Path|str) – The directory to load the template from.- Returns
A template instance.
- Return type
- property path: Path | None¶
The filepath to this template. This is
Noneif the template has not been saved.- Returns
The filepath to this template, or
Noneif it has not been saved.- Return type
- process_excludes(files: set[Path], *, use_defaults: bool = False, sources: list[Path | str] | None = None, patterns: list[str] | None = None) set[Path]¶
Compile a series of files to exclude from all given sources and expressions.
- Parameters
files (
set[pathlib.Path]) – A list of files to compare against exclude patterns. This should generally be obtained throughfind_files.- Keyword Arguments
- Returns
The files to exclude from the template.
- Return type
- property profile_data: dict[str, str | None]¶
The profile data stored in this template. If there is none, this is an empty dict.
Warning
This returns the profile data, not a profile instance. To get a profile instance, use
Profile.from_template.
- save(*, to_dir: Path | str, overwrite: bool = False) Path¶
Save this template to disk.
- Keyword Arguments
to_dir (
pathlib.Path,str) – The directory to save the template to.overwrite (
bool) – Whether to overwrite an existing template. If this isFalse, anFileExistsErrorerror will be raised if a template with the same name already exists. Defaults toFalse.
- Returns
A
pathlib.Pathobject with the full path to the template.- Return type