{"library":"dunamai","code":"import os\nfrom dunamai import Version\n\n# In a Git repository with tag v0.1.0 and some commits after it\ntry:\n    version = Version.from_any_vcs(\n        # Optional: Specify a fallback version if no VCS is found or no tags match.\n        # Defaults to '0.0.0' if not strict, or raises an error if strict.\n        fallback=os.environ.get(\"DUNAMAI_FALLBACK_VERSION\", \"0.0.0\"),\n        # Optional: Set strict=True to raise an error if a version cannot be determined.\n        # Default is False, which may use fallback.\n        strict=bool(os.environ.get(\"DUNAMAI_STRICT\", \"\").lower() == \"true\"),\n    )\n    # Prints a PEP 440 compliant version like \"0.1.0.post7.dev0+g29045e8\"\n    print(f\"Current version: {version.serialize()}\")\n    # Or a Semantic Versioning compliant string like \"0.1.0-post.7\"\n    print(f\"Semantic version: {version.serialize(style='semver', metadata=False)}\")\nexcept RuntimeError as e:\n    print(f\"Could not determine version: {e}\")\n    # Handle cases where version cannot be determined (e.g., not in a VCS repo)\n","lang":"python","description":"This example demonstrates how to retrieve and serialize a dynamic version string from any detected VCS. It includes options for fallback versions and strict mode, which are crucial for robust integration in varied environments like CI/CD pipelines. The output can be formatted according to different versioning styles.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}