### Install and Build with uv Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/examples/metadata-hook/README.md Installs the uv package and then builds the project using uv commands. Ensure uv is installed before running. ```bash pip install uv uv build ``` -------------------------------- ### Build project with dynamic versioning Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Example workflow showing how git tags influence the build version. ```bash $ git tag v1.0.0 $ uv build Building source distribution... Building wheel from source distribution... Successfully built dist/foo-1.0.0.tar.gz Successfully built dist/foo-1.0.0-py3-none-any.whl # check METADATA file (ref. https://packaging.python.org/en/latest/specifications/core-metadata/) $ tar -xf dist/foo-1.0.0-py3-none-any.whl $ head foo-1.0.0.dist-info/METADATA Metadata-Version: 2.4 Name: foo Version: 1.0.0 ``` -------------------------------- ### Example format-jinja-imports Configuration Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Demonstrates how to configure additional imports for the format-jinja template. This makes specified modules or items available within the Jinja formatting context. ```toml format-jinja-imports = [ { module = "foo" }, { module = "bar", item = "baz" }, ] ``` -------------------------------- ### Configure Version Pattern Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Examples of setting the version pattern using a regular expression or a named preset in the TOML configuration. ```toml # Regular expression: pattern = '(?P\d+\.\d+\.\d+)' # Named preset: pattern = "default-unprefixed" ``` -------------------------------- ### Configure Jinja Version Format Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Examples of using Jinja templates to define custom version output formats. ```toml format-jinja = "{% if distance == 0 %}{{ base }}{% else %}{{ base }}+{{ distance }}.{{ commit }}{% endif %}" ``` ```toml format-jinja = """ {%- if distance == 0 -%} {{ serialize_pep440(base, stage, revision) }} {%- elif revision is not none -%} {{ serialize_pep440(base, stage, revision + 1, dev=distance, metadata=[commit]) }} {%- else -%} {{ serialize_pep440(bump_version(base), stage, revision, dev=distance, metadata=[commit]) }} {%- endif -%} """ ``` -------------------------------- ### PEP 440 Versioning Example Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Shows the resulting PEP 440 version string when bumping is disabled, including post-release and development build information derived from commit history. ```text 1.3.1.post3.dev0+28c1684 ``` -------------------------------- ### Project Dependencies After Dynamic Versioning Setup Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/metadata_hook.md After setting up the dynamic versioning hook, remove direct 'dependencies' from the [project] section and declare 'dependencies' as dynamic. ```toml [project] name = "..." dynamic = ["dependencies"] ``` -------------------------------- ### Check Dunamai Default Pattern Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Run this command to verify the default regex pattern used by the installed version of Dunamai. ```bash uv run python -c "import dunamai; print(dunamai.Pattern.Default.regex())" ``` -------------------------------- ### Set __version__ using importlib.metadata Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Use this method to dynamically set the `__version__` attribute from installed package metadata. It may be slow and can fail if the package is installed in development mode. ```python # __init__.py import importlib.metadata __version__ = importlib.metadata.version(__name__) ``` ```python import importlib.metadata try: __version__ = importlib.metadata.version(__name__) except importlib.metadata.PackageNotFoundError: __version__ = "0.0.0" ``` -------------------------------- ### Default Build with Pre-configured Version Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Demonstrates the default build process when no specific versioning pattern is configured, using a standard Git tag like 'v1.0.0'. ```bash $ git tag v1.0.0 $ uv build Building source distribution... Building wheel from source distribution... Successfully built dist/foo-1.0.0.tar.gz Successfully built dist/foo-1.0.0-py3-none-any.whl ``` -------------------------------- ### Build with Unprefixed Version Tag Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Illustrates the build process after configuring a custom pattern that accepts unprefixed version tags, such as '1.0.0'. ```bash $ git tag 1.0.0 $ uv build Building source distribution... Building wheel from source distribution... Successfully built dist/foo-1.0.0.tar.gz Successfully built dist/foo-1.0.0-py3-none-any.whl ``` -------------------------------- ### Configure build-system for uv-dynamic-versioning Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/README.md Update the project's build-system configuration to include the plugin as a requirement. ```toml [build-system] requires = ["hatchling", "uv-dynamic-versioning"] build-backend = "hatchling.build" ``` -------------------------------- ### Update project version configuration Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Transition from a static version to dynamic versioning in the project table. ```toml [project] name = "..." version = "0.1.0" ``` ```toml [project] name = "..." dynamic = ["version"] ``` -------------------------------- ### PEP 440 Versioning with Bumping Enabled Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Illustrates the PEP 440 version string when bumping is enabled, showing an incremented patch version and development build information. ```text 1.3.2.dev3+28c1684 ``` -------------------------------- ### Check version with uv-dynamic-versioning Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Use the command line tool to verify the current version string. ```bash $ uvx uv-dynamic-versioning 1.0.0 ``` -------------------------------- ### Configure uv cache keys for dynamic metadata Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/tips.md Update the uv cache configuration to account for dynamic project metadata. ```toml [tool.uv] cache-keys = [{ file = "pyproject.toml" }, { git = { commit = true, tags = true }}] ``` -------------------------------- ### Python Equivalent of format-jinja-imports Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Illustrates the Python code that the TOML configuration for format-jinja-imports roughly translates to, showing how modules and specific items are imported. ```python import foo from bar import baz ``` -------------------------------- ### Configure uv-dynamic-versioning Hook Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/metadata_hook.md Add this configuration to your pyproject.toml to enable the metadata hook. Ensure 'dependencies' is listed in project.dynamic. ```toml [tool.hatch.metadata.hooks.uv-dynamic-versioning] dependencies = ["foo=={{ version }}"] ``` -------------------------------- ### Custom Pattern Configuration for Versioning Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Shows how to configure a custom pattern for version extraction, specifically 'default-unprefixed', which allows versions without a 'v' prefix. ```toml [tool.uv-dynamic-versioning] pattern = "default-unprefixed" ``` -------------------------------- ### Project Dependencies Before Dynamic Versioning Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/metadata_hook.md Before using the dynamic versioning hook, dependencies are typically listed directly in the [project] section. ```toml [project] name = "..." dependencies = [] ``` -------------------------------- ### Configure Dependabot for uv Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/tips.md Add this configuration to your dependabot.yml to support the uv package ecosystem. ```yml version: 2 updates: - package-ecosystem: uv ``` -------------------------------- ### Add Version File to .gitignore Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Add the dynamically generated version file to your `.gitignore` to prevent it from being committed to version control. ```text path/to/_version.py ``` -------------------------------- ### Patch fallback version for sandboxed builds Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/tips.md Commands to resolve the current version and patch pyproject.toml before entering a sandboxed environment. ```bash # Outside of the sandbox (where .git is available): VERSION=$(uvx uv-dynamic-versioning) # Linux (GNU sed): sed -i "s|^fallback-version = \".*\"|fallback-version = \"$VERSION\"|" pyproject.toml # macOS (BSD sed): sed -i '' "s|^fallback-version = \".*\"|fallback-version = \"$VERSION\"|" pyproject.toml ``` -------------------------------- ### Configure Hatch Version Build Hook Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/version_source.md Configure Hatch's version build hook to write the version to a file during the build process. Ensure the generated version file is not included in version control. ```toml [tool.hatch.build.hooks.version] path = "path/to/_version.py" template = ''' version = "{version}" ''' ``` -------------------------------- ### Set fallback version in pyproject.toml Source: https://github.com/ninoseki/uv-dynamic-versioning/blob/main/docs/tips.md Define a fallback version to prevent build failures when Git metadata is unavailable. ```toml [tool.uv-dynamic-versioning] fallback-version = "0.0.0" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.