Skip to main content

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 to templates folder in the user profile.
  • file: Copies a file from the provided path. Paths will always be relative to static folder 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forgeit-0.1.0b1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

forgeit-0.1.0b1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

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

Hashes for forgeit-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 e3d9c16d35051a65e8599ff8403614712894573719f5e2111b22fd8e1f6c83a4
MD5 7c91b83aed327becd89449d3ec15a79c
BLAKE2b-256 1404dfac4706e30f22a4164c3c87dc4c9d6e047c26b1b0a3bcc141283b301004

See more details on using hashes here.

Provenance

The following attestation bundles were made for forgeit-0.1.0b1.tar.gz:

Publisher: pypi.yaml on KennethUlloa/forgeit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for forgeit-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 97163af6ba7e6128691896e5e092c4b05fa60fcb5bcedb6f7cb0bd7f907dfaf1
MD5 e9459a9bd53ef3f90aa7366f51fc74bb
BLAKE2b-256 d2f532c3d90cc209e9eb85b32346d758a1eba5ae61f67a8f970cf0822b15e1ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for forgeit-0.1.0b1-py3-none-any.whl:

Publisher: pypi.yaml on KennethUlloa/forgeit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page