Writing Templates

Syntax

The used template format is based on Python’s str.format() method. Thus a list of predefined variables can be embedded into a text using {myVariable} syntax. As curley braces are used to denote variables, double curley braces will translate to curley braces in the output text, e.g. needed in C-like languages: {{{ or }}}.

myTemplate.c.template
typedef struct {{
  .field = "{myVariable}"
}} myExample;

Member Access

A variable’s member (property or field) can be accessed using the dot-notation.

myTemplate.c.template
typedef struct {{
  .field = "{myVariable.myProperty}"
}} myExample;

Method Access

A variable’s method can be accessed using the dot-notation.

myTemplate.c.template
typedef struct {{
  .field = "{myVariable.myMethod()}"
}} myExample;

A typical usecase might be concatenating list elements to a comma separated string

myTemplate.c.template
typedef struct {{
  .field = "{', '.join(myVariable)}"
}} myExample;

FunctionCall

A function can be called inside {.....}

myTemplate.c.template
typedef struct {{
  .field = "{len(myArray)}"
}} myExample;

Formatting

The Pyton string formating syntax allows for further customizations like left, middle or right justification as well as number formating e.g. as hex-values.

Examples

{myVariable:\0<16}

Left justified 16-character string padded with \0.

0x{myVariable:02X}

Zero-padded 2-character hexadecimal number, with 0x prefix and uppercase (X) hex-letters.

{myVariable!s}/{myVariable!r}

Call str() or repr() on a variable.

Predefined Variables

pyVersioning offers lots of predefined variables. A full list of variables and there actual values can be printed using the pyVersioning variables command in the command line interface.

The following root-level variables are defined:

version

Version information.

git

Information collected from version control system Git like branch name, tag name, commit date, commit hash, …

project

Project information mainly provided by the .pyVersioning.yaml configuration file.

build

Build information mainly provided by the .pyVersioning.yaml configuration file.

tool

Tool information about pyVersioning.

platform

Platform information.

Variables
$> pyVersioning.exe variables
version                 : v0.0.0
tool                    : pyVersioning 0.17.0
  name                  : pyVersioning
  version               : 0.17.0
project                 :  -  v0.0.0
  name                  :
  variant               :
  version               : v0.0.0
build                   : <pyVersioning.Build object at 0x000001F3FF7F46C0>
  date                  : 2025-04-21
  time                  : 10:43:02.882194
  compiler              : <pyVersioning.Compiler object at 0x000001F3819B63E0>
    name                :
    version             : v0.0.0
    configuration       :
    options             :
git                     : <pyVersioning.Git object at 0x000001F3819F5260>
  commit                : <pyVersioning.Commit object at 0x000001F3819DA920>
    hash                : 4f5b03b202887cab53ad27d80b0ed5bde028d705
    date                : 2025-04-21
    time                : 07:50:48
    author              : Patrick Lehmann <Paebbels@gmail.com>
      name              : Patrick Lehmann
      email             : Paebbels@gmail.com
    committer           : Patrick Lehmann <Paebbels@gmail.com>
      name              : Patrick Lehmann
      email             : Paebbels@gmail.com
    comment             : Fixed binary output check.

    oneline             : Fixed binary output check.
  reference             : dev
  tag                   :
  branch                : dev
  repository            : git@github.com:Paebbels/pyVersioning.git
platform                : <pyVersioning.Platform object at 0x000001F3FF441510>
  ci_service            : NO-CI
env                     : Environment(..........................)

Configuration File Variables

pyVersioning reads a .pyVersioning.yaml file for static (per project) settings. These are also exposed as variables.

Environment Variables

Todo

List environment variables.

Git Variables

Local Workstation

Todo

List Git variables.

AppVayor

Todo

List AppVayor variables.

GitHub

Todo

List GitHub variables.

GitLab

Todo

List GitLab variables.

Travis-CI

Todo

List Travis-CI variables.