Template reference

class nusex.Template(name, *, installs=[], as_addon_for='')

A class in which to create, load, modify, and save templates.

Parameters

name (str) – The name of the template. If the template does not exist, a new one is created, otherwise an existing one is loaded.

Keyword Arguments
  • installs (list[str]) – A list of dependancies to be installed when the template is deployed. Defaults to an empty list.

  • as_addon_for (str) – The name of the template this template is an add-on for. Defaults to an empty string.

path

The complete filepath to the template.

Type

pathlib.Path

data

The data for the template.

Type

dict[str, Any]

Changed in version 1.2: Added as_addon_for keyword argument.

build(*, project_name=None, files=[], root_dir='.', blueprint=None, **kwargs)

Build this template. View the template guide to see what this command does in more detail.

Keyword Arguments
  • project_name (str) – The name to use as the project name when building the project. If this is None, the name of the parent directory is used. Defaults to None.

  • files (list[str]) – The list of files to include in this template. If no files are specified, the file listing is automatically retrieved.

  • root_dir (str) – The root directory that nusex will search from. Defaults to the current directory.

  • blueprint (Blueprint) – The language blueprint to use. If this is None, the Python blueprint is selected. Defaults to None.

  • **kwargs (Any) – Arguments for the get_file_listing method.

Changed in version 1.1: Added blueprint keyword argument.

check()

Check the template manifest, including line changes.

Returns

The template manifest. The keys are always file names, and the values are tuples of the line numbers and line values that have been changed. This may not always be present.

Return type

dict[str, list[tuple[int, str]]]

create_new(name)

Create a new template. This should never need to be called as templates are created automatically when necessary upon object instantiation.

Parameters

name (str) – The name of the template.

Raises
delete()

Delete this template.

Raises

FileNotFoundError – The template does not exist on disk.

deploy(*, project_name=None, destination='.')

Deploy this template.

Keyword Arguments
  • project_name (str) – The name to use as the project name when deploying the project. If this is None, the name of the parent directory is used. Defaults to None.

  • destination (str) – The path to deploy this template to. Defaults to the current directory.

Changed in version 1.1: Added project_name keyword argument.

property exists

Whether the template exists on disk.

Returns

bool

classmethod from_cwd(name, *, project_name=None, blueprint=None, installs=[], as_addon_for='', ignore_exts={}, ignore_dirs={})

Create a template using files from the current working directory.

Parameters

name (str) – The name of the template.

Keyword Arguments
  • project_name (str) – The name to use as the project name when building the project. If this is None, the name of the parent directory is used. Defaults to None.

  • blueprint (Blueprint) – The language blueprint to use. If this is None, the Python blueprint is selected. Defaults to None.

  • installs (list[str]) – A list of dependencies to install when this template is deployed. Defaults to an empty list.

  • as_addon_for (str) – The name of the template this template is an add-on for. Defaults to an empty string.

  • ignore_exts (set[str]) – A set of file extensions to ignore. Defaults to an empty set.

  • ignore_dirs (set[str]) – A set of directories to ignore. Defaults to an empty set.

Returns

The newly created template.

Return type

Template

Changed in version 1.1: Added project_name and blueprint keyword arguments.

Changed in version 1.2: Added as_addon_for keyword argument.

classmethod from_dir(name, path, *, project_name=None, blueprint=None, installs=[], as_addon_for='', ignore_exts={}, ignore_dirs={})

Create a template using files from a specific directory.

Parameters
  • name (str) – The name of the template.

  • path (str | os.PathLike) – The path to the files to build the template with.

Keyword Arguments
  • project_name (str) – The name to use as the project name when building the project. If this is None, the name of the parent directory is used. Defaults to None.

  • blueprint (Blueprint) – The language blueprint to use. If this is None, the Python blueprint is selected. Defaults to None.

  • installs (list[str]) – A list of dependencies to install when this template is deployed. Defaults to an empty list.

  • as_addon_for (str) – The name of the template this template is an add-on for. Defaults to an empty string.

  • ignore_exts (set[str]) – A set of file extensions to ignore. Defaults to an empty set.

  • ignore_dirs (set[str]) – A set of directories to ignore. Defaults to an empty set.

Returns

The newly created template.

Return type

Template

Changed in version 1.1: Added project_name and blueprint keyword arguments.

Changed in version 1.2: Added as_addon_for keyword argument.

classmethod from_repo(name, url, *, project_name=None, blueprint=None, installs=[], as_addon_for='', ignore_exts={}, ignore_dirs={})

Create a template using files from a GitHub repository.

Parameters
  • name (str) – The name of the template.

  • url (str) – The URL of the GitHub repository to clone.

Keyword Arguments
  • project_name (str) – The name to use as the project name when building the project. If this is None, the name of the parent directory is used. Defaults to None.

  • blueprint (Blueprint) – The language blueprint to use. If this is None, the Python blueprint is selected. Defaults to None.

  • installs (list[str]) – A list of dependencies to install when this template is deployed. Defaults to an empty list.

  • as_addon_for (str) – The name of the template this template is an add-on for. Defaults to an empty string.

  • ignore_exts (set[str]) – A set of file extensions to ignore. Defaults to an empty set.

  • ignore_dirs (set[str]) – A set of directories to ignore. Defaults to an empty set.

Returns

The newly created template.

Return type

Template

Raises

BuildError – Cloning the repository failed.

Changed in version 1.1: Added project_name and blueprint keyword arguments.

Changed in version 1.2: Added as_addon_for keyword argument.

get_file_listing(root_dir, *, ignore_exts={}, ignore_dirs={})

Get a list of files to include in this template.

Parameters

root_dir (str) – The root directory that nusex will search from.

Keyword Arguments
  • ignore_exts (set[str]) – A set of file extensions to ignore. Defaults to an empty set.

  • ignore_dirs (set[str]) – A set of directories to ignore. Defaults to an empty set.

Returns

A list of filepaths.

Return type

list[pathlib.Path]

install_dependencies()

Install this template’s dependencies. Note that this does not work on PyPy Python implementations.

load()

Load an existing template. This should never need to be called as templates are loaded automatically when necessary upon object instantiation.

Raises

FileNotFoundError – The template does not exist on disk.

property name

The name of the template.

Returns

str

rename(new_name)

Rename this template.

Parameters

new_name (str) – The new name for the template.

Raises
  • TemplateError – The new name for the template is invalid.

  • AlreadyExists – The new name for the template is already being used by a profile.

  • FileNotFoundError – The template does not exist on disk.

save()

Save this profile.

Raises

TemplateError – The profile data has been improperly modified.