A tool to scaffold a projects from templates
Project description
skaf
Overview
skaf is a Python tool designed to simplify project scaffolding. It provides a simple interface for defining project templates that can be rendered with minimal effort. Here's a quick guide to installing and making templates:
Installation
Ensure you have Python 3.10 or above. Install using pip:
pip install skaf
Alternatively, you can clone and install the local package:
git clone <repository-url>
cd skaf
pip install .
Creating your own templates
-
Create a template directory
In skaf, templates are directories of files that may or may not contain templating blocks. The default templater is jinja2, which is a full-featured templating engine with advanced features. (Note that skaf does not currently use jinja Loaders)Any files that have a
.jinjafile suffix will be rendered. Otherwise, the file will be left as-is.All files should be placed in a directory structure that looks like:
my-template-root/ ├── templates/ │ └── [any files you want] └── template_properties.yaml # this is metadataFor example, imagine I want to generate a customized hello world printer that is hard-coded to say hello to a specific person named John. I would create the following file:
# my-template-root/templates/hello.py.jinja print("Hello {{ some_name }}!")
-
Create a
template_properties.yaml
Next, we can declare metadata about the template. At this point, that primarily looks like declaring a list of variables that might have default values. There are a couple of other optional top-level fields as well:templater: jinja2 # default auto_use_defaults: false # default custom_variables: - name: "some_name" type: "str" # optional default: "World" # optional description: Who are we saying hello to? # optional
For custom variables, the
type,default, anddescriptionfields are optional. Onlynameis required.When rendering is run, you will be prompted to enter a value for the
some_namevariable or to accept the default valueWorld. If we had instead specified that top-level valueauto_use_defaults: true, then the templater would run without asking for input, and would provideWorldin as the value forsome_name. (This particular behavior can also be overridden when invoking the CLI command.)The two top-level fields
templaterandauto_use_defaultsare shown here with default values.
Command-line Usage
The CLI provides several flags and arguments to customize the initialization of a project with templates:
skaf <project_name> [options]
Positional Arguments:
<project_name>: The name of the project to create.
Options:
-t, --template <template_name>: Specify the name of the project template to use.-p, --path <template_directory>: Provide the path to a local template directory.-o, --output <output_directory>: Set the output directory for the project. Defaults to the current working directory.-f, --force: Force overwrite of existing files if they already exist.--auto-use-defaults: Override the template properties'auto_use_defaultswith an explicit value here.--debug: Enable debug mode, which will raise exceptions rather than catching them with a tidier output.
Example Commands
-
Creating a project with a template that is included in the package:
skaf my_project -t setuptools_pyproject
-
Using a local, user-defined template:
skaf my_project -p /path/to/my/template
-
Defining an Output Directory:
skaf my_project -o /path/to/output -p /path/to/my/template
Developing Templates
To create and use custom templates in skaf, follow these steps:
-
Directory Setup:
-
In skaf, templates are directories of files that contain templating blocks. Custom templates can be created in an location on your local machine and should have the following structure:
my-template-root/ ├── templates/ │ └── [any files you want] └── template_properties.yaml # this is metadata
-
-
template_properties.yaml:
- Define custom variables and the templating engine to use.
- Example properties:
custom_variables: - name: "author_name" type: "string" default: "John Doe" description: "The name of the project author." templater: "jinja2"
-
Render your template
- Run the following command:
skaf my-project --path path/to/my-template-root
- Run the following command:
Development Dependencies
To contribute or run tests, install development dependencies:
pip install .[dev]
Contribute
If you find a bug or have a feature request, please file an issue.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file skaf-0.1.0.tar.gz.
File metadata
- Download URL: skaf-0.1.0.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fbc28f8c7220294d7f916f522400c55af67e81eff83357fd1562d6f17bda10c
|
|
| MD5 |
fa5335d228fda1e366ebc05926cec899
|
|
| BLAKE2b-256 |
766eba3d725bb3c08c01d8ea880d49e9736f333055920745a71e83a529c761c3
|
Provenance
The following attestation bundles were made for skaf-0.1.0.tar.gz:
Publisher:
manual.publish-pypi.yml on jdraines/skaf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
skaf-0.1.0.tar.gz -
Subject digest:
9fbc28f8c7220294d7f916f522400c55af67e81eff83357fd1562d6f17bda10c - Sigstore transparency entry: 207909027
- Sigstore integration time:
-
Permalink:
jdraines/skaf@53d4786852e1ddd353dd19218c715bcc394ebbd1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/jdraines
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
manual.publish-pypi.yml@53d4786852e1ddd353dd19218c715bcc394ebbd1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file skaf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: skaf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1e78f3ea529bf5df2b332d257aec4bb1aabe25fdd1367857307a6c536451ab6
|
|
| MD5 |
1b6021ef251612ef863274d1ecc08c91
|
|
| BLAKE2b-256 |
c258453b6ff1ff13ab3aabe68edc1e410d5d5f8c66729d5fef07acfe3af72770
|
Provenance
The following attestation bundles were made for skaf-0.1.0-py3-none-any.whl:
Publisher:
manual.publish-pypi.yml on jdraines/skaf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
skaf-0.1.0-py3-none-any.whl -
Subject digest:
a1e78f3ea529bf5df2b332d257aec4bb1aabe25fdd1367857307a6c536451ab6 - Sigstore transparency entry: 207909028
- Sigstore integration time:
-
Permalink:
jdraines/skaf@53d4786852e1ddd353dd19218c715bcc394ebbd1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/jdraines
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
manual.publish-pypi.yml@53d4786852e1ddd353dd19218c715bcc394ebbd1 -
Trigger Event:
workflow_dispatch
-
Statement type: