A simple cli tool to generate python project based on a template
Project description
ForgeIt
Scaffolding library written in Python. Jinja2 is used for template rendering and Typer for CLI.
CLI Documentation
It provides the following commands:
init
Render a template's files given a name. If no variables file is given, the user will be prompted to enter them manually.
- Usage:
fg init <name> [<file>]
new
Renders a template's fragment (subtemplate) using stored context .forge.json file. If no variables file is given, the user will be prompted to enter the manually.
- Usage:
fg new <name> [<file>]
install
Installs a template description from a file path. It must be a ZIP File.
The provided ZIP file must have the following structure:
[zip file]
templates/
# Files with jinja syntax
static/
# Files that will be cloned
template.json # Template schema/definition
- Usage:
fg install <path>
list
Lists all the available templates.
- Usage:
fg list
version
Displays the current version of the tool.
- Usage:
fg version
validate
Validate a template description. It must be a JSON file.
- Usage:
fg validate <file>
example
Create an example template. It will create a ZIP file containing a basic layout of a valid template in the current working directory. You could install it to use it if you want.
- Usage
fg example
Template Schema
It consists of the following properties:
name: The name of the template.label: The label of the template.description: The description of the template.variables: An object containing variable definitions.content: An object containing the template content.subtemplates: An object containing subtemplate definitions.
Template Types
The following types are supported:
template: Renders a template file using the provided variables. Paths will always be relative totemplatesfolder in the user profile.file: Copies a file from the provided path. Paths will always be relative tostaticfolder in the user profile.content: Renders a string template using the provided variables.
Template Context
When a template gets rendered, a .forgeit.json file is created in the current working directory so the new command nows which template use as parent and all the variables used to avoid introducing them again on every render.
Example Template File
Here is an example template file that uses the schema defined in forgeit/schemas.py
{
"name": "my_template",
"label": "My Template",
"description": "This is a sample template.",
"variables": {
"name": {
"type": "string",
"label": "Name"
},
"age": {
"type": "integer",
"label": "Age"
}
},
"content": {
"index.html": "template:index.html.j2",
"style.css": "file:style.css",
"script.js": "content:<script>alert('Hello, {{ name }}!');</script>"
},
"subtemplates": {
"child_template": {
"label": "Child Template",
"description": "This is a child template.",
"variables": {
"child_name": {
"type": "string",
"label": "Child Name"
}
},
"content": {
"child.html": "template:child.html.j2"
}
}
}
}
This template defines two variables, name and age, and uses them to render three files: index.html using a template file, style.css by copying a file, and script.js using a string template. It also defines a subtemplate, child_template, which has its own variables and content.
Note: This is just a sample template file, and you can customize it to fit your needs.
Template storage
All templates are stored locally in the user directory under .forgeit folder. For instance, in Windows you might encounter all the templates under C:\Users\<USER NAME>\AppData\Roaming\forgeit, in Mac OS under ~/Library/Application Support/.forgeit or ~/.config/.forgeit in Linux.
All templates are centralized, so this directory is the only source of truth regarding template files and its metadata. In your first install, a forgeit.db file will be created to store in a convenient way all the required information to render the template.
Why JSON?
JSON is a lightweight yet powerful format to define metadata. The starting approach was to use Python files to setup the templates. This was discarted due to security reasons. Since JSON are directly translated into dictionaries and its structure is a reflection from the original source it was a straight forward choice. YAML was discarted because it might required an extra step to understand its mappint to a dict or another structure in Python.
Project details
Release history Release notifications | RSS feed
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 forgeit-0.1.0b1.tar.gz.
File metadata
- Download URL: forgeit-0.1.0b1.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3d9c16d35051a65e8599ff8403614712894573719f5e2111b22fd8e1f6c83a4
|
|
| MD5 |
7c91b83aed327becd89449d3ec15a79c
|
|
| BLAKE2b-256 |
1404dfac4706e30f22a4164c3c87dc4c9d6e047c26b1b0a3bcc141283b301004
|
Provenance
The following attestation bundles were made for forgeit-0.1.0b1.tar.gz:
Publisher:
pypi.yaml on KennethUlloa/forgeit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
forgeit-0.1.0b1.tar.gz -
Subject digest:
e3d9c16d35051a65e8599ff8403614712894573719f5e2111b22fd8e1f6c83a4 - Sigstore transparency entry: 199087125
- Sigstore integration time:
-
Permalink:
KennethUlloa/forgeit@f96501f306e0e5a417c8fc467e6a45c5e8f214dc -
Branch / Tag:
refs/tags/0.1.0.beta1 - Owner: https://github.com/KennethUlloa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@f96501f306e0e5a417c8fc467e6a45c5e8f214dc -
Trigger Event:
push
-
Statement type:
File details
Details for the file forgeit-0.1.0b1-py3-none-any.whl.
File metadata
- Download URL: forgeit-0.1.0b1-py3-none-any.whl
- Upload date:
- Size: 14.1 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 |
97163af6ba7e6128691896e5e092c4b05fa60fcb5bcedb6f7cb0bd7f907dfaf1
|
|
| MD5 |
e9459a9bd53ef3f90aa7366f51fc74bb
|
|
| BLAKE2b-256 |
d2f532c3d90cc209e9eb85b32346d758a1eba5ae61f67a8f970cf0822b15e1ea
|
Provenance
The following attestation bundles were made for forgeit-0.1.0b1-py3-none-any.whl:
Publisher:
pypi.yaml on KennethUlloa/forgeit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
forgeit-0.1.0b1-py3-none-any.whl -
Subject digest:
97163af6ba7e6128691896e5e092c4b05fa60fcb5bcedb6f7cb0bd7f907dfaf1 - Sigstore transparency entry: 199087127
- Sigstore integration time:
-
Permalink:
KennethUlloa/forgeit@f96501f306e0e5a417c8fc467e6a45c5e8f214dc -
Branch / Tag:
refs/tags/0.1.0.beta1 - Owner: https://github.com/KennethUlloa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@f96501f306e0e5a417c8fc467e6a45c5e8f214dc -
Trigger Event:
push
-
Statement type: