Skip to main content

Python wrapper around the Nerdbank.GitVersioning CLI

Project description


post_title: nbgv-python Package Overview author1: Shuai Zhang post_slug: nbgv-python microsoft_alias: shuzhang featured_image: "https://devblogs.microsoft.com/azuremigrate/wp-content/uploads/sites/113/2023/01/microsoft-logo.png" categories:

  • Architecture tags:
  • nbgv
  • hatch
  • versioning ai_note: This document was prepared with AI assistance. summary: Guidance for using the nbgv-python package to integrate Nerdbank.GitVersioning with hatchling projects. post_date: 2025-11-08

Overview

  • nbgv-python wraps the Nerdbank.GitVersioning CLI so Python projects can reuse the same versioning semantics.
  • The package discovers the CLI via NBGV_PYTHON_COMMAND, a direct nbgv executable, or dotnet tool run nbgv as a fallback.
  • A Hatch version source plugin is provided, allowing projects to declare dynamic = ["version"] and resolve their version at build time.

Installation

  • Install the package into your monorepo environment using uv add --package nbgv-python nbgv-python.
  • Ensure the nbgv CLI is available either as a global .NET tool (dotnet tool install -g nbgv) or via a local tool manifest.
  • Optionally set NBGV_PYTHON_COMMAND when the executable lives outside of PATH or requires additional arguments.

Hatch Integration

Add the plugin to your project configuration:

[project]
dynamic = ["version"]

[tool.hatch.version]
source = "nbgv"

[tool.hatch.version.nbgv]
version-field = "simple_version"

During builds Hatch invokes nbgv get-version --format json in the project root and uses the selected field for the package version. Additional configuration keys include command (override CLI invocation) and working-directory (relative path for the repository root). The plugin normalizes the chosen value to a PEP 440 compliant version, so SemVer pre-release tags such as -beta.1 are mapped to b1 automatically.

Python API

Retrieve version metadata directly from Python code:

from nbgv_python import get_version

version = get_version()
print(version["simple_version"])  # -> 1.2.3

Forward arbitrary commands to the CLI:

from nbgv_python import forward

forward(["cloud", "--ci"])

All helpers raise NbgvNotFoundError when the CLI cannot be resolved and NbgvCommandError for non-zero exit codes.

Command-Line Usage

The console script nbgv-python proxies all arguments to the real CLI:

nbgv-python get-version --format json

The wrapper surfaces the same exit codes as the underlying tool and prints diagnostic guidance when the command cannot be located.

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

nbgv_python-1.0.0b1.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

nbgv_python-1.0.0b1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file nbgv_python-1.0.0b1.tar.gz.

File metadata

  • Download URL: nbgv_python-1.0.0b1.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for nbgv_python-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 d119a8d28c599364354ca3cc8d8a87bb7e7b5150cb66ea97545252f74d50f0fb
MD5 f5135530527312230565fcc48fab2363
BLAKE2b-256 8bcc2583d3c75fdad593e5f7f26d381983abd4494da4a8c2a51d6e6cded98acd

See more details on using hashes here.

File details

Details for the file nbgv_python-1.0.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for nbgv_python-1.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 34e2eae5ee903e22647c63e179989683e31a41f95a90599fd8c1ad8e887bc74a
MD5 93159a4ce089e223679f752169d51dcd
BLAKE2b-256 a588613716372a78d40488c1aaf8025d466879cd8236c87ddf6814560eb4583e

See more details on using hashes here.

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