pytemplator package¶
Submodules¶
pytemplator.cli module¶
Console script for pytemplator.
pytemplator.constants module¶
Various constants used throughout the project.
pytemplator.pytemplator module¶
Main module.
- class pytemplator.pytemplator.Templator(base_dir: Optional[str] = None, template_location: Optional[str] = None, checkout_branch: str = 'main', destination_dir: Optional[str] = None, no_input: bool = False)[source]¶
Bases:
objectMain class creating a project from a template.
- add_pytemplator_yaml()[source]¶
Add a .pytemplator.yml config file.
This allows for future automated boilerplate update to follow the latest version of the template.
- property last_commit_hash¶
Return the hash of the latest commit.
This is recorded in the .pytemplator.yml file to allow for further re-templating in the future.
This is kept separate from the prepare_template_dir as unlike the checkout logic, storing the commit for a git repo on the filesystem is something useful which doesn’t lead to unexpected side-effects.
pytemplator.utils module¶
Utility functions for the Templator.
- class pytemplator.utils.Context(questions=None)[source]¶
Bases:
objectUtility class handling the context passed to the Jinja2 engine.
- class pytemplator.utils.Question(key, ask=None, default=None, no_input_default=None, validators=None)[source]¶
Bases:
objectClass handling the user input and validation for a context key.
- pytemplator.utils.cd(new_dir)[source]¶
Cd into the directory.
Used as context manager to avoid side-effects if something goes wrong. See SO #24176022
- pytemplator.utils.check_if_new_dirs_can_be_created(directories, context, destination_dir, no_input: bool)[source]¶
Check if any of the templated directories already exist.
If so, offer the user to overwrite them.
- pytemplator.utils.generate_context_from_json(json_file, context, no_input)[source]¶
Generate the context from a json file.
Same behavior as cookiecutter.
- pytemplator.utils.import_module_from_path(path)[source]¶
Import and execute a module in a safer way.
Recipe taken from importlib doc at https://docs.python.org/3/library/importlib.html
Module contents¶
Top-level package for pytemplator.