versioning
gitversioned.versioning ¶
GitVersioned core module for resolving versions from Git state.
This module provides the primary logic for computing PEP 440 compliant version strings. It evaluates multiple configured sources (such as tags, branches, files, and functions) and applies appropriate templates based on the current build environment and repository state.
generate_version_py(version, reference, settings, repository, environment) ¶
Writes the resolved version metadata to a python file using templates.
This function utilizes the configured release or development templates to generate a python file containing version information, which can then be included directly within the target package.
Example: >>> path = generate_version_py(version, ref, settings, repo, env)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version | Version | The resolved PEP 440 version object. | required |
reference | GitReference | The resolved Git reference object. | required |
settings | Settings | Configuration rules for resolving the version. | required |
repository | GitRepository | The current git repository state. | required |
environment | BuildEnvironment | Build environment metadata. | required |
Returns:
| Type | Description |
|---|---|
Path | None | The Path object pointing to the written file. |
Source code in src/gitversioned/versioning.py
resolve_and_generate_version(settings, repository, environment) ¶
Main entry point to resolve the version and write the output file if configured.
This function wraps the core version resolution logic and subsequently triggers the generation of the version python file if an output file is specified in the settings. It provides a convenient single call for build hooks and integrations.
Example: >>> version, path = resolve_and_generate_version(settings, repo, env)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings | Settings | Configuration rules for resolving the version. | required |
repository | GitRepository | The current git repository state. | required |
environment | BuildEnvironment | Build environment metadata. | required |
Returns:
| Type | Description |
|---|---|
tuple[Version, Path | None] | A tuple of the resolved Version and output Path (if generated). |
Source code in src/gitversioned/versioning.py
resolve_version(settings, repository, environment) ¶
Computes the PEP 440 version based on configuration and repository state.
This function coordinates the resolution of version sources according to the provided settings, performs auto-increments if necessary, and formats the final version string based on the target build type (e.g., release, dev, alpha).
Example: >>> version, reference = resolve_version(settings, repo, env)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings | Settings | Configuration rules for resolving the version. | required |
repository | GitRepository | The current git repository state. | required |
environment | BuildEnvironment | Build environment metadata. | required |
Returns:
| Type | Description |
|---|---|
tuple[Version, GitReference] | A tuple containing the resolved Version and the Git reference object. |
Raises:
| Type | Description |
|---|---|
ValueError | If an unknown source type or git type is encountered. |
Source code in src/gitversioned/versioning.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |