gitversioned.versioning.generation¶
Format and generate output version strings.
Provides utilities to format versions under standards like PEP 440 and SemVer 2, render version templates using Git repository metadata, and execute strategies to inject version strings into files or output streams.
FormattedVersion
¶
Bases: Version
Version subclass providing custom string formatting.
Wraps a packaging Version to custom-format string output for PEP 440 and SemVer 2 standards based on the resolved version type.
Example
from packaging.version import Version ver = FormattedVersion(Version("1.0.0.post1"), "post", "semver2") str(ver) '1.0.0-post1'
Source code in src/gitversioned/versioning/generation.py
__init__(version, version_type, version_standard='pep440')
¶
Initialize the formatted version wrapper.
:param version: The base packaging Version object. :param version_type: The type of version being represented. :param version_standard: The target version standard ("pep440" or "semver2").
Source code in src/gitversioned/versioning/generation.py
__repr__()
¶
Return the developer-friendly string representation of the formatted version.
:return: The string representation.
__str__()
¶
Return the version formatted according to the standard.
:return: The formatted version string. :raises ValueError: If the version standard is unsupported.
Source code in src/gitversioned/versioning/generation.py
generate_from_template(pattern, version, reference, settings, repository, environment)
¶
Render a template pattern using version and git repository metadata.
Example
from gitversioned.settings import Settings from gitversioned.utils import BuildEnvironment, GitReference, GitRepository from packaging.version import Version generate_from_template( ... "v{version}-{ref.short_sha}", ... Version("1.0.0"), ... GitReference(short_sha="abc1234"), ... Settings(), ... GitRepository(), ... BuildEnvironment() ... ) 'v1.0.0-abc1234'
:param pattern: The template string pattern to render. :param version: The target Version object. :param reference: The active Git reference metadata. :param settings: Active application configuration. :param repository: The Git repository context helper. :param environment: The environment build variables context. :return: The rendered string, or an empty string if pattern is empty.
Source code in src/gitversioned/versioning/generation.py
generate_output_from_strategies(version, version_type, reference, settings, repository, environment)
¶
Resolve the configuration output strategy to generate formatted version content.
Example
from packaging.version import Version from gitversioned.settings import Settings, TemplateStrStrategy from gitversioned.utils import BuildEnvironment, GitReference, GitRepository settings = Settings( ... output_strategies=TemplateStrStrategy( ... content="version = '{version}'" ... ) ... ) generate_output_from_strategies( ... Version("1.0.0"), ... "release", ... GitReference(), ... settings, ... GitRepository(), ... BuildEnvironment(), ... ) "version = '1.0.0'"
:param version: The target Version object. :param version_type: The category of version being built. :param reference: The current Git reference metadata. :param settings: Active application configuration. :param repository: The Git repository context helper. :param environment: The environment build variables context. :return: The generated version string content. :raises ValueError: If the active strategy is unsupported or cannot be resolved.
Source code in src/gitversioned/versioning/generation.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |